First time here? Check out the FAQ!


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

Publish geometry_msgs Pose from command-line

asked Sep 30 '22

ankx22 gravatar image

updated Oct 1 '22

ravijoshi gravatar image

I want to publish to a topic the Pose of a robot to calculate its inverse kinematics. I am using the command:

ros2 topic pub --once /topic geometry_msgs/msg/Pose "{position:{1,1,1},orientation:{1,1,1,1}}"

but this isn't working and gives the following error

"Failed to populate field: getattr(): attribute name must be string".

What is the correct way to publish a Pose msg to topic.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered Oct 1 '22

ravijoshi gravatar image

There are no spaces in your data which makes it an invalid YAML. I am quoting from the ROS 2 (Foxy) documentation:

It’s important to note that this argument needs to be input in YAML syntax.

ROS 2

We can use the following command in ROS 2:

ravi@dell:~$ ros2 topic pub --once /topic geometry_msgs/msg/Pose "{position: {x: 0.2, y: 0.1, z: 0.3}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}"
publisher: beginning loop
publishing #1: geometry_msgs.msg.Pose(position=geometry_msgs.msg.Point(x=0.2, y=0.1, z=0.3), orientation=geometry_msgs.msg.Quaternion(x=0.0, y=0.0, z=0.0, w=1.0))

ROS 1

Although the question uses ROS 2 commands, it is tagged with ROS 1, i.e., noetic. Therefore, below is the equivalent ROS 1 command:

ravi@dell:~$ rostopic pub --once /topic geometry_msgs/Pose "{position: {x: 0.2, y: 0.1, z: 0.3}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}"
publishing and latching message for 3.0 seconds

Feel free to check the ROS 1 documentation.

Preview: (hide)

Question Tools

2 followers

Stats

Asked: Sep 30 '22

Seen: 3,168 times

Last updated: Oct 01 '22