youbot_joy_teleop.cpp
Go to the documentation of this file.
00001 
00012 #include <geometry_msgs/Twist.h>
00013 #include <ros/ros.h>
00014 #include <sensor_msgs/Joy.h>
00015 #include <youbot_teleop/youbot_joy_teleop.h>
00016 
00017 ros::Time T;
00018 bool receivedmsg = false;
00019 
00020 using namespace std;
00021 
00022 youbot_joy_teleop::youbot_joy_teleop()
00023 {
00024   // create the ROS topics
00025   cmd_vel = node.advertise < geometry_msgs::Twist > ("cmd_vel", 10);
00026   joy_sub = node.subscribe < sensor_msgs::Joy > ("joy", 10, &youbot_joy_teleop::joy_cback, this);
00027   
00028   //read in throttle value
00029   double temp;
00030   if (node.getParam("/youbot_joy_teleop/linear_throttle_factor", temp))
00031     linear_throttle_factor = (float)temp;
00032   else
00033     linear_throttle_factor = 1.0;
00034   if (node.getParam("/youbot_joy_teleop/angular_throttle_factor", temp))
00035     angular_throttle_factor = (float)temp;
00036   else
00037     angular_throttle_factor = 1.0;
00038   
00039   ROS_INFO("youBot Joystick Teleop Started");
00040 }
00041 
00042 void youbot_joy_teleop::joy_cback(const sensor_msgs::Joy::ConstPtr& joy)
00043 {
00044   if(!receivedmsg)
00045   {
00046     receivedmsg = true; 
00047   }
00048   T = ros::Time::now();
00049 
00050   // create the twist message
00051   geometry_msgs::Twist twist;
00052   // left joystick controls the linear movement
00053   twist.linear.x = joy->axes.at(1)*MAX_TRANS_VEL*linear_throttle_factor;
00054   twist.linear.y = joy->axes.at(0)*MAX_TRANS_VEL*linear_throttle_factor;
00055   twist.linear.z = 0;
00056   // right joystick controls the angular movement
00057   twist.angular.x = 0;
00058   twist.angular.y = 0;
00059   twist.angular.z = joy->axes.at(2)*MAX_ANG_VEL*angular_throttle_factor;
00060   // send the twist command
00061   
00062   cmd_vel.publish(twist);
00063 }
00064 
00065 void youbot_joy_teleop::joy_check()
00066 {
00067     if( (receivedmsg) && ( (ros::Time::now().toSec() - T.toSec() ) > .15) )
00068     {
00069       geometry_msgs::Twist zero;
00070       cmd_vel.publish(zero);
00071     }
00072 }
00073 
00074 int main(int argc, char **argv)
00075 {
00076   // initialize ROS and the node
00077   ros::init(argc, argv, "youbot_joy_teleop");
00078 
00079   // initialize the joystick controller
00080   youbot_joy_teleop controller;
00081 
00082   // continue until a ctrl-c has occurred
00083   while(ros::ok())
00084   {
00085     controller.joy_check();
00086     
00087     ros::spinOnce();
00088   }
00089   //ros::spin();
00090 }


youbot_teleop
Author(s): Russell Toris , Graylin Trevor Jay
autogenerated on Mon Oct 6 2014 09:08:50