mixer: use an enum for airmode

This commit is contained in:
Beat Küng 2018-11-23 19:40:27 +01:00
parent 9406fa5246
commit 19ccab28bb
11 changed files with 33 additions and 26 deletions

View File

@ -116,7 +116,7 @@ static void subscribe();
static void task_main(int argc, char *argv[]);
static void update_params(int32_t &airmode);
static void update_params(Mixer::Airmode &airmode);
/* mixer initialization */
int initialize_mixer(const char *mixer_filename);
@ -135,7 +135,7 @@ int mixer_control_callback(uintptr_t handle,
}
void update_params(int32_t &airmode)
void update_params(Mixer::Airmode &airmode)
{
// multicopter air-mode
param_t param_handle = param_find("MC_AIRMODE");
@ -255,7 +255,7 @@ void task_main(int argc, char *argv[])
// subscribe and set up polling
subscribe();
int32_t airmode = false;
Mixer::Airmode airmode = Mixer::Airmode::disabled;
update_params(airmode);
int params_sub = orb_subscribe(ORB_ID(parameter_update));

View File

@ -131,7 +131,7 @@ private:
actuator_controls_s _controls[actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS] {};
orb_id_t _control_topics[actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS] {};
int32_t _airmode{0}; ///< multicopter air-mode
Mixer::Airmode _airmode{Mixer::Airmode::disabled}; ///< multicopter air-mode
perf_counter_t _perf_control_latency;

View File

@ -237,7 +237,7 @@ private:
float _mot_t_max; ///< maximum rise time for motor (slew rate limiting)
float _thr_mdl_fac; ///< thrust to pwm modelling factor
int32_t _airmode; ///< multicopter air-mode
Mixer::Airmode _airmode; ///< multicopter air-mode
MotorOrdering _motor_ordering;
perf_counter_t _perf_control_latency;
@ -321,7 +321,7 @@ PX4FMU::PX4FMU(bool run_as_task) :
_to_mixer_status(nullptr),
_mot_t_max(0.0f),
_thr_mdl_fac(0.0f),
_airmode(0),
_airmode(Mixer::Airmode::disabled),
_motor_ordering(MotorOrdering::PX4),
_perf_control_latency(perf_alloc(PC_ELAPSED, "fmu control latency"))
{

View File

@ -138,7 +138,7 @@ static void subscribe();
static void task_main(int argc, char *argv[]);
static void update_params(int32_t &airmode);
static void update_params(Mixer::Airmode &airmode);
int initialize_mixer(const char *mixer_filename);
@ -162,7 +162,7 @@ int mixer_control_callback(uintptr_t handle,
return 0;
}
void update_params(int32_t &airmode)
void update_params(Mixer::Airmode &airmode)
{
// multicopter air-mode
param_t param_handle = param_find("MC_AIRMODE");
@ -355,7 +355,7 @@ void task_main(int argc, char *argv[])
// subscribe and set up polling
subscribe();
int32_t airmode = 0;
Mixer::Airmode airmode = Mixer::Airmode::disabled;
update_params(airmode);
int params_sub = orb_subscribe(ORB_ID(parameter_update));

View File

@ -141,7 +141,7 @@ private:
EscPacket _packet = {};
DEFINE_PARAMETERS(
(ParamBool<px4::params::MC_AIRMODE>) _airmode ///< multicopter air-mode
(ParamInt<px4::params::MC_AIRMODE>) _airmode ///< multicopter air-mode
)
void subscribe();
@ -420,7 +420,7 @@ void TAP_ESC::cycle()
}
if (_mixers) {
_mixers->set_airmode(_airmode.get());
_mixers->set_airmode((Mixer::Airmode)_airmode.get());
}
/* check if anything updated */

View File

@ -210,7 +210,7 @@ private:
perf_counter_t _perf_control_latency;
int32_t _airmode = 0;
Mixer::Airmode _airmode = Mixer::Airmode::disabled;
// index into _poll_fds for each _control_subs handle
uint8_t _poll_ids[NUM_ACTUATOR_CONTROL_GROUPS_UAVCAN];

View File

@ -140,6 +140,12 @@
class __EXPORT Mixer
{
public:
enum class Airmode : int32_t {
disabled = 0,
roll_pitch = 1,
roll_pitch_yaw = 2
};
/** next mixer in a list */
Mixer *_next;
@ -223,7 +229,7 @@ public:
*
* @param[in] airmode Select airmode type (0 = disabled, 1 = roll/pitch, 2 = roll/pitch/yaw)
*/
virtual void set_airmode(int32_t airmode) {};
virtual void set_airmode(Airmode airmode) {};
protected:
/** client-supplied callback used when fetching control values */
@ -419,7 +425,7 @@ public:
*/
void set_thrust_factor(float val) override;
void set_airmode(int32_t airmode) override;
void set_airmode(Airmode airmode) override;
private:
Mixer *_first; /**< linked list of mixers */
@ -667,7 +673,7 @@ public:
*/
void set_thrust_factor(float val) override { _thrust_factor = val; }
void set_airmode(int32_t airmode) override;
void set_airmode(Airmode airmode) override;
union saturation_status {
struct {
@ -694,7 +700,7 @@ private:
float _delta_out_max;
float _thrust_factor;
uint32_t _airmode;
Airmode _airmode;
void update_saturation_status(unsigned index, bool clipping_high, bool clipping_low);
saturation_status _saturation_status;

View File

@ -188,7 +188,7 @@ MixerGroup::set_thrust_factor(float val)
}
void
MixerGroup::set_airmode(int32_t airmode)
MixerGroup::set_airmode(Airmode airmode)
{
Mixer *mixer = _first;

View File

@ -72,7 +72,7 @@ MultirotorMixer::MultirotorMixer(ControlCallback control_cb,
_idle_speed(-1.0f + idle_speed * 2.0f), /* shift to output range here to avoid runtime calculation */
_delta_out_max(0.0f),
_thrust_factor(0.0f),
_airmode(0),
_airmode(Airmode::disabled),
_rotor_count(_config_rotor_count[(MultirotorGeometryUnderlyingType)geometry]),
_rotors(_config_index[(MultirotorGeometryUnderlyingType)geometry]),
_outputs_prev(new float[_rotor_count])
@ -214,7 +214,7 @@ MultirotorMixer::mix(float *outputs, unsigned space)
boost = 1.0f - ((max_out - thrust) * roll_pitch_scale + thrust);
}
if (_airmode == 0) {
if (_airmode == Airmode::disabled) {
// disable positive boosting if not in air-mode
// boosting can only be positive when min_out < 0.0
// roll_pitch_scale is reduced accordingly
@ -425,7 +425,7 @@ MultirotorMixer::update_saturation_status(unsigned index, bool clipping_high, bo
}
void
MultirotorMixer::set_airmode(int32_t airmode)
MultirotorMixer::set_airmode(Airmode airmode)
{
_airmode = airmode;
}

View File

@ -569,14 +569,15 @@ PARAM_DEFINE_FLOAT(MC_DTERM_CUTOFF, 30.f);
*
* The air-mode enables the mixer to increase the total thrust of the multirotor
* in order to keep attitude and rate control even at low and high throttle.
*
* This function should be disabled during tuning as it will help the controller
* to diverge if the closed-loop is unstable.
* to diverge if the closed-loop is unstable (i.e. the vehicle is not tuned yet).
*
* 0 = Disabled, 1 = Roll/Pitch, 2 = Roll/Pitch/Yaw
* Enabling air-mode for yaw requires the use of an arming switch.
*
* @min 0
* @max 2
* @decimal 0
* @value 0 Disabled
* @value 1 Roll/Pitch
* @value 2 Roll/Pitch/Yaw
* @group Multicopter Attitude Control
*/
PARAM_DEFINE_INT32(MC_AIRMODE, 0);

View File

@ -259,7 +259,7 @@ mixer_tick(void)
/*
* Update air-mode parameter
*/
mixer_group.set_airmode(REG_TO_BOOL(r_setup_airmode));
mixer_group.set_airmode((Mixer::Airmode)REG_TO_SIGNED(r_setup_airmode));
/*