Gazebo service SetModelConfiguration

asked 2022-06-01 16:27:41 -0600

AL1 gravatar image

updated 2022-06-02 13:36:42 -0600

I can't use the SetModelConfiguration gazebo service, can someone help me?

def main(args=None):
    # Initialize 'rclpy'
    rclpy.init(args=args)
    node = rclpy.create_node('test')
    joint_names=['tri_prism_joint_j1','tri_prism_joint_j2','tri_prism_joint_j3']
    os.system('ros2 service call /pause_physics std_srvs/srv/Empty')
    #os.system('ros2 service call /unpause_physics std_srvs/srv/Empty')
    req = SetModelConfiguration.Request()
    #req.model_name = str('agv')#model_name
    #req.urdf_param_name = str('agv_description')
    #req.joint_names = list('tri_prism_joint_j1')#joint_name
    req.model_name = 'agv_'#model_name
    req.urdf_param_name = 'robot_description'
    req.joint_names = joint_names
    set_model_configuration = node.create_service(SetModelConfiguration,'/gazebo/set_model_configuration',10)
    #position =["1.5"]
    #float_position = list(np.float_(position))
    float_position = [np.random.uniform(1.5,1.5),np.random.uniform(0,1.5),np.random.uniform(0,3)]
    req.joint_positions = float_position
    #node.get_logger().info('1')
    set_model_configuration = node.create_client(SetModelConfiguration, '/gazebo/set_model_configuration')
    #node.get_logger().info('2')
    while not set_model_configuration.wait_for_service(timeout_sec=1.0):
        node.get_logger().info('service not available, waiting again...')
    #node.get_logger().info('3')
    resp = set_model_configuration.call_async(req)
    #node.get_logger().info('4')
    #rclpy.spin_until_future_complete(node, resp)
    rclpy.spin(node)
    #node.get_logger().info('5')

    rclpy.shutdown()

if __name__ == '__main__':
    main()

ERROR MESSAGE:

waiting for service to become available...
requester: making request: std_srvs.srv.Empty_Request()

response:
std_srvs.srv.Empty_Response()

[INFO] [1654114010.750298093] [test]: 1
[INFO] [1654114010.751538327] [test]: 2
[INFO] [1654114010.752076238] [test]: 3
[INFO] [1654114010.752597629] [test]: 4
Traceback (most recent call last):
  File "tuto2.py", line 81, in <module>
    main()
  File "tuto2.py", line 75, in main
    rclpy.spin_until_future_complete(node, resp)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/__init__.py", line 217, in spin_until_future_complete
    executor.spin_until_future_complete(future, timeout_sec)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/executors.py", line 299, in spin_until_future_complete
    self.spin_once_until_future_complete(future, timeout_sec)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/executors.py", line 717, in spin_once_until_future_complete
    self.spin_once(timeout_sec)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/executors.py", line 714, in spin_once
    raise handler.exception()
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/task.py", line 239, in __call__
    self._handler.send(None)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/executors.py", line 429, in handler
    await call_coroutine(entity, arg)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/executors.py", line 383, in _execute_service
    response = await await_or_execute(srv.callback, request, srv.srv_type.Response())
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/executors.py", line 118, in await_or_execute
    return callback(*args)
TypeError: 'int' object is not callable

Any help would be appreciated, i can supply more information if needed

edit retag flag offensive close merge delete