Skip to content

Commit

Permalink
Add payload power switch
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKlimaj committed Oct 25, 2024
1 parent 25f91d1 commit b02384e
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 5 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ px4io_update:
bootloaders_update: \
3dr_ctrl-zero-h7-oem-revg_bootloader \
ark_fmu-v6x_bootloader \
ark_fpv_bootloader \
ark_pi6x_bootloader \
cuav_nora_bootloader \
cuav_x7pro_bootloader \
Expand Down
Binary file modified boards/ark/fpv/extras/ark_fpv_bootloader.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion boards/ark/fpv/src/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
/* Define True logic Power Control in arch agnostic form */

#define VDD_3V3_SD_CARD_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_3V3_SD_CARD_EN, (on_true))
#define VDD_12V_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_12V_EN, (on_true))
#define PAYLOAD_POWER_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_12V_EN, (on_true))

/* USB OTG FS
*
Expand Down
6 changes: 3 additions & 3 deletions boards/ark/fpv/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ __EXPORT void board_peripheral_reset(int ms)
{
/* set the peripheral rails off */

VDD_12V_EN(false);
PAYLOAD_POWER_EN(false);
board_control_spi_sensors_power(false, 0xffff);

/* wait for the peripheral rail to reach GND */
Expand All @@ -121,7 +121,7 @@ __EXPORT void board_peripheral_reset(int ms)

/* switch the peripheral rail back on */
board_control_spi_sensors_power(true, 0xffff);
VDD_12V_EN(true);
PAYLOAD_POWER_EN(true);
}

/************************************************************************************
Expand Down Expand Up @@ -204,7 +204,7 @@ stm32_boardinitialize(void)
__EXPORT int board_app_initialize(uintptr_t arg)
{
/* Power on Interfaces */
VDD_12V_EN(true);
PAYLOAD_POWER_EN(true);

/* Need hrt running before using the ADC */

Expand Down
2 changes: 2 additions & 0 deletions msg/ManualControlSwitches.msg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ uint8 transition_switch # VTOL transition switch: _HOVER, FORWARD_FLIGH
uint8 photo_switch # Photo trigger switch
uint8 video_switch # Photo trigger switch

uint8 payload_power_switch # Payload power switch

uint8 engage_main_motor_switch # Engage the main motor (for helicopters)

uint32 switch_changes # number of switch changes
3 changes: 2 additions & 1 deletion msg/RcChannels.msg
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ uint8 FUNCTION_FLTBTN_SLOT_4 = 24
uint8 FUNCTION_FLTBTN_SLOT_5 = 25
uint8 FUNCTION_FLTBTN_SLOT_6 = 26
uint8 FUNCTION_ENGAGE_MAIN_MOTOR = 27
uint8 FUNCTION_PAYLOAD_POWER = 28

uint8 FUNCTION_FLTBTN_SLOT_COUNT = 6

uint64 timestamp_last_valid # Timestamp of last valid RC signal
float32[18] channels # Scaled to -1..1 (throttle: 0..1)
uint8 channel_count # Number of valid channels
int8[28] function # Functions mapping
int8[29] function # Functions mapping
uint8 rssi # Receive signal strength index
bool signal_lost # Control signal lost, should be checked together with topic timeout
uint32 frame_drop_count # Number of dropped frames
13 changes: 13 additions & 0 deletions src/modules/manual_control/ManualControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,19 @@ void ManualControl::processSwitches(hrt_abstime &now)
}
}

#if defined(PAYLOAD_POWER_EN)

if (switches.payload_power_switch != _previous_switches.payload_power_switch) {
if (switches.payload_power_switch == manual_control_switches_s::SWITCH_POS_ON) {
PAYLOAD_POWER_EN(true);

} else if (switches.payload_power_switch == manual_control_switches_s::SWITCH_POS_OFF) {
PAYLOAD_POWER_EN(false);
}
}

