Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to use the subscribed cmd_vel?

Hi, i calculate the geometry_msgs::Twist cmd_vel and can subscribe to this topic /myrobot/cmd_vel successfully. But i don't know how to use it, e.g. send it directly to my robot? I mean I can call back with velCallback, but how to use the velocity, in the main() function or in the velCallback() function if i want to send it to the robot? I hope i express my question clearly. Below is the simple subscriber node.


include "ros/ros.h"

include "std_msgs/String.h"

include "geometry_msgs/Twist.h"

using namespace std;

void velCallback(const geometry_msgs::Twist& vel) { cout<<"velocity\n"<<vel&lt;&lt;"\n"; }<="" p="">

int main(int argc, char **argv) { ros::init(argc, argv, "myrobot_cmd_vel"); ros::NodeHandle n; ros::Subscriber sub = n.subscribe("/myrobot/cmd_vel", 10, velCallback);

ros::spin();
return 0;

}

How to use the subscribed cmd_vel?

Hi, i calculate the geometry_msgs::Twist cmd_vel and can subscribe to this topic /myrobot/cmd_vel successfully. But i don't know how to use it, e.g. send it directly to my robot? I mean I can call back with velCallback, but how to use the velocity, in the main() function or in the velCallback() function if i want to send it to the robot? I hope i express my question clearly. Below is the simple subscriber node.


include "ros/ros.h"

include "std_msgs/String.h"

include "geometry_msgs/Twist.h"

using namespace std;

void velCallback(const geometry_msgs::Twist& vel) { cout<<"velocity\n"<<vel&lt;&lt;"\n"; }<="" p=""> {

cout<<"velocity\n"<<vel<<"\n";

}

int main(int argc, char **argv) { {

ros::init(argc, argv, "myrobot_cmd_vel");
 ros::NodeHandle n;
 ros::Subscriber sub = n.subscribe("/myrobot/cmd_vel", 10, velCallback);

velCallback);
ros::spin();
return 0;

}