Advertisement
130s

ROS_Gazebo_MultipleRobotsContolSample_11Oct12.cpp

Oct 13th, 2011
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ros/ros.h>
  4. #include <geometry_msgs/Twist.h>
  5. const std::string NODE_NAME = "driveBase_multiBots";
  6. class RobotDriver {
  7. private:
  8. ros::NodeHandle nh_;
  9. ros::Publisher cmd_vel_pub_;
  10.  
  11. public:
  12. RobotDriver(ros::NodeHandle &nh) {
  13. nh_ = nh;
  14. cmd_vel_pub_ = nh_.advertise<geometry_msgs::Twist
  15. //> ("/base_controller/command", 1); // Topic 'base_controller' works only for 'base'.
  16. //>("crowd1/turtlebot_node/cmd_vel", 1);
  17. >("crowd1/turtlebot_node/cmd_vel", 1000);
  18. //>("/turtlebot_node/cmd_vel", 1);
  19. }
  20.  
  21. void runDemoScenario() {
  22. sleep(2); // To avoid error upon instantiating.
  23.  
  24. geometry_msgs::Twist base_cmd;
  25. base_cmd.linear.x = base_cmd.linear.y = base_cmd.angular.z = 0; // init
  26.  
  27. base_cmd.linear.y = 10.25; //arbitrary value for testing purpose only.
  28.  
  29. cmd_vel_pub_.publish(base_cmd);
  30. sleep(10); // Only to have ample time to look at rxgraph :P
  31. }
  32. };
  33.  
  34. int main(int argc, char** argv) {
  35. ros::init(argc, argv, NODE_NAME);
  36. ros::NodeHandle nh;
  37.  
  38. RobotDriver driver(nh);
  39. driver.runDemoScenario();
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement