Go to the documentation of this file.00001
00002
00003 #include <ros/ros.h>
00004
00005 #include <geometry_msgs/Twist.h>
00006 #include <sensor_msgs/Joy.h>
00007
00008
00009 class TeleopStingbot{
00010
00011 public:
00012 TeleopStingbot();
00013
00014 private:
00015 void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
00016
00017 ros::NodeHandle nh_;
00018
00019 double linear_, angular_;
00020 double l_scale_, a_scale_;
00021 ros::Publisher vel_pub_;
00022 ros::Subscriber joy_sub_;
00023
00024 };
00025
00026
00027 TeleopStingbot::TeleopStingbot():
00028 linear_(1),
00029 angular_(2)
00030 {
00031 nh_.param("axis_linear", linear_, linear_);
00032 nh_.param("axis_angular", angular_, angular_);
00033 nh_.param("scale_angular", a_scale_, a_scale_);
00034 nh_.param("scale_linear", l_scale_, l_scale_);
00035
00036 vel_pub_ = nh_.advertise<geometry_msgs::Twist>("cmd_vel", 1);
00037 joy_sub_ = nh_.subscribe<sensor_msgs::Joy>("joy_throttle", 10, &TeleopStingbot::joyCallback, this);
00038 }
00039
00040
00041 void TeleopStingbot::joyCallback(const sensor_msgs::Joy::ConstPtr& joy){
00042
00043 geometry_msgs::Twist vel;
00044
00045 vel.linear.x = l_scale_ * joy->buttons[8];
00046 if (vel.linear.x==0.0){
00047 vel.linear.x = -l_scale_ * joy->buttons[9];
00048 }
00049
00050 vel.angular.z = a_scale_ * joy->buttons[6];
00051 if (vel.angular.z==0.0){
00052 vel.angular.z = -a_scale_ * joy->buttons[7];
00053 }
00054
00055 vel_pub_.publish(vel);
00056
00057 }
00058
00059 int main(int argc, char** argv){
00060
00061 ros::init(argc, argv, "stingbot_teleop");
00062 TeleopStingbot teleop_stingbot;
00063
00064 ros::spin();
00065 }