Tetrapod Project
joystick_controller.h
Go to the documentation of this file.
1 #ifndef joystick_controller_h
2 #define joystick_controller_h
3 
4 #include "ros/ros.h"
5 #include "geometry_msgs/Twist.h"
6 #include "sensor_msgs/Joy.h"
7 #include "std_srvs/Empty.h"
8 #include "keyboard/Key.h"
9 #include <thread>
10 #include <fcntl.h>
11 #include <unistd.h>
12 #include <sys/select.h>
13 
14 #define BUTTON_ERROR 0.01
15 
17 {
18  RIGHT_STICK_UD = 4, // Up is positive (1)
19  RIGHT_STICK_LR = 3, // Left is positive (1)
20  LEFT_STICK_UD = 1, // Up is positive (1)
21  LEFT_STICK_LR = 0, // Left is positive (1)
22  R2 = 5, // No effort is positive (1)
23  L2 = 2, // No effort is positive (1)
24 };
25 
27 {
28  R1 = 5,
29  R2_BUTTON = 7,
30  R3 = 12,
31  L1 = 4,
32  L2_BUTTON = 6,
33  L3 = 11,
34  DPAD_RIGHT = 16,
35  DPAD_LEFT = 15,
36  DPAD_UP = 13,
37  DPAD_DOWN = 14,
38  START = 9,
39  SELECT = 8,
40  TRIANGLE = 2,
41  CIRCLE = 1,
42  CROSS = 0,
43  SQUARE = 3
44 };
45 
47 {
48  enum ButtonStatus {PRESSED = 0, RELEASED = 1};
49 
51  {
52  KEY_UP = 273, // up
53  KEY_DOWN = 274, // down
54  KEY_LEFT = 276, // left
55  KEY_RIGHT = 275, // right
62  KEY_PAUSE = 32 // space
63  };
64 
65  public: JoystickController();
66 
67  public: virtual ~JoystickController();
68 
69  public: void initROS();
70 
71  public: void initThreads();
72 
73  public: void listenerThread();
74 
75  private: void joystickCallback(const sensor_msgs::JoyConstPtr &_msg);
76 
77  private: void keyboardButtonReleasedCallback(const keyboard::KeyConstPtr &_msg);
78 
79  private: void keyboardButtonPressedCallback(const keyboard::KeyConstPtr &_msg);
80 
81  private: ros::Subscriber keyboard_button_pressed_subscriber;
82 
83  private: ros::Subscriber keyboard_button_released_subscriber;
84 
86 
88 
90 
92 
94 
96 
98 
100 
102 
104 
106 
107  private: void changeLinearMultiplier(bool _increase);
108 
109  private: void changeRotationalMultiplier(bool _increase);
110 
111  private: std::unique_ptr<ros::NodeHandle> nodeHandle;
112 
113  private: ros::Subscriber joystick_subscriber;
114 
115  private: ros::Publisher twist_command_publisher;
116 
117  private: double linear_rate_multiplier = 0.2;
118 
119  private: double linear_rate_multiplier_step = 0.1;
120 
121  private: double linear_rate_multiplier_min = 0.2;
122 
123  private: double linear_rate_multiplier_max = 0.6;
124 
125  private: double rotational_rate_multiplier = 0.2;
126 
127  private: double rotational_rate_multiplier_step = 0.2;
128 
129  private: double rotational_rate_multiplier_max = 2.6;
130 
131  private: double rotational_rate_multiplier_min = 0.2;
132 
134 
135  private: double pause = false;
136 
137  public: bool isControllerPaused(){return pause;}
138 
139  public: void publishTwistCommand();
140 
141  private: bool readyToChangeLinearMultiplier();
142 
143  private: bool readyToChangeRotationalMultiplier();
144 
146 
147  private: double time_of_last_linear_limit_change = 0.0;
148 
150 };
151 
152 #endif
ButtonStatus COUNTER_CLOCKWISE_ROTATION
void keyboardButtonReleasedCallback(const keyboard::KeyConstPtr &_msg)
ButtonStatus LINEAR_SPEED_INCREASE
std::unique_ptr< ros::NodeHandle > nodeHandle
void changeRotationalMultiplier(bool _increase)
geometry_msgs::Twist twist_command_message
ButtonStatus CLOCKWISE_ROTATION
ButtonStatus ANGULAR_RATE_INCREASE
ros::Subscriber joystick_subscriber
void keyboardButtonPressedCallback(const keyboard::KeyConstPtr &_msg)
ros::Publisher twist_command_publisher
void joystickCallback(const sensor_msgs::JoyConstPtr &_msg)
ButtonStatus ANGULAR_RATE_DECREASE
double minimum_seconds_between_limit_change
void changeLinearMultiplier(bool _increase)
double time_of_last_rotational_limit_change
ros::Subscriber keyboard_button_pressed_subscriber
ButtonStatus LINEAR_SPEED_DECREASE
ros::Subscriber keyboard_button_released_subscriber
JoyAxisIndices
@ RIGHT_STICK_UD
@ LEFT_STICK_UD
@ RIGHT_STICK_LR
@ LEFT_STICK_LR
JoyButtonIndices
@ SELECT
@ TRIANGLE
@ SQUARE
@ L2_BUTTON
@ R2_BUTTON
@ CIRCLE
@ DPAD_UP
@ DPAD_DOWN
@ DPAD_RIGHT
@ DPAD_LEFT
Eigen::Matrix< double, 6, 1 > Twist
Definition: kinematics.h:48