Skip to content

Commit

Permalink
differential: reset integrators when disarmed (PX4#23637)
Browse files Browse the repository at this point in the history
  • Loading branch information
chfriedrich98 committed Sep 3, 2024
1 parent 8f6ce4e commit a9cdb36
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/modules/rover_differential/RoverDifferential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ void RoverDifferential::Run()
break;
}

if (!_armed) { // Reset on disarm
_rover_differential_control.resetControllers();
}

_rover_differential_control.computeMotorCommands(_vehicle_yaw, _vehicle_yaw_rate, _vehicle_forward_speed);

}
Expand All @@ -132,6 +136,7 @@ void RoverDifferential::updateSubscriptions()
vehicle_status_s vehicle_status{};
_vehicle_status_sub.copy(&vehicle_status);
_nav_state = vehicle_status.nav_state;
_armed = vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED;
}

if (_vehicle_angular_velocity_sub.updated()) {
Expand Down
1 change: 1 addition & 0 deletions src/modules/rover_differential/RoverDifferential.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class RoverDifferential : public ModuleBase<RoverDifferential>, public ModulePar
float _vehicle_yaw{0.f};
float _max_yaw_rate{0.f};
int _nav_state{0};
bool _armed{false};

DEFINE_PARAMETERS(
(ParamFloat<px4::params::RD_MAN_YAW_SCALE>) _param_rd_man_yaw_scale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,10 @@ matrix::Vector2f RoverDifferentialControl::computeInverseKinematics(float forwar
return Vector2f(forward_speed_normalized - speed_diff_normalized,
forward_speed_normalized + speed_diff_normalized);
}

void RoverDifferentialControl::resetControllers()
{
pid_reset_integral(&_pid_throttle);
pid_reset_integral(&_pid_yaw_rate);
pid_reset_integral(&_pid_yaw);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class RoverDifferentialControl : public ModuleParams
*/
void computeMotorCommands(float vehicle_yaw, float vehicle_yaw_rate, float vehicle_forward_speed);

/**
* @brief Reset PID controllers
*/
void resetControllers();

protected:
/**
* @brief Update the parameters of the module.
Expand Down

0 comments on commit a9cdb36

Please sign in to comment.