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 2022-09-30 16:46:09 -0600

ankx22 gravatar image

updated 2022-10-01 00:51:35 -0600

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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2022-10-01 00:50:50 -0600

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.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-09-30 16:46:09 -0600

Seen: 3,181 times

Last updated: Oct 01 '22