24 from enum
import IntEnum
28 import moveit_commander
30 from std_msgs.msg
import Int32
31 from bcap_service.srv
import bcap, bcapRequest
32 from bcap_service.msg
import variant
35 _EXAMPLE_SCENE_NUMBER =
"0,0" 37 _EXAMPLE_POSITION = [0, -45, 135, 0, 45, 0]
47 CONTROLLER_CONNECT = 3
48 CONTROLLER_DISCONNECT = 4
49 CONTROLLER_GETROBOT = 7
50 CONTROLLER_EXECUTE = 17
81 rospy.logerr(
"Usage:\n" 82 " roslaunch denso_robot_bringup <robot_name>_bringup.launch" 83 " sim:=false ip_address:=<IP address> send_format:=0 recv_format:=2\n" 84 " roslaunch bcap_service bcap_service.launch ip_address:=<IP address>\n" 85 " rosrun denso_robot_bringup example_change_scene.py" 86 " _robot_name:=<robot_name>")
90 return hex(ctypes.c_uint(hresult).value)
94 global _bcap_slave_mode
95 _bcap_slave_mode = int(message.data)
99 if _bcap_slave_mode == mode:
102 pub_changemode.publish(mode)
103 while (
not rospy.is_shutdown())
and (_bcap_slave_mode != mode):
111 bcap_request = bcapRequest()
112 bcap_request.func_id = BcapFuncId.CONTROLLER_EXECUTE
113 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9),
114 variant(vt=VarType.VT_BSTR, value=
'GetErrorDescription'),
115 variant(vt=VarType.VT_I4, value=str(hresult))]
116 res = bcap_service(bcap_request)
127 bcap_request = bcapRequest()
128 bcap_request.func_id = BcapFuncId.ROBOT_EXECUTE
129 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9robot),
130 variant(vt=VarType.VT_BSTR, value=
'CurScene'),
131 variant(vt=VarType.VT_BSTR, value=
'')]
132 res = bcap_service(bcap_request)
135 raise Exception(
"bcap_service: RC9Robot: Failed to execute CurScene. error=" 137 scene_number = res.vntRet.value
142 bcap_request = bcapRequest()
143 bcap_request.func_id = BcapFuncId.ROBOT_EXECUTE
144 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9robot),
145 variant(vt=VarType.VT_BSTR, value=
'CurSubScene'),
146 variant(vt=VarType.VT_BSTR, value=
'')]
147 res = bcap_service(bcap_request)
150 raise Exception(
"bcap_service: RC9Robot: Failed to execute CurSubScene. error=" 152 sub_scene_number = res.vntRet.value
154 return scene_number, sub_scene_number
158 global _bcap_slave_mode
164 rospy.init_node(
'example_change_scene')
165 rospy.loginfo(
"Start Example of ChangeScene...")
167 robot_name = rospy.get_param(
"~robot_name",
"")
168 if not robot_name
or len(robot_name) <= 0:
169 rospy.logerr(
"Invalid parameter: robot_name")
172 rospy.loginfo(
"robot_name: %s", robot_name)
174 rospy.loginfo(
"Check if /%s/denso_robot_control is up...", robot_name)
175 node_list = rosnode.get_node_names(namespace=robot_name)
176 if not '/' + robot_name +
'/denso_robot_control' in node_list:
177 rospy.logerr(
"No such node: /%s/denso_robot_control", robot_name)
181 moveit_commander.roscpp_initialize(sys.argv)
182 move_group = moveit_commander.MoveGroupCommander(
'arm')
183 pub_changemode = rospy.Publisher(
'/' + robot_name +
'/ChangeMode',
185 sub_curmode = rospy.Subscriber(
'/' + robot_name +
'/CurMode',
186 Int32, callback_curmode)
187 while (pub_changemode.get_num_connections() < 1)\
188 and (sub_curmode.get_num_connections() < 1):
191 rospy.loginfo(
"Waiting for /bcap_service...")
192 rospy.wait_for_service(
'/bcap_service')
194 rospy.loginfo(
"Connecting to /bcap_service...")
195 bcap_service = rospy.ServiceProxy(
'/bcap_service', bcap)
200 rospy.loginfo(
"bcap_service: Controller_Connect()...")
201 bcap_request = bcapRequest()
202 bcap_request.func_id = BcapFuncId.CONTROLLER_CONNECT
203 bcap_request.vntArgs = [variant(vt=VarType.VT_BSTR, value=
'example_controller_name'),
204 variant(vt=VarType.VT_BSTR, value=
'CaoProv.DENSO.VRC9'),
205 variant(vt=VarType.VT_BSTR, value=
'localhost'),
206 variant(vt=VarType.VT_BSTR, value=
'@IfNotMember')]
207 res = bcap_service(bcap_request)
209 raise Exception(
"bcap_service: Failed to connect to RC9 controller. error=" 211 rc9 = res.vntRet.value
212 rospy.loginfo(
"bcap_service: Connected to RC9. Controller handle is %s", rc9)
217 rospy.loginfo(
"bcap_service: RC9: Controller_GetRobot()...")
218 bcap_request = bcapRequest()
219 bcap_request.func_id = BcapFuncId.CONTROLLER_GETROBOT
220 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9),
221 variant(vt=VarType.VT_BSTR, value=
'example_robot_name'),
222 variant(vt=VarType.VT_BSTR, value=
'@IfNotMember')]
223 res = bcap_service(bcap_request)
225 raise Exception(
"bcap_service: RC9: Failed to get the robot handle. error=" 227 rc9robot = res.vntRet.value
228 rospy.loginfo(
"bcap_service: RC9: Robot handle is %s", rc9robot)
233 rospy.loginfo(
"bcap_service: RC9Robot: Executing slvGetMode...")
234 bcap_request = bcapRequest()
235 bcap_request.func_id = BcapFuncId.ROBOT_EXECUTE
236 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9robot),
237 variant(vt=VarType.VT_BSTR, value=
'slvGetMode'),
238 variant(vt=VarType.VT_BSTR, value=
'')]
239 res = bcap_service(bcap_request)
242 raise Exception(
"bcap_service: RC9Robot: Failed to execute slvGetMode. error=" 244 _bcap_slave_mode = int(res.vntRet.value)
245 rospy.loginfo(
"bcap_service: RC9Robot: Current b-CAP Slave Mode is 0x%x",
249 rospy.loginfo(
"Stopping b-CAP Slave Mode...")
255 rospy.loginfo(
"bcap_service: RC9: Executing ClearError...")
256 bcap_request = bcapRequest()
257 bcap_request.func_id = BcapFuncId.CONTROLLER_EXECUTE
258 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9),
259 variant(vt=VarType.VT_BSTR, value=
'ClearError'),
260 variant(vt=VarType.VT_BSTR, value=
'')]
261 res = bcap_service(bcap_request)
264 raise Exception(
"bcap_service: RC9: Failed to execute ClearError. error=" 270 rospy.loginfo(
"bcap_service: RC9: Executing ManualReset...")
271 bcap_request = bcapRequest()
272 bcap_request.func_id = BcapFuncId.CONTROLLER_EXECUTE
273 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9),
274 variant(vt=VarType.VT_BSTR, value=
'ManualReset'),
275 variant(vt=VarType.VT_BSTR, value=
'')]
276 res = bcap_service(bcap_request)
279 raise Exception(
"bcap_service: RC9: Failed to execute ManualReset. error=" 285 rospy.loginfo(
"bcap_service: RC9Robot: Running Motor...")
286 bcap_request = bcapRequest()
287 bcap_request.func_id = BcapFuncId.ROBOT_EXECUTE
288 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9robot),
289 variant(vt=VarType.VT_BSTR, value=
'Motor'),
290 variant(vt=VarType.VT_I4, value=
'1')]
291 res = bcap_service(bcap_request)
294 raise Exception(
"bcap_service: RC9Robot: Failed to run motor. error=" 300 rospy.loginfo(
"bcap_service: RC9Robot: Executing TakeArm...")
301 bcap_request = bcapRequest()
302 bcap_request.func_id = BcapFuncId.ROBOT_EXECUTE
303 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9robot),
304 variant(vt=VarType.VT_BSTR, value=
'TakeArm'),
305 variant(vt=(VarType.VT_ARRAY | VarType.VT_I4),
307 res = bcap_service(bcap_request)
310 raise Exception(
"bcap_service: RC9Robot: Failed to execute TakeArm. error=" 315 rospy.loginfo(
"bcap_service: RC9Robot: Executing CurScene and CurSubScene...")
317 rospy.loginfo(
"bcap_service: RC9Robot: Current Scene is (%s,%s)",
318 scene_number, sub_scene_number)
326 rospy.loginfo(
"bcap_service: RC9Robot: Moving to SafetyP0 position before ChangeScene...")
327 bcap_request = bcapRequest()
328 bcap_request.func_id = BcapFuncId.ROBOT_MOVE
329 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9robot),
330 variant(vt=VarType.VT_I4, value=str(CaoRobotMove.MOVE_P.value)),
331 variant(vt=VarType.VT_BSTR, value=
'SafetyP0'),
332 variant(vt=VarType.VT_BSTR, value=
'')]
333 res = bcap_service(bcap_request)
336 raise Exception(
"bcap_service: RC9Robot: Failed to move SafetyP0. error=" 342 rospy.loginfo(
"bcap_service: RC9Robot: Executing ChangeScene(%s)...",
343 _EXAMPLE_SCENE_NUMBER)
344 bcap_request = bcapRequest()
345 bcap_request.func_id = BcapFuncId.ROBOT_EXECUTE
346 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9robot),
347 variant(vt=VarType.VT_BSTR, value=
'ChangeScene'),
348 variant(vt=(VarType.VT_ARRAY | VarType.VT_I4),
349 value=_EXAMPLE_SCENE_NUMBER)]
350 res = bcap_service(bcap_request)
353 raise Exception(
"bcap_service: RC9Robot: Failed to execute ChangeScene. error=" 359 rospy.loginfo(
"bcap_service: RC9Robot: Executing GiveArm...")
360 bcap_request = bcapRequest()
361 bcap_request.func_id = BcapFuncId.ROBOT_EXECUTE
362 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9robot),
363 variant(vt=VarType.VT_BSTR, value=
'GiveArm'),
364 variant(vt=VarType.VT_BSTR, value=
'')]
365 res = bcap_service(bcap_request)
368 raise Exception(
"bcap_service: RC9Robot: Failed to execute GiveArm. error=%x" 373 rospy.loginfo(
"Starting b-CAP Slave Mode...")
377 rospy.loginfo(
"Move(slvMove) to " + str(_EXAMPLE_POSITION) +
"...")
378 move_group.set_max_acceleration_scaling_factor(_SLVMOVE_SPEED)
379 move_group.set_max_velocity_scaling_factor(_SLVMOVE_SPEED)
380 pose = [x / 180.0 * math.pi
for x
in _EXAMPLE_POSITION]
381 move_group.go(pose, wait=
True)
384 except rospy.ServiceException
as se:
385 rospy.logerr(
"rospy.ServiceException: %s", se)
387 except Exception
as e:
388 rospy.logerr(
"%s: %s", e.__class__.__name__, e.message)
391 rospy.loginfo(
"Cleaning up...")
393 if rc9robot > 0
and take_arm:
394 rospy.loginfo(
"bcap_service: RC9Robot: Executing GiveArm...")
395 bcap_request = bcapRequest()
396 bcap_request.func_id = BcapFuncId.ROBOT_EXECUTE
397 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9robot),
398 variant(vt=VarType.VT_BSTR, value=
'GiveArm'),
399 variant(vt=VarType.VT_BSTR, value=
'')]
400 bcap_service(bcap_request)
406 rospy.loginfo(
"bcap_service: RC9Robot: Release robot handle...")
407 bcap_request = bcapRequest()
408 bcap_request.func_id = BcapFuncId.ROBOT_RELEASE
409 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9robot)]
410 bcap_service(bcap_request)
416 rospy.loginfo(
"bcap_service: RC9: Disconnect from the controller...")
417 bcap_request = bcapRequest()
418 bcap_request.func_id = BcapFuncId.CONTROLLER_DISCONNECT
419 bcap_request.vntArgs = [variant(vt=VarType.VT_I4, value=rc9)]
420 bcap_service(bcap_request)
421 rospy.loginfo(
"bcap_service: RC9: Disconnected.")
424 if __name__ ==
"__main__":
def convert_error_code(hresult)
def callback_curmode(message)
def change_bcap_slave_mode(pub_changemode, mode)
def get_current_scene(bcap_service, rc9, rc9robot)
def print_error_description(bcap_service, rc9, hresult)