@@ -107,28 +107,15 @@ bool Controller::is_throttle_high(float threshold) {
107107 RF_.command_manager_ .combined_control ().Fz .value > threshold;
108108}
109109
110- void Controller::run ()
110+ void Controller::run (const float dt )
111111{
112- // Time calculation
113- if (prev_time_us_ == 0 ) {
114- prev_time_us_ = RF_.estimator_ .state ().timestamp_us ;
115- return ;
116- }
117-
118- int32_t dt_us = (RF_.estimator_ .state ().timestamp_us - prev_time_us_);
119- if (dt_us < 0 ) {
120- RF_.state_manager_ .set_error (StateManager::ERROR_TIME_GOING_BACKWARDS);
121- return ;
122- }
123- prev_time_us_ = RF_.estimator_ .state ().timestamp_us ;
124-
125112 // Check if integrators should be updated
126113 bool update_integrators = (RF_.state_manager_ .state ().armed )
127- && is_throttle_high (0 .1f ) && dt_us < 10000 ;
114+ && is_throttle_high (0 .1f ) && dt < 0.01 ;
128115
129116 // Run the PID loops
130117 Controller::Output pid_output = run_pid_loops (
131- dt_us , RF_.estimator_ .state (), RF_.command_manager_ .combined_control (), update_integrators);
118+ dt , RF_.estimator_ .state (), RF_.command_manager_ .combined_control (), update_integrators);
132119
133120 // Add feedforward torques
134121 output_.Qx = pid_output.Qx + RF_.params_ .get_param_float (PARAM_X_EQ_TORQUE);
@@ -225,14 +212,12 @@ void Controller::param_change_callback(uint16_t param_id)
225212 }
226213}
227214
228- Controller::Output Controller::run_pid_loops (uint32_t dt_us , const Estimator::State & state,
215+ Controller::Output Controller::run_pid_loops (const float dt , const Estimator::State & state,
229216 const control_t & command, bool update_integrators)
230217{
231218 // Based on the control types coming from the command manager, run the appropriate PID loops
232219 Controller::Output out;
233220
234- float dt = 1e-6 * dt_us;
235-
236221 // ROLL
237222 if (command.Qx .type == RATE) {
238223 out.Qx = roll_rate_.run (dt, state.angular_velocity .x , command.Qx .value , update_integrators);
@@ -330,7 +315,7 @@ void Controller::PID::init(float kp, float ki, float kd, float max, float min, f
330315 tau_ = tau;
331316}
332317
333- float Controller::PID::run (float dt, float x, float x_c, bool update_integrator)
318+ float Controller::PID::run (const float dt, float x, float x_c, bool update_integrator)
334319{
335320 float xdot;
336321 if (dt > 0 .0001f ) {
@@ -348,7 +333,7 @@ float Controller::PID::run(float dt, float x, float x_c, bool update_integrator)
348333 return run (dt, x, x_c, update_integrator, xdot);
349334}
350335
351- float Controller::PID::run (float dt, float x, float x_c, bool update_integrator, float xdot)
336+ float Controller::PID::run (const float dt, float x, float x_c, bool update_integrator, float xdot)
352337{
353338 // Calculate Error
354339 float error = x_c - x;
0 commit comments