#endif // PAYLOAD_POWER_EN

} else if (!_armed) {
// Directly initialize mode using RC switch but only before arming
evaluateModeSlot(switches.mode_slot);
Expand Down
45 changes: 45 additions & 0 deletions src/modules/rc_update/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,35 @@ PARAM_DEFINE_INT32(RC_MAP_AUX5, 0);
* @value 18 Channel 18
*/
PARAM_DEFINE_INT32(RC_MAP_AUX6, 0);

/**
* Payload Power Switch RC channel
*
* @min 0
* @max 18
* @group Radio Switches
* @value 0 Unassigned
* @value 1 Channel 1
* @value 2 Channel 2
* @value 3 Channel 3
* @value 4 Channel 4
* @value 5 Channel 5
* @value 6 Channel 6
* @value 7 Channel 7
* @value 8 Channel 8
* @value 9 Channel 9
* @value 10 Channel 10
* @value 11 Channel 11
* @value 12 Channel 12
* @value 13 Channel 13
* @value 14 Channel 14
* @value 15 Channel 15
* @value 16 Channel 16
* @value 17 Channel 17
* @value 18 Channel 18
*/
PARAM_DEFINE_INT32(RC_MAP_PAY_SW, 0);

/**
* PARAM1 tuning channel
*
Expand Down Expand Up @@ -2029,6 +2058,22 @@ PARAM_DEFINE_FLOAT(RC_GEAR_TH, 0.75f);
*/
PARAM_DEFINE_FLOAT(RC_ENG_MOT_TH, 0.75f);

/**
* Threshold for selecting payload power switch
*
* 0-1 indicate where in the full channel range the threshold sits
* 0 : min
* 1 : max
* sign indicates polarity of comparison
* positive : true when channel>th
* negative : true when channel<th
*
* @min -1
* @max 1
* @group Radio Switches
*/
PARAM_DEFINE_FLOAT(RC_PAYLOAD_TH, 0.75f);

/**
* PWM input channel that provides RSSI.
*
Expand Down
8 changes: 8 additions & 0 deletions src/modules/rc_update/rc_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static bool operator ==(const manual_control_switches_s &a, const manual_control
a.gear_switch == b.gear_switch &&
a.photo_switch == b.photo_switch &&
a.video_switch == b.video_switch &&
a.payload_power_switch == b.payload_power_switch &&
a.engage_main_motor_switch == b.engage_main_motor_switch);
}

Expand Down Expand Up @@ -219,6 +220,8 @@ void RCUpdate::update_rc_functions()
_rc.function[rc_channels_s::FUNCTION_AUX_5] = _param_rc_map_aux5.get() - 1;
_rc.function[rc_channels_s::FUNCTION_AUX_6] = _param_rc_map_aux6.get() - 1;

_rc.function[rc_channels_s::FUNCTION_PAYLOAD_POWER] = _param_rc_map_payload_sw.get() - 1;

for (int i = 0; i < rc_parameter_map_s::RC_PARAM_MAP_NCHAN; i++) {
_rc.function[rc_channels_s::FUNCTION_PARAM_1 + i] = _parameters.rc_map_param[i] - 1;
}
Expand Down Expand Up @@ -616,6 +619,11 @@ void RCUpdate::UpdateManualSwitches(const hrt_abstime &timestamp_sample)
switches.video_switch = getRCSwitchOnOffPosition(rc_channels_s::FUNCTION_AUX_4, 0.5f);
#endif

#if defined(PAYLOAD_POWER_EN)
switches.payload_power_switch = getRCSwitchOnOffPosition(rc_channels_s::FUNCTION_PAYLOAD_POWER,
_param_rc_payload_th.get());
#endif

// last 2 switch updates identical within 1 second (simple protection from bad RC data)
if ((switches == _manual_switches_previous)
&& (switches.timestamp_sample < _manual_switches_previous.timestamp_sample + VALID_DATA_MIN_INTERVAL_US)) {
Expand Down
3 changes: 3 additions & 0 deletions src/modules/rc_update/rc_update.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ class RCUpdate : public ModuleBase<RCUpdate>, public ModuleParams, public px4::W

(ParamInt<px4::params::RC_FAILS_THR>) _param_rc_fails_thr,

(ParamInt<px4::params::RC_MAP_PAY_SW>) _param_rc_map_payload_sw,

(ParamFloat<px4::params::RC_LOITER_TH>) _param_rc_loiter_th,
(ParamFloat<px4::params::RC_OFFB_TH>) _param_rc_offb_th,
(ParamFloat<px4::params::RC_KILLSWITCH_TH>) _param_rc_killswitch_th,
Expand All @@ -238,6 +240,7 @@ class RCUpdate : public ModuleBase<RCUpdate>, public ModuleParams, public px4::W
(ParamFloat<px4::params::RC_GEAR_TH>) _param_rc_gear_th,
(ParamFloat<px4::params::RC_RETURN_TH>) _param_rc_return_th,
(ParamFloat<px4::params::RC_ENG_MOT_TH>) _param_rc_eng_mot_th,
(ParamFloat<px4::params::RC_PAYLOAD_TH>) _param_rc_payload_th,

(ParamInt<px4::params::RC_CHAN_CNT>) _param_rc_chan_cnt
)
Expand Down

0 comments on commit b02384e

Please sign in to comment.