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.
1
#include "
motion_lib/steering_motor_model/pid_steering_motor.hpp
"
2
3
double
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
}
PIDSteeringMotor::previous_error_
double previous_error_
Definition
pid_steering_motor.hpp:10
PIDSteeringMotor::compute_steering_rate
double compute_steering_rate(double current_steering, double steering_goal) override
Computes the change in steering angle based on PID control.
Definition
pid_steering_motor.cpp:3
PIDSteeringMotor::last_update
rclcpp::Time last_update
Definition
pid_steering_motor.hpp:11
PIDSteeringMotor::integral_
double integral_
Definition
pid_steering_motor.hpp:9
SteeringMotorModel::car_parameters_
std::shared_ptr< common_lib::car_parameters::CarParameters > car_parameters_
Definition
base_steering_motor_model.hpp:10
pid_steering_motor.hpp
src
motion_lib
src
steering_motor_model
pid_steering_motor.cpp
Generated by
1.9.8