Skip to content

Commit

Permalink
visualization client: Create client, implement ComputeRobotConfigsFor…
Browse files Browse the repository at this point in the history
…GraspVisualization
  • Loading branch information
Tan Li Boon committed Feb 3, 2022
1 parent 66b8ffd commit f0dac44
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 83 deletions.
45 changes: 0 additions & 45 deletions python/mujincontrollerclient/realtimeitlplanning3client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,6 @@ def ResumeExecuteTrajectory(self, usewebapi=True, timeout=10, fireandforget=Fals
taskparameters = {'command': 'ResumeExecuteTrajectory'}
return self.ExecuteCommand(taskparameters, usewebapi=usewebapi, timeout=timeout, fireandforget=fireandforget)

def ComputeRobotConfigsForCommandVisualization(self, executiongraph, commandindex=0, usewebapi=True, timeout=2, fireandforget=False, **kwargs):
taskparameters = {
'command': 'ComputeRobotConfigsForCommandVisualization',
'executiongraph': executiongraph,
'commandindex': commandindex,
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=usewebapi, timeout=timeout, fireandforget=fireandforget)

def ComputeRobotJointValuesForCommandVisualization(self, program, commandindex=0, usewebapi=True, timeout=2, fireandforget=False, **kwargs):
taskparameters = {
'command': 'ComputeRobotJointValuesForCommandVisualization',
'program': program,
'commandindex': commandindex,
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=usewebapi, timeout=timeout, fireandforget=fireandforget)

def PlotProgramWaypoints(self, usewebapi=False, timeout=1, fireandforget=True, **kwargs):
taskparameters = {
'command': 'PlotProgramWaypoints',
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=usewebapi, timeout=timeout, fireandforget=fireandforget)

def StartITLProgram(self, programName, robotspeed=None, robotaccelmult=None, usewebapi=True, timeout=10, fireandforget=False, **kwargs):
taskparameters = {
'command': 'StartITLProgram',
Expand All @@ -132,26 +107,6 @@ def StopITLProgram(self, timeout=10, usewebapi=None, fireandforget=False, **kwar
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, timeout=timeout, usewebapi=usewebapi, fireandforget=fireandforget)

def GenerateExecutionGraph(self, programName, commandTimeout=0.2, totalTimeout=1.0, timeout=10, usewebapi=None, fireandforget=False, **kwargs):
"""generate list of commands for the itl program
"""
taskparameters = {
'command': 'GenerateExecutionGraph',
'programName': programName,
'commandTimeout': commandTimeout,
'totalTimeout': totalTimeout,
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, timeout=timeout, usewebapi=usewebapi, fireandforget=fireandforget)

def PlotContacts(self, report={}, usewebapi=False, timeout=1, fireandforget=True, **kwargs):
taskparameters = {
'command': 'PlotContacts',
'report': report
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=usewebapi, timeout=timeout, fireandforget=fireandforget)

def CheckITLProgramExists(self, programName, usewebapi=True, timeout=1):
"""checks existence of itl program
returns true if exists, exception is thrown otherwise
Expand Down
25 changes: 0 additions & 25 deletions python/mujincontrollerclient/realtimeitlplanningclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,3 @@ def ResumeExecuteTrajectory(self, envclearance=15, robotspeed=None, robotaccelmu
if robotaccelmult is not None:
taskparameters['robotaccelmult'] = robotaccelmult
return self.ExecuteCommand(taskparameters, usewebapi=usewebapi, timeout=timeout, fireandforget=fireandforget)

def ComputeRobotConfigsForCommandVisualization(self, program, commandindex=0, usewebapi=True, timeout=2, fireandforget=False, **kwargs):
taskparameters = {
'command': 'ComputeRobotConfigsForCommandVisualization',
'program': program,
'commandindex': commandindex,
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=usewebapi, timeout=timeout, fireandforget=fireandforget)

def ComputeRobotJointValuesForCommandVisualization(self, program, commandindex=0, usewebapi=True, timeout=2, fireandforget=False, **kwargs):
taskparameters = {
'command': 'ComputeRobotJointValuesForCommandVisualization',
'program': program,
'commandindex': commandindex,
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=usewebapi, timeout=timeout, fireandforget=fireandforget)

def PlotProgramWaypoints(self, usewebapi=False, timeout=1, fireandforget=True, **kwargs):
taskparameters = {
'command': 'PlotProgramWaypoints',
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=usewebapi, timeout=timeout, fireandforget=fireandforget)
13 changes: 0 additions & 13 deletions python/mujincontrollerclient/realtimerobotclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,19 +812,6 @@ def GetDynamicObjects(self, usewebapi=False, timeout=1, **kwargs):
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=usewebapi, timeout=timeout)

def ComputeRobotConfigsForGraspVisualization(self, targetname, graspname, robotname=None, toolname=None, unit='mm', usewebapi=False, timeout=10, **kwargs):
'''Returns robot configs for grasp visualization
'''
taskparameters = {
'command': 'ComputeRobotConfigsForGraspVisualization',
'targetname': targetname,
'graspname': graspname
}
if unit is not None:
taskparameters['unit'] = unit
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, robotname=robotname, toolname=toolname, usewebapi=usewebapi, timeout=timeout)

def ResetCacheTemplates(self, usewebapi=False, timeout=1, fireandforget=False, **kwargs):
"""Resets any cached templates
"""
Expand Down
118 changes: 118 additions & 0 deletions python/mujincontrollerclient/visualizationclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2022 MUJIN Inc.
# Mujin controller client for visualization task

from . import realtimerobotclient

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

class VisualizationClient(realtimerobotclient.RealtimeRobotControllerClient):
"""Mujin controller client for visualization tasks
"""
tasktype = 'visualization'

def __init__(self, **kwargs):
"""Logs into the mujin controller, initializes realtimeitlplanning3 task, and sets up parameters
:param controllerurl: URL of the mujin controller, e.g. http://controller13
:param controllerusername: Username of the mujin controller, e.g. testuser
:param controllerpassword: Password of the mujin controller
:param taskzmqport: Port of the realtimeitlplanning3 task's zmq server, e.g. 7110
:param taskheartbeatport: Port of the realtimeitlplanning3 task's zmq server's heartbeat publisher, e.g. 7111
:param taskheartbeattimeout: Seconds until reinitializing realtimeitlplanning3 task's zmq server if no heartbeat is received, e.g. 7
:param scenepk: Primary key (pk) of the bin picking task scene, e.g. komatsu_ntc.mujin.dae
:param robotname: Name of the robot, e.g. VP-5243I
:param robotspeed: Speed of the robot, e.g. 0.4
:param regionname: Name of the bin, e.g. container1
:param targetname: Name of the target, e.g. plasticnut-center
:param toolname: Name of the manipulator, e.g. 2BaseZ
:param envclearance: Environment clearance in millimeters, e.g. 20
:param usewebapi: Whether to use webapi for controller commands
:param robotaccelmult: Optional multiplier for forcing the acceleration
"""
super(VisualizationClient, self).__init__(tasktype = self.tasktype, **kwargs)
self.SetVisualizationState({})

def SetVisualizationState(self, visualizationState, timeout=10, fireandforget=False, **kwargs):
# type: (dict, int, bool, dict) -> dict | None
taskparameters = {
'command': 'SetVisualizationState',
'visualizationState': visualizationState,
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=False, timeout=timeout, fireandforget=fireandforget)

def ComputeRobotConfigsForGraspVisualization(self, targetname, graspname, robotname=None, toolname=None, unit='mm', timeout=10, **kwargs):
# type: (str, str, str, str, str, int, dict) -> dict | None
'''Returns robot configs for grasp visualization
'''
taskparameters = {
'command': 'ComputeRobotConfigsForGraspVisualization',
'targetname': targetname,
'graspname': graspname
}
if unit is not None:
taskparameters['unit'] = unit
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, robotname=robotname, toolname=toolname, usewebapi=False, timeout=timeout)

#SetCameraTransforms, SetViewerParameters inherited from PlanningControllerClient

#
# Nothing from binpickingui yet
#

#
# Originally from teachworkerui
#

def ComputeRobotConfigsForCommandVisualization(self, executiongraph, commandindex=0, timeout=2, fireandforget=False, **kwargs):
# type: (dict, int, int, bool, dict) -> dict | None
taskparameters = {
'command': 'ComputeRobotConfigsForCommandVisualization',
'executiongraph': executiongraph,
'commandindex': commandindex,
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=False, timeout=timeout, fireandforget=fireandforget)

def ComputeRobotJointValuesForCommandVisualization(self, program, commandindex=0, timeout=2, fireandforget=False, **kwargs):
# type: (dict, int, int, bool, dict) -> dict | None
taskparameters = {
'command': 'ComputeRobotJointValuesForCommandVisualization',
'program': program,
'commandindex': commandindex,
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=False, timeout=timeout, fireandforget=fireandforget)

def PlotProgramWaypoints(self, timeout=1, fireandforget=True, **kwargs):
# type: (int, bool, dict) -> dict | None
taskparameters = {
'command': 'PlotProgramWaypoints',
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=False, timeout=timeout, fireandforget=fireandforget)

def PlotContacts(self, report={}, timeout=1, fireandforget=True, **kwargs):
# type: (dict, int, bool, dict) -> dict | None
taskparameters = {
'command': 'PlotContacts',
'report': report
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, usewebapi=False, timeout=timeout, fireandforget=fireandforget)

def GenerateExecutionGraph(self, programName, commandTimeout=0.2, totalTimeout=1.0, timeout=10, fireandforget=False, **kwargs):
# type: (str, float, float, float, bool, dict) -> dict | None
"""generate list of commands for the itl program
"""
taskparameters = {
'command': 'GenerateExecutionGraph',
'programName': programName,
'commandTimeout': commandTimeout,
'totalTimeout': totalTimeout,
}
taskparameters.update(kwargs)
return self.ExecuteCommand(taskparameters, timeout=timeout, usewebapi=False, fireandforget=fireandforget)

0 comments on commit f0dac44

Please sign in to comment.