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

Revision history [back]

click to hide/show revision 1
initial version

The answer to the question you asked is below. However I think there is a hidden question here. What have you tried so far to make a publisher in C++ and what happened when it didn't work?


Take a look at the tutorial for writing a publisher in C++.

You will need to make the following changes:

  1. Change the name of the node on line 47 to something more appropriate for what you are doing, e.g. "gripper_controller"
  2. Change the topic name on line 73 to be the topic you want to publish to, in this case "gripper_angle".
  3. Change the header file on line 28 to the data type you want to publish, which is "std_msgs/UInt16.h"
  4. Change the type of the Publisher on line 73 to be UInt16.
  5. Remove the while loop and have it just publish data once, with the value you want to publish. If you are trying to make a utility you can call from the command line with an argument, then you should get that value from a command line argument. There are plenty of tutorials on the web about how to parse command line arguments in C++.