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

How to publish message with several type in yaml syntax

asked 2020-12-07 08:17:56 -0600

Vinco gravatar image

Hi, I'm currently learning to use ROS with Gazebo and I'm working on a drone project. I'm struggling to send the right terminal command to publish a message on a particular topic.

I use ROS-Melodic on a 18.04 Ubuntu LTS version.

Here is the structure of the message:

string[] name 
geometry_msgs/Pose[] pose   
  geometry_msgs/Point[] position
    float64 x
    float64 y
    float64 z
  geometry_msgs/Quaternion[] orientation
    float64 x
    float64 y
    float64 z
    float64 w
geometry_msgs/Twist[] twist   
  geometry_msgs/Vector3[] linear
    float64 x
    float64 y
    float64 z
  geometry_msgs/Vector3[] angular
    float64 x
    float64 y
    float64 z

I'm trying to simply publish a message on the appropriate topic using the yaml syntax but I can't make it properly.

Here is one of the multiple trial I made:

rostopic pub /gazebo/model_states gazebo_msgs/ModelStates -- '[state1]'  '[[10.0,10.0,10.0],[0.0,0.0,0.0,1.0]' '[1.0,1.0,0.0,0.0,0.0,0.0]'

I want to precise that my problem is really about the syntax and how I should write this command to publish on the topic named "gazebo/model_states" with a type message defined as "ModelStates" and described above.

I also tried the dictonnary syntax but it seems it can't work with Vector3 type as it tells me "twist must be a tuple or a list instead of: dict".

Thank you for your help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-12-08 02:22:54 -0600

mgruhler gravatar image

What you have here is not the proper YAML syntax.

Check the wiki examples.

Correct it should be something along the lines of:

rostopic pub /gazebo/model_states gazebo_msgs/ModelStates "{name: ['State1'], pose: [{position: {x: 1.0, y: 2.0, z: 3.0}, orientation: {x: 1.0, y: 2.0, z: 3.0, w: 4.0}}], twist: [{linear: {x: 1.0, y: 2.0, z: 3.0}, angular: {x: 1.0, y: 2.0, z: 3.0}}]}"

Note that hitting TAB after the rostopic pub /gazebo/model_states gazebo_msgs/ModelStates will provide you with a pretty-printed version.

edit flag offensive delete link more

Comments

Hey, thanks for answering !

Looks like your syntax doesn't work either, I get this error:

rostopic pub /gazebo/set_model_state gazebo_msgs/ModelState "{name: ['State1'], pose: [{position: {x: 1.0, y: 1.0, z: 1.0}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}], twist: [{linear: {x: 1.0, y: 1.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}]}"
ERROR: Not enough arguments:
 * Given: [{'linear': {'y': 1.0, 'x': 1.0, 'z': 0.0}, 'angular': {'y': 0.0, 'x': 0.0, 'z': 0.0}}]
 * Expected: ['linear', 'angular']

Args are: [model_name pose.position.x pose.position.y pose.position.z pose.orientation.x pose.orientation.y pose.orientation.z pose.orientation.w twist.linear.x twist.linear.y twist.linear.z twist.angular.x twist.angular.y twist.angular.z reference_frame]

But your second tips helped me, I didn't know ...(more)

Vinco gravatar image Vinco  ( 2020-12-08 04:08:38 -0600 )edit

You have gazebo_msgs/ModelState instead of gazebo_msgs/ModelStates (note the plural form of the latter as well as in my answer). This is a different message and thus obviously not working with what I have here. In your question you asked for the ModelStates, which corresponds with the msg structure you posted.

mgruhler gravatar image mgruhler  ( 2020-12-08 06:01:08 -0600 )edit

Alright thanks I noticed the difference there is a additionnal parameter. Is there another syntax that can be used (with '[ ]') instead of the dict ? It's kind of heavy to write.

Vinco gravatar image Vinco  ( 2020-12-09 03:50:02 -0600 )edit

No. [] is array syntax. As the messages are structured fields, represented as yaml dicts, you have to use those.

I'd recommend creating a simple python (ros node) or bash (wrapping the call) script and parse command line arguments, if you want to do this on a regular basis.

mgruhler gravatar image mgruhler  ( 2020-12-09 04:35:50 -0600 )edit

Question Tools

Stats

Asked: 2020-12-07 08:17:56 -0600

Seen: 729 times

Last updated: Dec 08 '20