Autonomous Racing  1
f1tenth Project Group of Technical University Dortmund, Germany
navigation_stack_control_converter.cpp
Go to the documentation of this file.
2 #include "car_config.h"
3 #include <algorithm>
4 #include <boost/algorithm/clamp.hpp>
5 #include <eigen3/Eigen/Dense>
6 
7 using namespace Eigen;
8 
10 {
11  this->m_command_velocity_subscriber =
12  this->m_node_handle.subscribe<geometry_msgs::Twist>(TOPIC_CMD_VEL, 1,
13  &NavigationStackControlConverter::convertCallback, this);
14 
15  this->m_drive_param_publisher = this->m_node_handle.advertise<drive_msgs::drive_param>(TOPIC_DRIVE_PARAM, 10);
16 }
17 
18 void NavigationStackControlConverter::convertCallback(const geometry_msgs::Twist::ConstPtr& cmd_vel_message)
19 {
20 
21  double velocity = cmd_vel_message->linear.x;
22  double angle = cmd_vel_message->angular.z;
23 
24  double erpm_speed = velocity * car_config::TRANSMISSION / car_config::ERPM_TO_SPEED;
25  double angle_rad = 0;
26 
27  /*
28  if (std::abs(velocity_angular) < ANGULAR_VELOCITY_THRESHOLD)
29  {
30  if (velocity_result < 0 && velocity_result > -VELOCITY_THRESHOLD)
31  {
32  velocity_result = -VELOCITY_THRESHOLD;
33  }
34  else if (velocity_result > 0 && velocity_result < VELOCITY_THRESHOLD)
35  {
36  velocity_result = VELOCITY_THRESHOLD;
37  }
38  }
39  */
40 
42 
43  servo_data = boost::algorithm::clamp(servo_data, 0.0, 1.0);
44 
45  drive_msgs::drive_param control_message;
46  control_message.velocity = erpm_speed / car_config::MAX_RPM_ELECTRICAL; // convert from min-max erpm to (-1)-1
47  control_message.angle = (servo_data * 2 - car_config::MAX_SERVO_POSITION) /
48  car_config::MAX_SERVO_POSITION; // convert from 0-1 to (-1)-1
49  m_drive_param_publisher.publish(control_message);
50 }
constexpr double TRANSMISSION
Gear transmission inside the differential of the car. This is an estimate, the exact value is not kno...
Definition: car_config.h:83
NavigationStackControlConverter()
Initializes the publisher and subscriber.
constexpr double STEERING_TO_SERVO_GAIN
Conversion factor from steering angle to servo input 1/radian.
Definition: car_config.h:73
constexpr double MAX_SERVO_POSITION
Definition: car_config.h:85
constexpr const char * TOPIC_DRIVE_PARAM
constexpr double STEERING_TO_SERVO_OFFSET
Position of the servo for normal wheel position.
Definition: car_config.h:67
constexpr double MAX_RPM_ELECTRICAL
Maximum electrical revolutions per minute for use in the VESC 1/min.
Definition: car_config.h:44
constexpr double ERPM_TO_SPEED
Conversion factor from electrical revolutions per minute to meters per second m/s * minute = m...
Definition: car_config.h:50