Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
pid.hpp
Go to the documentation of this file.
1#pragma once
2
5#include "utils/utils.hpp"
6#include "gtest/gtest.h"
7#include <rclcpp/rclcpp.hpp>
8
19private:
20 std::vector<custom_interfaces::msg::PathPoint> last_path_msg_;
21 custom_interfaces::msg::Velocities last_velocity_msg_;
22 custom_interfaces::msg::Pose last_pose_msg_;
23 double absolute_velocity_ = 0.0;
24
28
29 double proportional_{0.0f};
30 double integrator_{0.0f};
31 double differentiator_{0.0f};
33 double prev_error_{0.0f};
34 double prev_measurement_{0.0f};
36 double out_{0.0f};
45 double calculate_error(double setpoint, double measurement) const;
46
52 void calculate_proportional_term(double error);
53
59 void calculate_integral_term(double error);
60
64 void anti_wind_up();
65
71 void calculate_derivative_term(double measurement);
72
76 void compute_output();
77
85 double update(double setpoint, double measurement);
86
87public:
92 PID(const ControlParameters &params);
93
94 void path_callback(const custom_interfaces::msg::PathPointArray& msg) override;
95 void vehicle_state_callback(const custom_interfaces::msg::Velocities& msg) override;
96 void vehicle_pose_callback(const custom_interfaces::msg::Pose& msg) override;
98 void publish_solver_data(std::shared_ptr<rclcpp::Node> node, std::map<std::string, std::shared_ptr<rclcpp::PublisherBase>>& publisher_map) override;
99
100 FRIEND_TEST(PidTests, TestAntiWindUp1);
101 FRIEND_TEST(PidTests, TestAntiWindUp2);
102 FRIEND_TEST(PidTests, TestAntiWindUp3);
103 FRIEND_TEST(PidTests, ProportionalTerm);
104 FRIEND_TEST(PidTests, IntegralTerm1);
105 FRIEND_TEST(PidTests, IntegralTerm2);
106 FRIEND_TEST(PidTests, DerivativeTerm1);
107 FRIEND_TEST(PidTests, DerivativeTerm2);
108 FRIEND_TEST(PidTests, Output1);
109 FRIEND_TEST(PidTests, Output2);
110 FRIEND_TEST(PidTests, Output3);
111 FRIEND_TEST(PidTests, Update1);
112};
Base (abstract) class for longitudinal controllers (the ones that calculate throttle)
PI-D Controller class.
Definition pid.hpp:18
void calculate_integral_term(double error)
Calculate the integral term.
Definition pid.cpp:72
FRIEND_TEST(PidTests, TestAntiWindUp3)
std::vector< custom_interfaces::msg::PathPoint > last_path_msg_
Definition pid.hpp:20
FRIEND_TEST(PidTests, Update1)
FRIEND_TEST(PidTests, DerivativeTerm1)
FRIEND_TEST(PidTests, TestAntiWindUp2)
FRIEND_TEST(PidTests, Output2)
FRIEND_TEST(PidTests, IntegralTerm1)
void publish_solver_data(std::shared_ptr< rclcpp::Node > node, std::map< std::string, std::shared_ptr< rclcpp::PublisherBase > > &publisher_map) override
Publishes solver specific data using the provided ControlNode.
Definition pid.cpp:136
FRIEND_TEST(PidTests, Output1)
bool received_first_pose_
Definition pid.hpp:27
void calculate_derivative_term(double measurement)
Calculate the derivative term (derivative on measurement)
Definition pid.cpp:84
custom_interfaces::msg::Pose last_pose_msg_
Definition pid.hpp:22
void compute_output()
Compute the output value and apply limits.
Definition pid.cpp:91
double differentiator_
Differentiator term current value.
Definition pid.hpp:31
double proportional_
Proportional term current value.
Definition pid.hpp:29
void path_callback(const custom_interfaces::msg::PathPointArray &msg) override
Called when a new path is sent by Path Planning.
Definition pid.cpp:103
double update(double setpoint, double measurement)
Calculate the output value.
Definition pid.cpp:19
void vehicle_state_callback(const custom_interfaces::msg::Velocities &msg) override
Called when the car state (currently just velocity) is updated.
Definition pid.cpp:107
FRIEND_TEST(PidTests, Output3)
void vehicle_pose_callback(const custom_interfaces::msg::Pose &msg) override
Called when the car pose is updated by SLAM.
Definition pid.cpp:112
bool received_first_path_
Definition pid.hpp:25
FRIEND_TEST(PidTests, DerivativeTerm2)
FRIEND_TEST(PidTests, IntegralTerm2)
double absolute_velocity_
Definition pid.hpp:23
double out_
Current output value.
Definition pid.hpp:36
common_lib::structures::ControlCommand get_throttle_command() override
Returns the throttle command calculated by the solver (only throttle)
Definition pid.cpp:117
double integrator_
Integrator term current value.
Definition pid.hpp:30
custom_interfaces::msg::Velocities last_velocity_msg_
Definition pid.hpp:21
void anti_wind_up()
Anti-wind-up via dynamic integrator clamping.
Definition pid.cpp:77
double prev_measurement_
Previous measurement value, required for defferentiator.
Definition pid.hpp:34
FRIEND_TEST(PidTests, TestAntiWindUp1)
bool received_first_state_
Definition pid.hpp:26
double calculate_error(double setpoint, double measurement) const
Calculate the error signal.
Definition pid.cpp:56
FRIEND_TEST(PidTests, ProportionalTerm)
double prev_error_
Previous error value, required for integrator.
Definition pid.hpp:33
void calculate_proportional_term(double error)
Calculate the proportional term.
Definition pid.cpp:68