Ask Your Question
0

'rostopic pub' command doesn't work as expected. Probably quote-command-line argument issue.

asked 2020-02-17 04:11:43 -0500

John999991 gravatar image

updated 2020-02-17 04:49:22 -0500

gvdhoorn gravatar image

Dear all,

One simple (I think) question regarding rostopic pub command sending message to 2 joints.

I have a robot with 4 wheels and would like to send velocity commands to the 2 front wheel joints (FLJ=Front Left Joint, FRJ=Front Right Joint) using the following command:

rostopic pub -1 /joint_states sensor_msgs/JointState '{header: auto, name: ['FLJ','FLJ'], position: [0,0], velocity: [1,0], effort: [0,0]}'

After running the command at another terminal (having Gazebo with my robot online), I get:

publishing and latching message for 3.0 seconds

but the robot is not moving...Why?

My configuration is : ROS Kinetic Kame UBUNTU 16.04 Gazebo-7


Edit: If I do not quote:

rostopic pub -1 /joint_states sensor_msgs/JointState {header: auto, name: [FLJ,FLJ], position: [0,0], velocity: [1,0], effort: [0,0]}

Result:

rostopic: error: Argument error: while parsing a flow node
expected the node content, but found '<stream end>'
  in "<string>", line 1, column 9:
    {header:

If I do quote:

rostopic pub -1 /joint_states sensor_msgs/JointState '{header: auto, name: ["FLJ","FLJ"], position: [0,0], velocity: [1,0], effort: [0,0]}'

Result:

publishing and latching message for 3.0 seconds

But no movement...

BTW I have changed the title of the questing reflecting your Answer.

edit retag flag offensive close merge delete

Comments

Note: you list FLJ twice, while I believe you meant to write: FRJ.

gvdhoorn gravatar image gvdhoorn  ( 2020-02-17 04:37:56 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2020-02-17 04:33:49 -0500

gvdhoorn gravatar image

updated 2020-02-17 04:49:48 -0500

I [..] send velocity commands [..] using the following command:

rostopic pub -1 /joint_states sensor_msgs/JointState '{header: auto, name: ['FLJ','FLJ'], position: [0,0], velocity: [1,0], effort: [0,0]}'

There is a problem with the way you've formatted the command. Note how you start the message contents with a single quote (ie: ') and end it with one.

But in the middle, you also use single quotes for the names of the joints. That can't work, as the shell (ie: bash) will assume you'll use ' to demarcate the arguments to rostopic. So in the end, this is what the command line ends up being:

  • rostopic
  • pub
  • -1
  • /joint_states
  • sensor_msgs/JointState
  • '{header: auto, name: ['
  • FLJ
  • ',' (ie: a comma in quotes)
  • FLJ
  • '], position: [0,0], velocity: [1,0], effort: [0,0]}'

that's probably not what you intended to do.

Summarising: you cannot embed single quotes in the YAML you want to pass to rostopic pub.

Two options:

  1. don't quote at all: if there are no spaces in the names, you could forgo quoting completely (YAML actually doesn't require strings to be quoted, it just helps avoid ambiguity)
  2. use double quotes (ie: "') for the joint names

But, this most likely won't help with:

but the robot is not moving...Why?

JointState messages are meant to report on current state, not to command desired state. The /joint_states topic also typically only carries current state, not commands.

We don't know how you've setup your Gazebo simulation, so you could have configured it such that it does accept JointState messages as commands, but you would have to check that yourself.


Edit:

If I do not quote:

this won't work. You need to quote the yaml argument. When I wrote: "you could avoid quoting", I only meant the joint names.

But no movement...

as I wrote earlier: /joint_states is typically not used to command motion.

We cannot check that for you as we don't know how you've configured your simulation. You'll have to figure that out.

edit flag offensive delete link more

Comments

Note: this is not a ROS or rostopic problem, but a general how-to-quote-command-line-arguments one.

gvdhoorn gravatar image gvdhoorn  ( 2020-02-17 04:34:58 -0500 )edit

Could you please mark the question as answered by ticking the checkmark (✓) to the left of the answer if you feel it has been answered? Thanks.

gvdhoorn gravatar image gvdhoorn  ( 2020-02-19 04:56:05 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-02-17 04:11:43 -0500

Seen: 121 times

Last updated: Feb 17