Skip to content

Add P gain value for Ackermann steering. #1873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/systems/ackermann_steering/AckermannSteering.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ class gz::sim::systems::AckermannSteeringPrivate
/// \brief Last target angle requested.
public: msgs::Double targetAng;

/// \brief P gain for angular position.
public: double gainPAng{1.0};

/// \brief A mutex to protect the target velocity command.
public: std::mutex mutex;

Expand Down Expand Up @@ -290,6 +293,11 @@ void AckermannSteering::Configure(const Entity &_entity,
this->dataPtr->steeringLimit = _sdf->Get<double>("steering_limit",
this->dataPtr->steeringLimit).first;

// Get proportional gain for steering angle.
if (_sdf->HasElement("steer_p_gain"))
{
this->dataPtr->gainPAng = _sdf->Get<double>("steer_p_gain");
}

// Instantiate the speed limiters.
this->dataPtr->limiterLin = std::make_unique<math::SpeedLimiter>();
Expand Down Expand Up @@ -927,11 +935,10 @@ void AckermannSteeringPrivate::UpdateAngle(
double leftDelta = leftSteeringJointAngle - leftSteeringPos->Data()[0];
double rightDelta = rightSteeringJointAngle - rightSteeringPos->Data()[0];

// Simple proportional control with a gain of 1
// Simple proportional control with settable gain.
// Adding programmable PID values might be a future feature.
// Works as is for tested cases
this->leftSteeringJointSpeed = leftDelta;
this->rightSteeringJointSpeed = rightDelta;
this->leftSteeringJointSpeed = this->gainPAng * leftDelta;
this->rightSteeringJointSpeed = this->gainPAng * rightDelta;
}

//////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions src/systems/ackermann_steering/AckermannSteering.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ namespace systems
/// and wheel_separation. Uses gz::msg::Double on default topic name
/// `/model/{name_of_model}/steer_angle`
///
/// `<steer_p_gain>`: Float used to control the steering angle P gain.
/// Only used for when in steering_only mode.
///
/// `<left_joint>`: Name of a joint that controls a left wheel. This
/// element can appear multiple times, and must appear at least once.
///
Expand Down
1 change: 1 addition & 0 deletions test/worlds/ackermann_steering_only.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@
<left_steering_joint>front_left_wheel_steering_joint</left_steering_joint>
<right_steering_joint>front_right_wheel_steering_joint</right_steering_joint>
<steering_only>true</steering_only>
<steer_p_gain>10.0</steer_p_gain>
<steering_limit>0.5</steering_limit>
<wheel_base>1.0</wheel_base>
<wheel_separation>1.25</wheel_separation>
Expand Down