57 double error = setpoint - measurement;
58 if (error > this->
params_->pid_max_positive_error_) {
59 error = this->
params_->pid_max_positive_error_;
60 }
else if (error < this->
params_->pid_max_negative_error_) {
61 error = this->
params_->pid_max_negative_error_;
79 if (curr_output > this->
params_->pid_lim_max_ || curr_output < this->
params_->pid_lim_min_) {
88 (2.0f * this->
params_->pid_tau_ + this->params_->pid_t_);
96 }
else if (this->out_ < this->
params_->pid_lim_min_) {
109 this->
absolute_velocity_ = std::sqrt(msg.velocity_x * msg.velocity_x + msg.velocity_y * msg.velocity_y);
123 this->params_->car_parameters_.dist_cg_2_rear_axis);
125 auto [closest_point, closest_point_id, closest_point_velocity] =
128 if (closest_point_id != -1) {
136void PID::publish_solver_data(std::shared_ptr<rclcpp::Node> node, std::map<std::string, std::shared_ptr<rclcpp::PublisherBase>>& publisher_map) {}
Base (abstract) class for longitudinal controllers (the ones that calculate throttle)
std::shared_ptr< ControlParameters > params_
void calculate_integral_term(double error)
Calculate the integral term.
std::vector< custom_interfaces::msg::PathPoint > last_path_msg_
PID(const ControlParameters ¶ms)
Construct a new PID object.
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.
bool received_first_pose_
void calculate_derivative_term(double measurement)
Calculate the derivative term (derivative on measurement)
custom_interfaces::msg::Pose last_pose_msg_
void compute_output()
Compute the output value and apply limits.
double differentiator_
Differentiator term current value.
double proportional_
Proportional term current value.
void path_callback(const custom_interfaces::msg::PathPointArray &msg) override
Called when a new path is sent by Path Planning.
double update(double setpoint, double measurement)
Calculate the output value.
void vehicle_state_callback(const custom_interfaces::msg::Velocities &msg) override
Called when the car state (currently just velocity) is updated.
void vehicle_pose_callback(const custom_interfaces::msg::Pose &msg) override
Called when the car pose is updated by SLAM.
bool received_first_path_
double absolute_velocity_
double out_
Current output value.
common_lib::structures::ControlCommand get_throttle_command() override
Returns the throttle command calculated by the solver (only throttle)
double integrator_
Integrator term current value.
custom_interfaces::msg::Velocities last_velocity_msg_
void anti_wind_up()
Anti-wind-up via dynamic integrator clamping.
double prev_measurement_
Previous measurement value, required for defferentiator.
bool received_first_state_
double calculate_error(double setpoint, double measurement) const
Calculate the error signal.
double prev_error_
Previous error value, required for integrator.
void calculate_proportional_term(double error)
Calculate the proportional term.
std::tuple< common_lib::structures::Position, int, double > get_closest_point(const std::vector< custom_interfaces::msg::PathPoint > &pathpoint_array, const common_lib::structures::Position &position)
Find the closest point on the path.
common_lib::structures::Position rear_axis_position(const common_lib::structures::Position &cg, double orientation, double dist_cg_2_rear_axis)
Calculate rear axis coordinates.