Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

/gazebo/get_model_state in ROS2 not present

Hello,

I want to extract with a python script the position of a robot (that I know the model name of) from gazebo.

In many forum posts and tutorials for ROS1, the /gazebo/get_model_state service (API docu) is used for that, but I can not see it with ros2 service list

When I create it myself, the client raises an error, that the GetModelState.Request is not a SrvTypeRequest. I have not found any other ways to make this work so far.

My services are:

/apply_joint_effort [gazebo_msgs/srv/ApplyJointEffort]
/apply_link_wrench [gazebo_msgs/srv/ApplyLinkWrench]
/clear_joint_efforts [gazebo_msgs/srv/JointRequest]
/clear_link_wrenches [gazebo_msgs/srv/LinkRequest]
/delete_entity [gazebo_msgs/srv/DeleteEntity]
/gazebo/describe_parameters [rcl_interfaces/srv/DescribeParameters]   
/gazebo/get_parameter_types [rcl_interfaces/srv/GetParameterTypes]
/gazebo/get_parameters [rcl_interfaces/srv/GetParameters]
/gazebo/list_parameters [rcl_interfaces/srv/ListParameters]
/gazebo/set_parameters [rcl_interfaces/srv/SetParameters]
/gazebo/set_parameters_atomically [rcl_interfaces/srv/SetParametersAtomically]
/get_model_list [gazebo_msgs/srv/GetModelList]
/pause_physics [std_srvs/srv/Empty]
/position_handler/describe_parameters [rcl_interfaces/srv/DescribeParameters]
/position_handler/get_parameter_types [rcl_interfaces/srv/GetParameterTypes]
/position_handler/get_parameters [rcl_interfaces/srv/GetParameters]
/position_handler/list_parameters [rcl_interfaces/srv/ListParameters]
/position_handler/set_parameters [rcl_interfaces/srv/SetParameters]
/position_handler/set_parameters_atomically [rcl_interfaces/srv/SetParametersAtomically]
/reset_simulation [std_srvs/srv/Empty]
/reset_world [std_srvs/srv/Empty]
/spawn_entity [gazebo_msgs/srv/SpawnEntity]
/turtlebot3_imu/describe_parameters [rcl_interfaces/srv/DescribeParameters]
/turtlebot3_imu/get_parameter_types [rcl_interfaces/srv/GetParameterTypes]
/turtlebot3_imu/get_parameters [rcl_interfaces/srv/GetParameters]
/turtlebot3_imu/list_parameters [rcl_interfaces/srv/ListParameters]
/turtlebot3_imu/set_parameters [rcl_interfaces/srv/SetParameters]
/turtlebot3_imu/set_parameters_atomically [rcl_interfaces/srv/SetParametersAtomically]
/turtlebot3_joint_state/describe_parameters [rcl_interfaces/srv/DescribeParameters]
/turtlebot3_joint_state/get_parameter_types [rcl_interfaces/srv/GetParameterTypes]
/turtlebot3_joint_state/get_parameters [rcl_interfaces/srv/GetParameters]
/turtlebot3_joint_state/list_parameters [rcl_interfaces/srv/ListParameters]
/turtlebot3_joint_state/set_parameters [rcl_interfaces/srv/SetParameters]
/turtlebot3_joint_state/set_parameters_atomically [rcl_interfaces/srv/SetParametersAtomically]
/turtlebot3_laserscan/describe_parameters [rcl_interfaces/srv/DescribeParameters]
/turtlebot3_laserscan/get_parameter_types [rcl_interfaces/srv/GetParameterTypes]
/turtlebot3_laserscan/get_parameters [rcl_interfaces/srv/GetParameters]
/turtlebot3_laserscan/list_parameters [rcl_interfaces/srv/ListParameters]
/turtlebot3_laserscan/set_parameters [rcl_interfaces/srv/SetParameters]
/turtlebot3_laserscan/set_parameters_atomically [rcl_interfaces/srv/SetParametersAtomically]
/unpause_physics [std_srvs/srv/Empty]

with my own started service as /gazebo/get_model_state [gazebo_msgs/srv/GetModelState] .

If you have any ideas or helpful tutorials, please let me know. Thank you for your time!

/gazebo/get_model_state in ROS2 not present

Hello,

I want to extract with a python script the position of a robot (that I know the model name of) from gazebo.

In many forum posts and tutorials for ROS1, the /gazebo/get_model_state service (API docu) is used for that, but I can not see it with ros2 service list

When I create it myself, the client raises an error, that the GetModelState.Request is not a SrvTypeRequest. I have not found any other ways to make this work so far.

