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
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
00063
00064
00065
00066
00067
00068
00069
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
00078
00079
00080
00081
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