mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
rc_update: add unit tests for two way payload power switch
with the intention to extend it to an optional 3 way switch.
This commit is contained in:
parent
8e7c2ed440
commit
1bccd5557a
@ -128,13 +128,39 @@ public:
|
||||
EXPECT_EQ(manual_control_switches_sub.get().return_switch, expected_position);
|
||||
}
|
||||
|
||||
void checkPayloadPowerSwitch(float channel_value, float threshold, uint8_t expected_position)
|
||||
{
|
||||
// GIVEN: First channel is configured as payload power switch
|
||||
_param_rc_map_pay_sw.set(1);
|
||||
_param_rc_map_pay_sw.commit();
|
||||
_param_rc_payload_th.set(threshold);
|
||||
_param_rc_payload_th.commit();
|
||||
_rc_update.updateParams();
|
||||
EXPECT_EQ(_param_rc_map_pay_sw.get(), 1);
|
||||
EXPECT_FLOAT_EQ(_param_rc_payload_th.get(), threshold);
|
||||
// GIVEN: First channel has some value
|
||||
_rc_update.setChannel(0, channel_value);
|
||||
|
||||
// WHEN: we update the switches two times to pass the simple outlier protection
|
||||
_rc_update.UpdateManualSwitches(0);
|
||||
_rc_update.UpdateManualSwitches(0);
|
||||
|
||||
// THEN: we receive the expected mode slot
|
||||
uORB::SubscriptionData<manual_control_switches_s> manual_control_switches_sub{ORB_ID(manual_control_switches)};
|
||||
EXPECT_EQ(manual_control_switches_sub.get().payload_power_switch, expected_position);
|
||||
}
|
||||
|
||||
TestRCUpdate _rc_update;
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamInt<px4::params::RC_MAP_FLTMODE>) _param_rc_map_fltmode,
|
||||
(ParamInt<px4::params::RC_MAP_FLTM_BTN>) _param_rc_map_fltm_btn,
|
||||
|
||||
(ParamInt<px4::params::RC_MAP_RETURN_SW>) _param_rc_map_return_sw,
|
||||
(ParamFloat<px4::params::RC_RETURN_TH>) _param_rc_return_th
|
||||
(ParamFloat<px4::params::RC_RETURN_TH>) _param_rc_return_th,
|
||||
|
||||
(ParamInt<px4::params::RC_MAP_PAY_SW>) _param_rc_map_pay_sw,
|
||||
(ParamFloat<px4::params::RC_PAYLOAD_TH>) _param_rc_payload_th
|
||||
)
|
||||
};
|
||||
|
||||
@ -233,3 +259,44 @@ TEST_F(RCUpdateTest, ReturnSwitchNegativeThresholds)
|
||||
checkReturnSwitch(1.f, -.001f, 3); // Above minimum threshold -> SWITCH_POS_OFF
|
||||
checkReturnSwitch(-1.f, -.001f, 1); // Slightly below minimum threshold -> SWITCH_POS_OFF
|
||||
}
|
||||
|
||||
TEST_F(RCUpdateTest, PayloadPowerSwitchPositiveThresholds)
|
||||
{
|
||||
checkPayloadPowerSwitch(-1.f, 0.5f, 3); // Below threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(0.f, 0.5f, 3); // On threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(.001f, 0.5f, 1); // Slightly above threshold -> SWITCH_POS_ON
|
||||
checkPayloadPowerSwitch(1.f, 0.5f, 1); // Above threshold -> SWITCH_POS_ON
|
||||
|
||||
checkPayloadPowerSwitch(-1.f, 0.75f, 3); // Below threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(0.f, 0.75f, 3); // Below threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(.5f, 0.75f, 3); // On threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(.501f, 0.75f, 1); // Slightly above threshold -> SWITCH_POS_ON
|
||||
checkPayloadPowerSwitch(1.f, 0.75f, 1); // Above threshold -> SWITCH_POS_ON
|
||||
|
||||
checkPayloadPowerSwitch(-1.f, 0.f, 3); // On minimum threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(-.999f, 0.f, 1); // Slightly above minimum threshold -> SWITCH_POS_ON
|
||||
checkPayloadPowerSwitch(1.f, 0.f, 1); // Above minimum threshold -> SWITCH_POS_ON
|
||||
|
||||
checkPayloadPowerSwitch(-1.f, 1.f, 3); // Below maximum threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(1.f, 1.f, 3); // On maximum threshold -> SWITCH_POS_OFF
|
||||
}
|
||||
|
||||
TEST_F(RCUpdateTest, PayloadPowerSwitchNegativeThresholds)
|
||||
{
|
||||
checkPayloadPowerSwitch(1.f, -0.5f, 3); // Above threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(0.f, -0.5f, 3); // On threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(-.001f, -0.5f, 1); // Slightly below threshold -> SWITCH_POS_ON
|
||||
checkPayloadPowerSwitch(-1.f, -0.5f, 1); // Below threshold -> SWITCH_POS_ON
|
||||
|
||||
checkPayloadPowerSwitch(1.f, -0.75f, 3); // Above threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(.5f, -0.75f, 3); // On threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(.499f, -0.75f, 1); // Slightly below threshold -> SWITCH_POS_ON
|
||||
checkPayloadPowerSwitch(-1.f, -0.75f, 1); // Below threshold -> SWITCH_POS_ON
|
||||
|
||||
checkPayloadPowerSwitch(1.f, -1.f, 3); // On maximum threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(.999f, -1.f, 1); // Slighly below maximum threshold -> SWITCH_POS_ON
|
||||
checkPayloadPowerSwitch(-1.f, -1.f, 1); // Below minimum threshold -> SWITCH_POS_ON
|
||||
|
||||
checkPayloadPowerSwitch(1.f, -.001f, 3); // Above minimum threshold -> SWITCH_POS_OFF
|
||||
checkPayloadPowerSwitch(-1.f, -.001f, 1); // Slightly below minimum threshold -> SWITCH_POS_OFF
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user