# -*- coding: utf-8 -*-
# Copyright (C) 2013-2015 MUJIN Inc.
# Mujin controller client for bin picking task

# system imports

# mujin imports
from . import planningclient

# logging
import logging
log = logging.getLogger(__name__)


class HandEyeCalibrationControllerClient(planningclient.PlanningControllerClient):
    """mujin controller client for hand-eye calibration task
    """
    tasktype = 'handeyecalibration'

    def __init__(self, robot, **kwargs):
        """logs into the mujin controller, initializes hand eye calibration task, and sets up parameters
        :param controllerurl: url of the mujin controller, e.g. http://controller14
        :param controllerusername: username of the mujin controller, e.g. testuser
        :param controllerpassword: password of the mujin controller
        :param scenepk: pk of the bin picking task scene, e.g. irex2013.mujin.dae
        :param usewebapi: whether to use webapi for controller commands
        """
        super(HandEyeCalibrationControllerClient, self).__init__(tasktype=self.tasktype, **kwargs)
        self.robot = robot

    def ComputeCalibrationPoses(self, camerafullname, numsamples, halconpatternparameters, calibboardvisibility, calibboardLinkName=None, calibboardGeomName=None, timeout=3000, **kwargs):
        taskparameters = {
            'command': 'ComputeCalibrationPoses',
            'camerafullname': camerafullname,
            'halconpatternparameters': halconpatternparameters,
            'calibboardvisibility': calibboardvisibility,
            'calibboardLinkName': calibboardLinkName,
            'calibboardGeomName': calibboardGeomName,
            'numsamples': numsamples,
        }
        taskparameters.update(kwargs)
        if self.robot is not None:
            taskparameters['robot'] = self.robot
        result = self.ExecuteCommand(taskparameters, timeout=timeout, usewebapi=True)
        return result

    def SampleCalibrationConfiguration(self, gridindex, timeout=3000, **kwargs):
        return self.ExecuteCommand({
            'command': 'SampleCalibrationConfiguration',
            'gridindex': gridindex
        }, timeout=timeout, usewebapi=True)

    def ReloadModule(self, **kwargs):
        return self.ExecuteCommand({
            'command': 'ReloadModule',
            'sceneparams': self.sceneparams,
            'tasktype': self.tasktype,
        }, **kwargs)

@@ -1138,52 +1138,73 @@
 mera
-fullname, numsamples, halconpatternparameter
+containername, primarysensorname, secondarysensornames, numsample
 s, c
@@ -1391,28 +1391,33 @@
      'camera
-full
+container
 name': camer
@@ -1421,12 +1421,17 @@
 mera
-full
+container
 name
@@ -1449,56 +1449,140 @@
    '
-halconpatternparameters': halconpatternparameter
+primarysensorname': primarysensorname,%0A            'secondarysensornames': secondarysensornames,%0A            'numsamples': numsample
 s,%0A 
@@ -1750,46 +1750,8 @@
 me,%0A
-            'numsamples': numsamples,%0A
     
@@ -1892,14 +1892,12 @@
   re
-sult =
+turn
  sel
@@ -1965,30 +1965,8 @@
 rue)
-%0A        return result
 %0A%0A  
@@ -2008,25 +2008,159 @@
 n(self, 
-gridindex
+cameracontainername, primarysensorname, secondarysensornames, gridindex, calibboardvisibility, calibboardLinkName=None, calibboardGeomName=None
 , timeou
@@ -2190,35 +2190,25 @@
     
-return self.ExecuteCommand(
+taskparameters = 
 %7B%0A  
@@ -2279,39 +2279,544 @@
    '
-gridindex': gridindex%0A        %7D
+cameracontainername': cameracontainername,%0A            'primarysensorname': primarysensorname,%0A            'secondarysensornames': secondarysensornames,%0A            'gridindex': gridindex,%0A            'calibboardvisibility': calibboardvisibility,%0A            'calibboardLinkName': calibboardLinkName,%0A            'calibboardGeomName': calibboardGeomName,%0A        %7D%0A        taskparameters.update(kwargs)%0A        if self.robot is not None:%0A            taskparameters%5B'robot'%5D = self.robot%0A        return self.ExecuteCommand(taskparameters
 , ti

update parameters to ComputeCalibrationPoses() and SampleCalibrationConfiguration()