0
$\begingroup$

Rosanswers logo

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.


Originally posted by kak13 on ROS Answers with karma: 113 on 2021-08-25

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Ranjit Kathiriya with karma: 1622 on 2021-08-26

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by kak13 on 2021-08-26:
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)

Comment by Ranjit Kathiriya on 2021-08-26:\

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.

Comment by kak13 on 2021-08-26:
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!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.