My services are:

/apply_joint_effort [gazebo_msgs/srv/ApplyJointEffort]
/apply_link_wrench [gazebo_msgs/srv/ApplyLinkWrench]
/clear_joint_efforts [gazebo_msgs/srv/JointRequest]
/clear_link_wrenches [gazebo_msgs/srv/LinkRequest]
/delete_entity [gazebo_msgs/srv/DeleteEntity]
/gazebo/describe_parameters [rcl_interfaces/srv/DescribeParameters]   
/gazebo/get_parameter_types [rcl_interfaces/srv/GetParameterTypes]
/gazebo/get_parameters [rcl_interfaces/srv/GetParameters]
/gazebo/list_parameters [rcl_interfaces/srv/ListParameters]
/gazebo/set_parameters [rcl_interfaces/srv/SetParameters]
/gazebo/set_parameters_atomically [rcl_interfaces/srv/SetParametersAtomically]
/get_model_list [gazebo_msgs/srv/GetModelList]
/pause_physics [std_srvs/srv/Empty]
/position_handler/describe_parameters [rcl_interfaces/srv/DescribeParameters]
/position_handler/get_parameter_types [rcl_interfaces/srv/GetParameterTypes]
/position_handler/get_parameters [rcl_interfaces/srv/GetParameters]
/position_handler/list_parameters [rcl_interfaces/srv/ListParameters]
/position_handler/set_parameters [rcl_interfaces/srv/SetParameters]
/position_handler/set_parameters_atomically [rcl_interfaces/srv/SetParametersAtomically]
/reset_simulation [std_srvs/srv/Empty]
/reset_world [std_srvs/srv/Empty]
/spawn_entity [gazebo_msgs/srv/SpawnEntity]
/turtlebot3_imu/describe_parameters [rcl_interfaces/srv/DescribeParameters]
/turtlebot3_imu/get_parameter_types [rcl_interfaces/srv/GetParameterTypes]
/turtlebot3_imu/get_parameters [rcl_interfaces/srv/GetParameters]
/turtlebot3_imu/list_parameters [rcl_interfaces/srv/ListParameters]
/turtlebot3_imu/set_parameters [rcl_interfaces/srv/SetParameters]
/turtlebot3_imu/set_parameters_atomically [rcl_interfaces/srv/SetParametersAtomically]
/turtlebot3_joint_state/describe_parameters [rcl_interfaces/srv/DescribeParameters]
/turtlebot3_joint_state/get_parameter_types [rcl_interfaces/srv/GetParameterTypes]
/turtlebot3_joint_state/get_parameters [rcl_interfaces/srv/GetParameters]
/turtlebot3_joint_state/list_parameters [rcl_interfaces/srv/ListParameters]
/turtlebot3_joint_state/set_parameters [rcl_interfaces/srv/SetParameters]
/turtlebot3_joint_state/set_parameters_atomically [rcl_interfaces/srv/SetParametersAtomically]
/turtlebot3_laserscan/describe_parameters [rcl_interfaces/srv/DescribeParameters]
/turtlebot3_laserscan/get_parameter_types [rcl_interfaces/srv/GetParameterTypes]
/turtlebot3_laserscan/get_parameters [rcl_interfaces/srv/GetParameters]
/turtlebot3_laserscan/list_parameters [rcl_interfaces/srv/ListParameters]
/turtlebot3_laserscan/set_parameters [rcl_interfaces/srv/SetParameters]
/turtlebot3_laserscan/set_parameters_atomically [rcl_interfaces/srv/SetParametersAtomically]
/unpause_physics [std_srvs/srv/Empty]

with my own started service as /gazebo/get_model_state [gazebo_msgs/srv/GetModelState] .

If you have any ideas or helpful tutorials, please let me know. Thank you for your time!

UPDATE 1: I have found here that the old plugin was split up. Does anybody know how to use the new plugin?

/gazebo/get_model_state in ROS2 not present

Hello,

I want to extract with a python script the position of a robot (that I know the model name of) from gazebo.

In many forum posts and tutorials for ROS1, the /gazebo/get_model_state service (API docu) is used for that, but I can not see it with ros2 service list

If you have any ideas or helpful tutorials, please let me know. Thank you for your time!

UPDATE 1: I have found as mentioned here that the old plugin was split up. Does anybody know it is deprecated.

What I have done so far is following this tutorial:

If I put ros2 service call /get_entity_state gazebo_msgs/GetEntityState '{name: turtlebot3, reference_frame: world}' the output is just: waiting for service to become available...

In my code I tried

