Skip to content

Commit

Permalink
added circuit_breaker_enabled_by_val()
Browse files Browse the repository at this point in the history
added and using circuit_breaker_enabled_by_val() where possible instead of circuit_breaker_enabled() which search for cbrk parameters by name, which is extensive process.
  • Loading branch information
BazookaJoe1900 authored and dagar committed Sep 22, 2019
1 parent c18104d commit fb3a91c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/lib/circuit_breaker/circuit_breaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ bool circuit_breaker_enabled(const char *breaker, int32_t magic)

return (PX4_PARAM_GET_BYNAME(breaker, &val) == 0) && (val == magic);
}

bool circuit_breaker_enabled_by_val(int32_t breaker_val, int32_t magic)
{
return (breaker_val == magic);
}
1 change: 1 addition & 0 deletions src/lib/circuit_breaker/circuit_breaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
__BEGIN_DECLS

extern "C" __EXPORT bool circuit_breaker_enabled(const char *breaker, int32_t magic);
extern "C" __EXPORT bool circuit_breaker_enabled_by_val(int32_t breaker_val, int32_t magic);

__END_DECLS

Expand Down
2 changes: 1 addition & 1 deletion src/lib/mixer_module/mixer_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void MixingOutput::updateParams()
{
ModuleParams::updateParams();

bool safety_disabled = circuit_breaker_enabled("CBRK_IO_SAFETY", CBRK_IO_SAFETY_KEY);
bool safety_disabled = circuit_breaker_enabled_by_val(_param_cbrk_io_safety.get(), CBRK_IO_SAFETY_KEY);

if (safety_disabled) {
_safety_off = true;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/mixer_module/mixer_module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ class MixingOutput : public ModuleParams
(ParamInt<px4::params::MC_AIRMODE>) _param_mc_airmode, ///< multicopter air-mode
(ParamFloat<px4::params::MOT_SLEW_MAX>) _param_mot_slew_max,
(ParamFloat<px4::params::THR_MDL_FAC>) _param_thr_mdl_fac, ///< thrust to pwm modelling factor
(ParamInt<px4::params::MOT_ORDERING>) _param_mot_ordering
(ParamInt<px4::params::MOT_ORDERING>) _param_mot_ordering,
(ParamInt<px4::params::CBRK_IO_SAFETY>) _param_cbrk_io_safety

)
};

20 changes: 8 additions & 12 deletions src/modules/commander/Commander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ void usage(const char *reason);
void control_status_leds(vehicle_status_s *status_local, const actuator_armed_s *actuator_armed, bool changed,
const uint8_t battery_warning, const cpuload_s *cpuload_local);

void get_circuit_breaker_params();

bool stabilization_required();

void print_reject_mode(const char *msg);
Expand Down Expand Up @@ -2469,17 +2467,15 @@ Commander::run()
}

void
get_circuit_breaker_params()
Commander::get_circuit_breaker_params()
{
status_flags.circuit_breaker_engaged_power_check = circuit_breaker_enabled("CBRK_SUPPLY_CHK", CBRK_SUPPLY_CHK_KEY);
status_flags.circuit_breaker_engaged_usb_check = circuit_breaker_enabled("CBRK_USB_CHK", CBRK_USB_CHK_KEY);
status_flags.circuit_breaker_engaged_airspd_check = circuit_breaker_enabled("CBRK_AIRSPD_CHK", CBRK_AIRSPD_CHK_KEY);
status_flags.circuit_breaker_engaged_enginefailure_check = circuit_breaker_enabled("CBRK_ENGINEFAIL",
CBRK_ENGINEFAIL_KEY);
status_flags.circuit_breaker_engaged_gpsfailure_check = circuit_breaker_enabled("CBRK_GPSFAIL", CBRK_GPSFAIL_KEY);
status_flags.circuit_breaker_flight_termination_disabled = circuit_breaker_enabled("CBRK_FLIGHTTERM",
CBRK_FLIGHTTERM_KEY);
status_flags.circuit_breaker_engaged_posfailure_check = circuit_breaker_enabled("CBRK_VELPOSERR", CBRK_VELPOSERR_KEY);
status_flags.circuit_breaker_engaged_power_check = circuit_breaker_enabled_by_val(_param_cbrk_supply_chk.get(), CBRK_SUPPLY_CHK_KEY);
status_flags.circuit_breaker_engaged_usb_check = circuit_breaker_enabled_by_val(_param_cbrk_usb_chk.get(), CBRK_USB_CHK_KEY);
status_flags.circuit_breaker_engaged_airspd_check = circuit_breaker_enabled_by_val(_param_cbrk_airspd_chk.get(), CBRK_AIRSPD_CHK_KEY);
status_flags.circuit_breaker_engaged_enginefailure_check = circuit_breaker_enabled_by_val(_param_cbrk_enginefail.get(), CBRK_ENGINEFAIL_KEY);
status_flags.circuit_breaker_engaged_gpsfailure_check = circuit_breaker_enabled_by_val(_param_cbrk_gpsfail.get(), CBRK_GPSFAIL_KEY);
status_flags.circuit_breaker_flight_termination_disabled = circuit_breaker_enabled_by_val(_param_cbrk_flightterm.get(), CBRK_FLIGHTTERM_KEY);
status_flags.circuit_breaker_engaged_posfailure_check = circuit_breaker_enabled_by_val(_param_cbrk_velposerr.get(), CBRK_VELPOSERR_KEY);
}

