00001 #include<ros/ros.h> 00002 #include<std_msgs/Float64.h> 00003 00004 /* This code was based on the examples provided in Chap. 8 of "Effective Robotics Programming with ROS - Third Edition" 00005 by Anil Mahtani, Luis Sanchez, Enrique Fernandea, and Aaron Martinez. 00006 This is a shell for publishing servo movement to the /commands topic. The /commands published here are taken into the 00007 commander node to be processed and then transmitted to the servo. The basic_motors.launch file must be used prior 00008 to running any nodes created with this code. Alternatively, this node can be included in a new launch file (copied and 00009 then modified from basic_motors.launch) and will work. 00010 00011 This shell creates a Pulbisher class to which motor commands can be prepared and then published to the /commands topic. 00012 To use this publisher, use motor.move("int") in the main function. Replace "int" with the value, in degrees, to which you 00013 want the motor to move. Please see commander.cpp for additional information on movement. */ 00014 00015 using namespace std; 00016 00017 class Publisher 00018 { 00019 private: 00020 ros::NodeHandle nh; 00021 ros::Publisher pub; 00022 public: 00023 Publisher(); 00024 void move(float request); 00025 }; 00026 00027 Publisher::Publisher() 00028 { 00029 pub=nh.advertise<std_msgs::Float64>("commands", 1000); 00030 } 00031 00032 void Publisher::move(float request) 00033 { 00034 std_msgs::Float64 msg; 00035 msg.data = request; 00036 pub.publish(msg); 00037 } 00038 00039 int main(int argc, char **argv) 00040 { 00041 ros::init(argc, argv, "Shell"); 00042 ros::NodeHandle nh; 00043 Publisher motor; 00044 00045 }