teleop_joy.cpp
Go to the documentation of this file.
00001 
00026 #include "teleop_joy.h"
00027 
00029 
00030 TeleopJoy::TeleopJoy()
00031 {
00032     _nh.param("axis_analog_linear", axis_analog_linear, 3);
00033     _nh.param("axis_analog_angular", axis_analog_angular, 2);
00034     _nh.param("axis_digital_linear", axis_digital_linear, 1);
00035     _nh.param("axis_digital_angular", axis_digital_angular, 0);
00036     _nh.param("scale_angular", scale_angular, (double) 1);
00037     _nh.param("scale_linear", scale_linear, (double) 1);
00038 
00039     _vel_pub = _nh.advertise<geometry_msgs::Twist>("cmd_vel", 1);
00040 
00041     // This topics must be checked to match the subscribers (if already existing)
00042 
00043     _right_arm_vel_pub = _nh.advertise<geometry_msgs::Twist>("body/right_arm_cmd_vel", 1);
00044     _left_arm_vel_pub = _nh.advertise<geometry_msgs::Twist>("body/left_arm_cmd_vel", 1);
00045 
00046     _neck_pan_vel_pub = _nh.advertise<geometry_msgs::Twist>("body/neck_pan_cmd_vel", 1);
00047     _neck_tilt_vel_pub = _nh.advertise<geometry_msgs::Twist>("body/neck_tilt_cmd_vel", 1);
00048 
00049     _joy_sub = _nh.subscribe<sensor_msgs::Joy>("joy", 10, &TeleopJoy::joy_callback, this);
00050 }
00051 
00053 
00054 TeleopJoy::~TeleopJoy()
00055 {
00056 }
00057 
00059 
00060 void TeleopJoy::joy_callback(const sensor_msgs::Joy::ConstPtr& joy)
00061 {
00062     // Drawing for the code of the buttons on the Logitech RumblePad 2:
00063     //   ---------------
00064     //  |  [6]     [7]  |
00065     //  |  [4]     [5]  |
00066     //   ---------------
00067     //  |   |      (3)  |
00068     //  | --+--  (0) (2)|
00069     //  |   |      (1)  |
00070     //  / /-----------\ \
00071     // / /
00072 
00073     geometry_msgs::Twist vel;
00074     vel.linear.x = scale_linear * (joy->axes[axis_analog_linear] + joy->axes[axis_digital_linear]);
00075     vel.angular.z = scale_angular * (joy->axes[axis_analog_angular] + joy->axes[axis_digital_angular]);
00076 
00077     // Buttons 0, 1, 2, 3 corresponds to 1, 2, 3, 4 in the joypad
00078     // Button 0 + joystick = move right arm
00079     // Button 1 + joystick = move left arm
00080     // Button 2 + joystick = pan head
00081     // Button 3 + joystick = tilt head
00082 
00083     if (joy->buttons[0]) {
00084         ROS_DEBUG_THROTTLE(1, "Button 0 pushed. Moving right arm. \n Emitting linear: %g, angular: %g", vel.linear.x,
00085                           vel.angular.z);
00086 
00087         _right_arm_vel_pub.publish(vel);
00088     }
00089     else if (joy->buttons[1]) {
00090         ROS_DEBUG_THROTTLE(1, "Button 1 pushed. Moving left arm. \n Emitting linear: %g, angular: %g", vel.linear.x,
00091                           vel.angular.z);
00092 
00093         _left_arm_vel_pub.publish(vel);
00094     }
00095     else if (joy->buttons[2]) {
00096         ROS_DEBUG_THROTTLE(1, "Button 2 pushed. Panning head. \n Emitting linear: %g, angular: %g", vel.linear.x,
00097                           vel.angular.z);
00098 
00099         _neck_pan_vel_pub.publish(vel);
00100     }
00101     else if (joy->buttons[3]) {
00102         ROS_DEBUG_THROTTLE(1, "Button 3 pushed. Tilting head. \n Emitting linear: %g, angular: %g", vel.linear.x,
00103                           vel.angular.z);
00104 
00105         _neck_tilt_vel_pub.publish(vel);
00106     }
00107     else {
00108         ROS_DEBUG_THROTTLE(1, "Emitting linear: %g, angular: %g", vel.linear.x, vel.angular.z);
00109 
00110         _vel_pub.publish(vel);
00111     }
00112 }
00113 


maggie_teleop
Author(s): Raul Perula-Martinez
autogenerated on Wed Sep 16 2015 10:28:39