Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
inspection_functions.cpp
Go to the documentation of this file.
1#include "rclcpp/rclcpp.hpp"
3
4InspectionFunctions::InspectionFunctions(double max_angle, double turning_period,
5 double wheel_radius, double finish_time,
6 bool start_and_stop, double gain /* = 0.0 */,
7 double ideal_velocity /* = 0.0 */)
8 : max_angle_(max_angle),
9 ideal_velocity_(ideal_velocity),
10 turning_period_(turning_period),
11 wheel_radius_(wheel_radius),
12 gain_(gain),
13 finish_time_(finish_time),
14 current_goal_velocity_(ideal_velocity),
15 start_and_stop_(start_and_stop) {}
16
18
19double InspectionFunctions::rpm_to_velocity(double rpm) const {
20 double perimeter = 2 * M_PI * wheel_radius_;
21 return rpm * perimeter / 60.0;
22}
23
24double InspectionFunctions::calculate_throttle(double current_velocity) const {
25 RCLCPP_DEBUG(rclcpp::get_logger("inspection"), "Current goal velocity - current velocity: %f - %f", current_goal_velocity_, current_velocity);
26 double error = current_goal_velocity_ - current_velocity;
27 return gain_ * error;
28}
29
30double InspectionFunctions::calculate_steering(double time) const {
31 return stop_oscilating_ ? 0.0 : sin(time * 2 * M_PI / turning_period_) * max_angle_;
32}
33
35 if (fabs(throttle) >= MAX_THROTTLE) {
36 return (throttle > 0) ? 1 : -1;
37 }
38 return throttle / MAX_THROTTLE;
39}
40
41void InspectionFunctions::redefine_goal_velocity(double current_velocity) {
42 if (start_and_stop_ && fabs(current_velocity - this->current_goal_velocity_) < WHEELS_STOPPED_THRESHOLD) {
43 if (this->current_goal_velocity_ == 0) {
45 } else {
46 this->current_goal_velocity_ = 0;
47 }
48 }
49}
void redefine_goal_velocity(double current_velocity)
used when in oscilation mode to redefine the ideal velocity
double calculate_throttle(double current_velocity) const
calculate torque output according to velocity
bool stop_oscilating_
Used to stop the oscilation near zero and avoid violent wheel movements.
double throttle_to_adequate_range(double throttle) const
convert the throttle to a range between -1 and 1
double rpm_to_velocity(double rpm) const
convert rpm [rotations/minute] to velocity [m/s]
double calculate_steering(double time) const
calculate the steering angle according to time
InspectionFunctions()
Construct a new Inspection Functions object.
#define MAX_THROTTLE
constexpr double WHEELS_STOPPED_THRESHOLD