Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <ros/ros.h>
00009 #include <geometry_msgs/Twist.h>
00010 #include <sensor_msgs/Joy.h>
00011
00012 #include <omnix/buttons.h>
00013
00014 class TeleopOmnix
00015 {
00016 public:
00017 TeleopOmnix();
00018
00019 private:
00020 void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
00021
00022 ros::NodeHandle nh_;
00023 double l_scale_, a_scale_;
00024 ros::Publisher vel_pub_;
00025 ros::Subscriber joy_sub_;
00026
00027 };
00028
00029 TeleopOmnix::TeleopOmnix():
00030 nh_("~"),
00031 l_scale_(0.4),
00032 a_scale_(0.4)
00033 {
00034 nh_.param("scale_angular", a_scale_, a_scale_);
00035 nh_.param("scale_linear", l_scale_, l_scale_);
00036 vel_pub_ = nh_.advertise<geometry_msgs::Twist>("/cmd_vel",1);
00037 joy_sub_ = nh_.subscribe<sensor_msgs::Joy>("/joy", 1, &TeleopOmnix::joyCallback, this);
00038
00039 ROS_INFO("TeleopOmnix: Teleoperation and Emergency Stop Interface active!");
00040 }
00041
00042 void saturate_control(double& val, double max){
00043 if (max < 0.0)
00044 throw -1;
00045 if (val > max) val = max;
00046 if (val < -max) val = -max;
00047 }
00048
00049 void TeleopOmnix::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
00050 {
00051 geometry_msgs::Twist vel;
00052 double angvel = a_scale_ * joy->axes[PS3_RIGHT_STICK_LR];
00053 saturate_control(angvel, 0.4);
00054 vel.angular.z = angvel;
00055 double linvel_x = l_scale_ * joy->axes[PS3_LEFT_STICK_UD];
00056 saturate_control(linvel_x, 0.6);
00057 vel.linear.x = linvel_x;
00058 double linvel_y = l_scale_ * joy->axes[PS3_LEFT_STICK_LR];
00059 saturate_control(linvel_y, 0.6);
00060 vel.linear.y = linvel_y;
00061
00062 vel_pub_.publish(vel);
00063
00064 }
00065
00066 int main(int argc, char** argv)
00067 {
00068 ros::init(argc, argv, "omnix_ps3joy");
00069 TeleopOmnix teleop_omnix;
00070
00071 ros::spin();
00072 return 0;
00073 }
00074