joy_teleop_node.cpp
Go to the documentation of this file.
1 //
2 // Created by tom on 03/05/16.
3 //
4 
5 #include <ros/ros.h>
6 #include <sensor_msgs/Joy.h>
7 #include <geometry_msgs/Twist.h>
8 
9 class JoyTeleop {
10 private:
14 
15  float _linearScale;
20 
21  void joyCallback(const sensor_msgs::Joy::ConstPtr &msg) {
22  bool isDeadManActive = msg->buttons[_deadManIndex] == 1;
23  if(isDeadManActive) {
24  geometry_msgs::Twist twist;
25  twist.linear.x = msg->axes[_linearAxisIndex] * _linearScale;
26  twist.angular.z = msg->axes[_angularAxisIndex] * _angularScale;
27  _cmd.publish(twist);
28  }
29  }
30 
31 public:
33  if(!_nodeHandle.getParam("drive_joy_teleop_linear_axis", _linearAxisIndex)
34  || !_nodeHandle.getParam("drive_joy_teleop_angular_axis", _angularAxisIndex)
35  || !_nodeHandle.getParam("drive_joy_teleop_deadman_button", _deadManIndex)
36  || !_nodeHandle.getParam("drive_joy_teleop_linear_max_vel", _linearScale)
37  || !_nodeHandle.getParam("drive_joy_teleop_angular_max_vel", _angularScale)) {
38  ROS_ERROR("[%s]: Missing parameter, the requird parameters are: "
39  "drive_joy_teleop_linear_axis, drive_joy_teleop_angular_axis"
40  ", drive_joy_teleop_deadman_button , drive_joy_teleop_linear_max_vel"
41  ", drive_joy_teleop_angular_max_vel", ros::this_node::getName().c_str());
42  ros::shutdown();
43  }
44  else {
45  _joyListener = _nodeHandle.subscribe<sensor_msgs::Joy>("joy", 10, &JoyTeleop::joyCallback, this);
46  _cmd = _nodeHandle.advertise<geometry_msgs::Twist>("joy_vel", 10);
47  }
48  }
49 
50  void run() {
51  ros::spin();
52  }
53 
54 
55 
56 };
57 
58 int main(int argc, char **argv) {
59  ros::init(argc, argv, "joy_teleop_node");
60  JoyTeleop joyTeleop;
61  joyTeleop.run();
62  return 0;
63 }
void joyCallback(const sensor_msgs::Joy::ConstPtr &msg)
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle _nodeHandle
ros::Subscriber _joyListener
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
float _linearScale
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
float _angularScale
ROSCPP_DECL const std::string & getName()
ROSCPP_DECL void spin(Spinner &spinner)
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Publisher _cmd
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL void shutdown()
#define ROS_ERROR(...)


robotican_common
Author(s):
autogenerated on Wed Jan 3 2018 03:48:33