Skip to content

Commit

Permalink
Support pass in a precomputed derivative error
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjunnn authored and bmagyar committed May 6, 2022
1 parent 3e389b9 commit e13643b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/control_toolbox/pid_ros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ class CONTROL_TOOLBOX_PUBLIC PidROS
*/
double computeCommand(double error, rclcpp::Duration dt);

/*!
* \brief Set the PID error and compute the PID command with nonuniform
* time step size. This also allows the user to pass in a precomputed
* derivative error.
*
* \param error Error since last call (error = target - state)
* \param error_dot d(Error)/dt since last call
* \param dt Change in time since last call in seconds
*
* \returns PID command
*/
double computeCommand(double error, double error_dot, rclcpp::Duration dt);

/*!
* \brief Get PID gains for the controller.
* \return gains A struct of the PID gain values
Expand Down
8 changes: 8 additions & 0 deletions src/pid_ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ PidROS::computeCommand(double error, rclcpp::Duration dt)
return cmd_;
}

double PidROS::computeCommand(double error, double error_dot, rclcpp::Duration dt)
{
double cmd_ = pid_.computeCommand(error, error_dot, dt.nanoseconds());
publishPIDState(cmd_, error, dt);

return cmd_;
}

Pid::Gains
PidROS::getGains()
{
Expand Down

0 comments on commit e13643b

Please sign in to comment.