Skip to content

Commit 8dfbba3

Browse files
committed
minor code cleanup
1 parent be8a43a commit 8dfbba3

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

include/controller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Controller : public ParamListenerInterface
7070
void calculate_max_thrust();
7171
void calculate_equilbrium_torque_from_rc();
7272
void param_change_callback(uint16_t param_id) override;
73+
bool is_throttle_high(float threshold);
7374

7475
private:
7576
class PID

include/mixer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class Mixer : public ParamListenerInterface
278278
float R_; // Motor resistance
279279
float rho_; // Air density
280280
float K_V_; // Motor back-emf constant
281-
float K_Q_ = 0.01706; // Motor torque constant
281+
float K_Q_; // Motor torque constant
282282
float i_0_; // Motor no-load current
283283
float D_; // Propeller diameter
284284
float C_T_; // Thrust coefficient

src/command_manager.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ void CommandManager::init_failsafe()
114114
void CommandManager::interpret_rc(void)
115115
{
116116
// get initial, unscaled RC values
117-
// TODO: Adjust this to choose the channel that the RC thottle corresponds to
118117
rc_command_.Qx.value = RF_.rc_.stick(RC::STICK_X);
119118
rc_command_.Qy.value = RF_.rc_.stick(RC::STICK_Y);
120119
rc_command_.Qz.value = RF_.rc_.stick(RC::STICK_Z);
@@ -307,7 +306,6 @@ bool CommandManager::run()
307306
if (RF_.board_.clock_millis()
308307
> offboard_command_.stamp_ms + RF_.params_.get_param_int(PARAM_OFFBOARD_TIMEOUT)) {
309308
// If it has been longer than 100 ms, then disable the offboard control
310-
// TODO: Check to make sure the FX and FY commands can be set to true
311309
offboard_command_.Fx.active = false;
312310
offboard_command_.Fy.active = false;
313311
offboard_command_.Fz.active = false;

src/controller.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ void Controller::calculate_max_thrust()
101101
max_thrust_ = rho * pow(D, 4.0) * CT * pow(omega, 2.0) / (4 * pow(M_PI, 2.0)) * num_motors;
102102
}
103103

104+
bool Controller::is_throttle_high(float threshold) {
105+
return RF_.command_manager_.combined_control().Fx.value > threshold ||
106+
RF_.command_manager_.combined_control().Fy.value > threshold ||
107+
RF_.command_manager_.combined_control().Fz.value > threshold;
108+
}
109+
104110
void Controller::run()
105111
{
106112
// Time calculation
@@ -117,10 +123,8 @@ void Controller::run()
117123
prev_time_us_ = RF_.estimator_.state().timestamp_us;
118124

119125
// Check if integrators should be updated
120-
//! @todo better way to figure out if throttle is high
121-
// TODO: fix this... Needs to be checked based on the throttle channel (not necessarily Fz)
122126
bool update_integrators = (RF_.state_manager_.state().armed)
123-
&& (RF_.command_manager_.combined_control().Fz.value > 0.1f) && dt_us < 10000;
127+
&& is_throttle_high(0.1f) && dt_us < 10000;
124128

125129
// Run the PID loops
126130
Controller::Output pid_output = run_pid_loops(

src/mixer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -805,17 +805,17 @@ void Mixer::mix_fixedwing()
805805
Controller::Output commands = RF_.controller_.output();
806806

807807
// Reverse fixed-wing channels just before mixing if we need to
808-
if (RF_.params_.get_param_int(PARAM_FIXED_WING)) {
809-
commands.Qx *= RF_.params_.get_param_int(PARAM_AILERON_REVERSE) ? -1 : 1;
810-
commands.Qy *= RF_.params_.get_param_int(PARAM_ELEVATOR_REVERSE) ? -1 : 1;
811-
commands.Qz *= RF_.params_.get_param_int(PARAM_RUDDER_REVERSE) ? -1 : 1;
812-
}
808+
commands.Qx *= RF_.params_.get_param_int(PARAM_AILERON_REVERSE) ? -1 : 1;
809+
commands.Qy *= RF_.params_.get_param_int(PARAM_ELEVATOR_REVERSE) ? -1 : 1;
810+
commands.Qz *= RF_.params_.get_param_int(PARAM_RUDDER_REVERSE) ? -1 : 1;
813811

814812
// Mix the outputs
815813
for (uint8_t i = 0; i < NUM_MIXER_OUTPUTS; i++) {
816814
if ((*mixer_to_use_.output_type)[i] != NONE) {
817815
// Matrix multiply to mix outputs
818816
outputs_[i] = commands.Fx * (*mixer_to_use_.Fx)[i] +
817+
commands.Fy * (*mixer_to_use_.Fy)[i] +
818+
commands.Fz * (*mixer_to_use_.Fz)[i] +
819819
commands.Qx * (*mixer_to_use_.Qx)[i] +
820820
commands.Qy * (*mixer_to_use_.Qy)[i] +
821821
commands.Qz * (*mixer_to_use_.Qz)[i];

0 commit comments

Comments
 (0)