Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
pid_steering_motor.cpp
Go to the documentation of this file.
2
3double PIDSteeringMotor::compute_steering_rate(double current_steering, double steering_goal) {
4 if (this->last_update == rclcpp::Time(0, 0)) {
5 this->last_update = rclcpp::Clock().now();
6 return 0;
7 }
8 double dt = (rclcpp::Clock().now() - this->last_update).seconds();
9 double error = steering_goal - current_steering;
10
11 double proportional = error;
12
13 integral_ += error * dt;
14
15 double derivative = (error - previous_error_) / dt;
16 previous_error_ = error;
17
18 // PID control output
19 double output = this->car_parameters_->steering_motor_parameters.kp * proportional +
20 this->car_parameters_->steering_motor_parameters.ki * integral_ +
21 this->car_parameters_->steering_motor_parameters.kd * derivative;
22
23 return output;
24}
double compute_steering_rate(double current_steering, double steering_goal) override
Computes the change in steering angle based on PID control.
std::shared_ptr< common_lib::car_parameters::CarParameters > car_parameters_