Ask Your Question

Revision history [back]

Hi. Welcome to ROS.

In your code, you just have to use regular publishers and subscribers. The multiplexing is then done outside. So for example if you run:

rosrun topic_tools mux sel_cmdvel auto_cmdvel joystick_cmdvel mux:=mux_cmdvel

Then you could publish in your nodes on the topics auto_cmdvel or joystick_cmdvel

ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("topic_name", 5);
geometry_msgs::Twist cmd;
cmd.linear.x = 1
pub.publish(cmd);

And in another node you can subscribe to sel_cmdvel (just like you would to any other topic)

ros::Subscriber sub = nh.subscribe("sel_cmdvel", 1, callback);

Look here for more info on topics in general: https://wiki.ros.org/ROS/Tutorials/UnderstandingTopics and in cpp: https://wiki.ros.org/roscpp/Overview/Publishers%20and%20Subscribers

I saw that once I created a mux I can change it with ros services from my c++ code, but I don't know how to start the ros node except of running it from cmd.

For this you need a launchfile: https://wiki.ros.org/ROS/Tutorials/UsingRqtconsoleRoslaunch#The_Launch_File

Hi. Welcome to ROS.

In your code, you just have to use regular publishers and subscribers. The multiplexing is then done outside. So for example if you run:

rosrun topic_tools mux sel_cmdvel auto_cmdvel joystick_cmdvel mux:=mux_cmdvel

Then you could publish in your nodes on the topics auto_cmdvel or joystick_cmdvel

ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("topic_name", nh.advertise<geometry_msgs::Twist>("auto_cmdvel", 5);
geometry_msgs::Twist cmd;
cmd.linear.x = 1
pub.publish(cmd);

And in another node you can subscribe to sel_cmdvel (just like you would to any other topic)

ros::Subscriber sub = nh.subscribe("sel_cmdvel", 1, callback);

Look here for more info on topics in general: https://wiki.ros.org/ROS/Tutorials/UnderstandingTopics and in cpp: https://wiki.ros.org/roscpp/Overview/Publishers%20and%20Subscribers

I saw that once I created a mux I can change it with ros services from my c++ code, but I don't know how to start the ros node except of running it from cmd.

For this you need a launchfile: https://wiki.ros.org/ROS/Tutorials/UsingRqtconsoleRoslaunch#The_Launch_File

Hi. Welcome to ROS.

In your code, you just have to use regular publishers and subscribers. The multiplexing is then done outside. So for example if you run:

rosrun topic_tools mux sel_cmdvel auto_cmdvel joystick_cmdvel mux:=mux_cmdvel

Then you could publish in your nodes on the topics auto_cmdvel or joystick_cmdvel

ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("auto_cmdvel", 5);
geometry_msgs::Twist cmd;
cmd.linear.x = 1
pub.publish(cmd);

And in another node you can subscribe to sel_cmdvel (just like you would to any other topic)

ros::Subscriber sub = nh.subscribe("sel_cmdvel", 1, callback);

Look here for more info on topics in general: https://wiki.ros.org/ROS/Tutorials/UnderstandingTopics and in cpp: https://wiki.ros.org/roscpp/Overview/Publishers%20and%20Subscribers

I saw that once I created a mux I can change it with ros services from my c++ code, but I don't know how to start the ros node except of running it from cmd.

For this you need a launchfile: https://wiki.ros.org/ROS/Tutorials/UsingRqtconsoleRoslaunch#The_Launch_File


edit:

To use the service, you have to follow https://wiki.ros.org/roscpp_tutorials/Tutorials/WritingServiceClient#Writing_the_Client_Node For example to add a new input topic:

ros::NodeHandle n;
ros::ServiceClient client = n.serviceClient<topic_tools::MuxAdd>("mux/add");
topic_tools::MuxAdd srv;
srv.request.topic = "my_topic_to_add";
client.call(srv)

Hi. Welcome to ROS.

In your code, you just have to use regular publishers and subscribers. The multiplexing is then done outside. So for example if you run:

rosrun topic_tools mux sel_cmdvel auto_cmdvel joystick_cmdvel mux:=mux_cmdvel

Then you could publish in your nodes on the topics auto_cmdvel or joystick_cmdvel

ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("auto_cmdvel", 5);
geometry_msgs::Twist cmd;
cmd.linear.x = 1
pub.publish(cmd);

And in another node you can subscribe to sel_cmdvel (just like you would to any other topic)

ros::Subscriber sub = nh.subscribe("sel_cmdvel", 1, callback);

Look here for more info on topics in general: https://wiki.ros.org/ROS/Tutorials/UnderstandingTopics and in cpp: https://wiki.ros.org/roscpp/Overview/Publishers%20and%20Subscribers

I saw that once I created a mux I can change it with ros services from my c++ code, but I don't know how to start the ros node except of running it from cmd.

For this you need a launchfile: https://wiki.ros.org/ROS/Tutorials/UsingRqtconsoleRoslaunch#The_Launch_File


edit:

To use the service, you have to follow https://wiki.ros.org/roscpp_tutorials/Tutorials/WritingServiceClient#Writing_the_Client_Node For example to add a new input topic:

ros::NodeHandle n;
ros::ServiceClient client = n.serviceClient<topic_tools::MuxAdd>("mux/add");
topic_tools::MuxAdd srv;
srv.request.topic = "my_topic_to_add";
client.call(srv)

But you have to start the topic_tools mux command beforehand. your code then communicates with its services. For example in a launchfile:

<launch>
  <node pkg="topic_tools" name="my_little_mux" type="mux"/>
</launch>

You'll have to try it but you can probably do all the configuration from your cpp program, then.