void
Expand Down
13 changes: 11 additions & 2 deletions src/modules/commander/Commander.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class Commander : public ModuleBase<Commander>, public ModuleParams
// TODO: only temporarily static until low priority thread is removed
static bool preflight_check(bool report);

void get_circuit_breaker_params();

private:

DEFINE_PARAMETERS(
Expand All @@ -114,7 +116,7 @@ class Commander : public ModuleBase<Commander>, public ModuleParams
(ParamFloat<px4::params::COM_HOME_V_T>) _param_com_home_v_t,

(ParamFloat<px4::params::COM_POS_FS_EPH>) _param_com_pos_fs_eph,
(ParamFloat<px4::params::COM_POS_FS_EPV>) _param_com_pos_fs_epv,
(ParamFloat<px4::params::COM_POS_FS_EPV>) _param_com_pos_fs_epv, /*Not realy used for now*/
(ParamFloat<px4::params::COM_VEL_FS_EVH>) _param_com_vel_fs_evh,
(ParamInt<px4::params::COM_POSCTL_NAVL>) _param_com_posctl_navl, /* failsafe response to loss of navigation accuracy */

Expand Down Expand Up @@ -142,8 +144,15 @@ class Commander : public ModuleBase<Commander>, public ModuleParams
(ParamInt<px4::params::COM_OBL_ACT>) _param_com_obl_act,
(ParamInt<px4::params::COM_OBL_RC_ACT>) _param_com_obl_rc_act,

(ParamInt<px4::params::COM_PREARM_MODE>) _param_com_prearm_mode
(ParamInt<px4::params::COM_PREARM_MODE>) _param_com_prearm_mode,

(ParamInt<px4::params::CBRK_SUPPLY_CHK>) _param_cbrk_supply_chk,
(ParamInt<px4::params::CBRK_USB_CHK>) _param_cbrk_usb_chk,
(ParamInt<px4::params::CBRK_AIRSPD_CHK>) _param_cbrk_airspd_chk,
(ParamInt<px4::params::CBRK_ENGINEFAIL>) _param_cbrk_enginefail,
(ParamInt<px4::params::CBRK_GPSFAIL>) _param_cbrk_gpsfail,
(ParamInt<px4::params::CBRK_FLIGHTTERM>) _param_cbrk_flightterm,
(ParamInt<px4::params::CBRK_VELPOSERR>) _param_cbrk_velposerr
)

enum class PrearmedMode {
Expand Down
5 changes: 4 additions & 1 deletion src/modules/mc_att_control/mc_att_control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ class MulticopterAttitudeControl : public ModuleBase<MulticopterAttitudeControl>
_param_mpc_thr_hover, /**< throttle at which vehicle is at hover equilibrium */
(ParamInt<px4::params::MPC_THR_CURVE>) _param_mpc_thr_curve, /**< throttle curve behavior */

(ParamInt<px4::params::MC_AIRMODE>) _param_mc_airmode
(ParamInt<px4::params::MC_AIRMODE>) _param_mc_airmode,

(ParamInt<px4::params::CBRK_RATE_CTRL>) _param_cbrk_rate_ctrl

)

bool _is_tailsitter{false};
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mc_att_control/mc_att_control_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ MulticopterAttitudeControl::parameters_updated()

_man_tilt_max = math::radians(_param_mpc_man_tilt_max.get());

_actuators_0_circuit_breaker_enabled = circuit_breaker_enabled("CBRK_RATE_CTRL", CBRK_RATE_CTRL_KEY);
_actuators_0_circuit_breaker_enabled = circuit_breaker_enabled_by_val(_param_cbrk_rate_ctrl.get(), CBRK_RATE_CTRL_KEY);
}

void
Expand Down

0 comments on commit fb3a91c

Please sign in to comment.