ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to use the position value published by joint state publisher in another node?

asked 2021-12-09 18:52:18 -0600

aash gravatar image

updated 2021-12-09 19:29:26 -0600

Hi all, I am using a gazebo plugin found at /opt/ros/foxy/share/gazebo_plugins/worlds/gazebo_ros_joint_state_publisher. By echo the topic which is /demo/join_states_demo, I can see the position value of my joints. I would like to use those values in another node as an input. May i know how can i do that? Where should I find the source code of plugin?

Thank you in advance.

edit retag flag offensive close merge delete

Comments

edit: what is with me is only the .so file which is not readable.

aash gravatar image aash  ( 2021-12-10 10:29:53 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-12-10 05:05:56 -0600

Ranjit Kathiriya gravatar image

updated 2021-12-10 05:07:48 -0600

Hello @aash,

By echo the topic which is /demo/join_states_demo, I can see the position value of my joints. I would like to use those values in another node as an input.

If you can view /demo/join_states_demo by ros2 echo, you just need to write a new subscribe node, and in that, you need to listen to the following topic. You can have a look at this link for Python code or CPP code for writing a subscriber node.

edit flag offensive delete link more

Comments

Hi, thank you for your information. I have created a subscriber. However, what I have for this plugin is only a .so file which I cannot read what is the code inside. If I am not mistaken, I will need to know the variable name declared in the code that represent the data of the 'position' to subscribe right? for example: position = msg.data. But the problem right now is the .so file is not readable. Is there any method that allow me to just take the data published at the terminal at put in my subscriber node?

aash gravatar image aash  ( 2021-12-10 08:04:48 -0600 )edit

Hello @aash,

I will need to know the variable name declared in the code that represent the data of the 'position' to subscribe right?

If you want the parameter name then use can directly get those parameter names via terminal and that parameter name you can use via your subscriber node.

rostopic info /demo/join_states_demo

You will get details like message type, Publisher - for a current publisher or not, and Subscriber - current subscriber to a specific topic.

Over here message type is very important. Now, you just need to view

rosmsg show `message_type_name`

You will get a full definition of specific messages and that things you can use for subscribing. Just like msg.data.<message definition perameaters.>.

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-12-10 08:17:05 -0600 )edit

Hi, I am currently using ROS2 Foxy and the command rosmsg is not applicable in ROS, do you know what is the alternative command for ROS2?

aash gravatar image aash  ( 2021-12-10 09:04:11 -0600 )edit

I am so sorry, I have given you the command for Ros1 and you are using ROS2.

ros2 topic info /demo/join_states_demo

and for checking message the command is:

ros2 interface show <message_name>

You can have a look at this tutorial for more details.

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-12-10 09:10:08 -0600 )edit

what i get is

std_msgs/Header header

string[] name

float64[] position

float64[] velocity

float64[] effort.

May i know with only these information without the .py file, which of these info that i can use for subscribing to this topic?

aash gravatar image aash  ( 2021-12-10 09:17:52 -0600 )edit

It completely depends on you, Just have a look by echoing into the terminal which data you required, and based on that you can just obtain the data from the subscribed topic.

I would suggest you have a look at the following tutorials for an in-depth understanding of ros2 publisher and subscriber and custom message and services. This will help you a lot in ros development.

https://docs.ros.org/en/foxy/index.html

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-12-10 09:25:35 -0600 )edit

If you think, This is a solution for your answer, tick this answer, so it can help others.

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-12-10 09:46:08 -0600 )edit

I am sorry but I still could not get any further progress from here. Based on my previous reply, the information that i get from ros2 interface show <topic> are not sufficient for me to subscribe to the topic (or maybe I still cant see the way). From the publisher/subscriber tutorial: link text , we can see that we need to know what is the output from publisher is declared. In this example, msg.data = 'Hello World: %d' % self.i. Then in subscriber only i can listen to it with self.get_logger().info('I heard: "%s"' % msg.data). But for my case, i dont know what is the position, velocity and effort are declared in its original source code hence I dont know the way to subscribe to the output publish by the publisher.

aash gravatar image aash  ( 2021-12-10 10:25:20 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-12-09 18:52:18 -0600

Seen: 747 times

Last updated: Dec 10 '21