1) Check if the service /get_entity_state is in service list

2) if not, create it new with node.create_service()

3) create a client to connect to the /get_entity_state service

4) create a request with GetEntityState.Request()

5) send the request via

answer = self.node_client.call_async(request)
rclpy.spin_until_future_complete(self, answer)
return answer

But when I do that, I get the error

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: __init__() takes 1 positional argument but 3 were given

Any idea or a good tutorial, how to use the new plugin?I can make it work?

/gazebo/get_model_state in ROS2 not present

Hello,

I want to extract with a python script the position of a robot (that I know the model name of) from gazebo.

In many forum posts and tutorials for ROS1, the /gazebo/get_model_state service (API docu) is used for that, but as mentioned here it is deprecated.

What I have done so far is following this tutorial:

If I put ros2 service call /get_entity_state gazebo_msgs/GetEntityState '{name: turtlebot3, reference_frame: world}' world}' the output is just:

waiting for service to become available...

available...

In my code I tried

1) Check if the service /get_entity_state is in service list

2) if not, create it new with node.create_service()

3) create a client to connect to the /get_entity_state service

4) create a request with GetEntityState.Request()

5) send the request via

answer = self.node_client.call_async(request)
rclpy.spin_until_future_complete(self, answer)
return answer

But when I do that, I get the error

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: __init__() takes 1 positional argument but 3 were given

Any idea or a good tutorial, how I can make it work?

/gazebo/get_model_state in ROS2 not present

Hello,

I want to extract with a python script the position of a robot (that I know the model name of) from gazebo.

In many forum posts and tutorials for ROS1, the /gazebo/get_model_state service (API docu) is used for that, but as mentioned here it is deprecated.

What I have done so far is following this tutorial:tutorial and now want to use it to get the position of a turtlebot3 inside its demo world.

If I put ros2 service call /get_entity_state gazebo_msgs/GetEntityState '{name: turtlebot3, reference_frame: world}' the output is just:

waiting for service to become available...

In my code I tried

1) Check if the service /get_entity_state is in service list

2) if not, create it new with node.create_service()

3) create a client to connect to the /get_entity_state service

4) create a request with GetEntityState.Request()

5) send the request via

answer = self.node_client.call_async(request)
rclpy.spin_until_future_complete(self, answer)
return answer

But when I do that, I get the error

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: __init__() takes 1 positional argument but 3 were given

Any idea or a good tutorial, how I can make it work?

/gazebo/get_model_state in ROS2 not present

Hello,

I want to extract with a python script the position of a robot (that I know the model name of) from gazebo.

In many forum posts and tutorials for ROS1, the /gazebo/get_model_state service (API docu) is used for that, but as mentioned here it is deprecated.

What I have done so far is following this tutorial and now want to use it to get the position of a turtlebot3 inside its demo world.

If I put ros2 service call /get_entity_state gazebo_msgs/GetEntityState '{name: turtlebot3, reference_frame: world}' the output is just:

waiting for service to become available...

Does that mean, /get_entity_state is not running automatically when gazebo is started?

In my code I tried

1) Check if the service /get_entity_state is in service list

2) if not, create it new with node.create_service()

3) create a client to connect to the /get_entity_state service

4) create a request with GetEntityState.Request()

5) send the request via

answer = self.node_client.call_async(request)
rclpy.spin_until_future_complete(self, answer)
return answer

But when I do that, I get the error

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: __init__() takes 1 positional argument but 3 were given

Any idea or a good tutorial, how I can make it work?

/gazebo/get_model_state in ROS2 not present

Hello,

I want to extract with a python script the position of a robot (that I know the model name of) from gazebo.

In many forum posts and tutorials for ROS1, the /gazebo/get_model_state service (API docu) is used for that, but as mentioned here it is deprecated.

What I have done so far is following this tutorial and now want to use it to get the position of a turtlebot3 inside its demo world.

If I put ros2 service call /get_entity_state gazebo_msgs/GetEntityState '{name: turtlebot3, reference_frame: world}' the output is just:

waiting for service to become available...

Does that mean, /get_entity_state is not running automatically when gazebo is started?

In my code I tried

1) Check if the service /get_entity_state is in service list

2) if not, create it new with node.create_service()

3) create a client to connect to the /get_entity_state service

4) create a request with GetEntityState.Request()

5) send the request via

answer = self.node_client.call_async(request)
rclpy.spin_until_future_complete(self, answer)
return answer

But when I do that, I get the error

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: __init__() takes 1 positional argument but 3 were given

Any idea or a good tutorial, how I can make it work?