Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Very primitive K-based PID control. Could work.
Browse files Browse the repository at this point in the history
  • Loading branch information
aentinger committed May 13, 2024
1 parent 95127f7 commit a1e086d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,28 @@ void Node::handle_Driving()
{
RCLCPP_INFO_THROTTLE(get_logger(), *get_clock(), 1000UL, "handle_Driving");

/* TODO: add control code. */
auto const yaw_err = (_yaw_target - _yaw_actual);

double const k = 0.01;
double const pid_res = k * yaw_err.numerical_value_in(deg);

_motor_left_vel = 0.5 * m/s - pid_res * m/s;
_motor_left_vel = std::max(_motor_left_vel, 0.3 * m/s);
_motor_left_vel = std::min(_motor_left_vel, 0.7 * m/s);

_motor_right_vel = 0.5 * m/s + pid_res * m/s;
_motor_right_vel = std::max(_motor_right_vel, 0.3 * m/s);
_motor_right_vel = std::min(_motor_right_vel, 0.7 * m/s);

RCLCPP_INFO(get_logger(),
"actual = %0.2f, target = %0.2f, error = %0.2f, pid_res = %0.2f, LEFT = %0.2f m/s, RIGHT = %0.2f m/s",
_yaw_actual.numerical_value_in(deg),
_yaw_target.numerical_value_in(deg),
yaw_err.numerical_value_in(deg),
pid_res,
_motor_left_vel.numerical_value_in(m/s),
_motor_right_vel.numerical_value_in(m/s));

pub_motor_left (_motor_left_vel);
pub_motor_right(_motor_right_vel);
}
Expand Down

0 comments on commit a1e086d

Please sign in to comment.