Autonomous Racing  1
f1tenth Project Group of Technical University Dortmund, Germany
joystick_controller.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ros/ros.h>
4 
5 #include <algorithm>
6 #include <drive_msgs/drive_param.h>
7 #include <sensor_msgs/Joy.h>
8 #include <string>
9 
10 #include <dynamic_reconfigure/server.h>
11 #include <teleoperation/joystick_controllerConfig.h>
12 
13 constexpr const char* PARAMETER_JOYSTICK_TYPE = "joystick_type";
14 
15 constexpr const char* PARAMETER_JOYSTICK_STEERING_AXIS = "joystick_steering_axis";
16 constexpr const char* PARAMETER_JOYSTICK_ACCELERATION_AXIS = "joystick_acceleration_axis";
17 constexpr const char* PARAMETER_JOYSTICK_DECELERATION_AXIS = "joystick_deceleration_axis";
18 constexpr const char* PARAMETER_JOYSTICK_ENABLE_MANUAL_BTN = "joystick_enable_manual_button";
19 constexpr const char* PARAMETER_JOYSTICK_ENABLE_AUTONOMOUS_BTN = "joystick_enable_autonomous_button";
20 
21 constexpr const char* TOPIC_DRIVE_PARAMETERS = "input/drive_param/joystick";
22 constexpr const char* TOPIC_HEARTBEAT_MANUAL = "/input/heartbeat_manual";
23 constexpr const char* TOPIC_HEARTBEAT_AUTONOMOUS = "/input/heartbeat_autonomous";
24 
25 constexpr float EPSILON = 0.001;
26 
28 {
29 
34  float m_acceleration_scaling_factor = 0.35f;
35 
40  float m_deceleration_scaling_factor = 0.35f;
41 
46  float m_steering_scaling_factor = 0.8f;
47 
48  struct JoystickMapping
49  {
50  int steeringAxis;
51  int accelerationAxis;
52  int decelerationAxis;
53  int enableManualButton;
54  int enableAutonomousButton;
55  std::string name;
56  };
57 
58  const struct JoystickMapping joystick_mapping_ps3 = { 0, 13, 12, 14, 13, "ps3" };
59  const struct JoystickMapping joystick_mapping_xbox360 = { 0, 4, 5, 0, 1, "xbox360" };
60  const struct JoystickMapping joystick_mapping_xboxone = { 0, 5, 2, 0, 1, "xbone" };
61  const struct JoystickMapping joystick_mapping_default = joystick_mapping_xbox360;
62 
63  public:
65 
66  private:
67  dynamic_reconfigure::Server<teleoperation::joystick_controllerConfig> m_dyn_cfg_server;
68 
69  ros::NodeHandle m_node_handle;
70  ros::Publisher m_drive_parameter_publisher;
71  ros::Subscriber m_joystick_subscriber;
72  ros::Publisher m_enable_manual_publisher;
73  ros::Publisher m_enable_autonomous_publisher;
74 
75  JoystickMapping m_joystick_map;
76 
81  bool m_acceleration_locked;
82  bool m_deceleration_locked;
83 
91  void joystickCallback(const sensor_msgs::Joy::ConstPtr& joystick);
92 
99  void publishDriveParameters(double velocity, double steering_angle);
100 
104  void selectJoystickMapping();
105 
109  void updateDynamicConfig();
110 };
JoystickController()
Construct a new Remote Joy:: Remote Joy object.
constexpr const char * TOPIC_HEARTBEAT_AUTONOMOUS
constexpr const char * TOPIC_DRIVE_PARAMETERS
constexpr const char * PARAMETER_JOYSTICK_TYPE
constexpr const char * TOPIC_HEARTBEAT_MANUAL
constexpr const char * PARAMETER_JOYSTICK_DECELERATION_AXIS
constexpr float EPSILON
constexpr const char * PARAMETER_JOYSTICK_ACCELERATION_AXIS
constexpr const char * PARAMETER_JOYSTICK_ENABLE_MANUAL_BTN
constexpr const char * PARAMETER_JOYSTICK_ENABLE_AUTONOMOUS_BTN
constexpr const char * PARAMETER_JOYSTICK_STEERING_AXIS