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

What's the right command line for ROS2 FOXY using sensors_msg?

asked 2021-08-25 14:46:03 -0500

kak13 gravatar image

I ran ros2 show interface sensor_msgs/msg/JointState to see how to publish using the command line AND python code. THis is the result:

^Cbwuk@robots:~/my_robot/my_robot_description$ rosinterface show sensor_msgs/msg/JointState 
# This is a message that holds data to describe the state of a set of torque controlled joints.
#
# The state of each joint (revolute or prismatic) is defined by:
#  * the position of the joint (rad or m),
#  * the velocity of the joint (rad/s or m/s) and
#  * the effort that is applied in the joint (Nm or N).
#
# Each joint is uniquely identified by its name
# The header specifies the time at which the joint states were recorded. All the joint states
# in one message have to be recorded at the same time.
#
# This message consists of a multiple arrays, one for each part of the joint state.
# The goal is to make each of the fields optional. When e.g. your joints have no
# effort associated with them, you can leave the effort array empty.
#
# All arrays in this message should have the same size, or be empty.
# This is the only way to uniquely associate the joint name with the correct
# states.

std_msgs/Header header

string[] name
float64[] position
float64[] velocity
float64[] effort

As you can see it's using the array input.

I have no idea how to start that in python code or command line.

I tried to run like this; ros2 topic pub --once /joint_states sensor_msgs/msg/JointState '{name, "front_right_wheel", position: [0.0], velocity: [1.0], effort: [0.0]}' --once Obviously, it didn't work. I tried others as wel. No luck.

I couldn't find the ros2 document for it. I found a lot of documents on ROS1 however, I joined ROS2 so I have almost no knowledge on ROS1.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-08-26 01:48:13 -0500

Ranjit Kathiriya gravatar image

updated 2021-08-26 01:58:49 -0500

Hello @kak13,

I tried to run like this; ros2 topic pub --once /joint_states sensor_msgs/msg/JointState '{name, "front_right_wheel", position: [0.0], velocity: [1.0], effort: [0.0]}' --once

There are many mistakes in your command.

  1. {name, "front_right_wheel" : Name is not properly defined.

  2. --once : you are using this 2 times in your command.

  3. string[] name = you have to pass in list formate, I think you are passing a single string.

    ros2 topic pub --once /joint_states sensor_msgs/msg/JointState "{name: ['<your-name>'], position: [0.0], velocity: [1.0], effort: [0.0]}"

And If you want to take multiple data in your Array then

ros2 topic pub --once /joint_states sensor_msgs/msg/JointState "{name: ['<your-name>', '<your-second-name>'], position: [0.0, 0.4], velocity: [1.0, 1.2], effort: [0.0, 0.4]}"

Try this if you are having any issues feel free to drop commet. I think this should work.

edit flag offensive delete link more

Comments

Thank you so much for your time!

But the question I still have is that I wanted to run /joint_states, not cmd_vel.

Which is this;

bwuk@robots:~/my_robot/my_robot_description$ ros2 topic list
/clock
/joint_states
/parameter_events
/performance_metrics
/robot_description
/rosout
/tf
/tf_static

So, I checked what kind of data type does it use? I found out about this

bwuk@robots:~/my_robot/my_robot_description$ ros2 topic info /joint_states 
Type: sensor_msgs/msg/JointState
Publisher count: 1
Subscription count: 1

So, I ran and see what kind of format does it use. The result is just as above to the post (characters limit reached btw)

kak13 gravatar image kak13  ( 2021-08-26 01:57:19 -0500 )edit
1

But the question I still have is that I wanted to run /joint_states, not cmd_vel. Which is this;

I am sorry for the wrong answer, I have updated my answer please! have a look again.

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-08-26 02:04:12 -0500 )edit
1

Oohh!! It worked! Thank you so much!

I learned that ros2 pub doesn't make gazebo robot move T_T

THank you so much for your time, I'll mark your answer as a correct so others can learn from it as well too!

kak13 gravatar image kak13  ( 2021-08-26 02:09:16 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-08-25 14:46:03 -0500

Seen: 1,969 times

Last updated: Aug 26 '21