Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/ArduSub/RC_Channel_Sub.cpp
9347 views
1
#include "Sub.h"
2
3
#include "RC_Channel_Sub.h"
4
#include "config.h"
5
6
// defining these two macros and including the RC_Channels_VarInfo
7
// header defines the parameter information common to all vehicle
8
// types
9
#define RC_CHANNELS_SUBCLASS RC_Channels_Sub
10
#define RC_CHANNEL_SUBCLASS RC_Channel_Sub
11
12
#include <RC_Channel/RC_Channels_VarInfo.h>
13
14
15
#if AP_SUB_RC_ENABLED
16
int8_t RC_Channels_Sub::flight_mode_channel_number() const
17
{
18
return sub.g.flight_mode_chan.get();
19
}
20
21
void RC_Channel_Sub::mode_switch_changed(modeswitch_pos_t new_pos)
22
{
23
if (new_pos < 0 || new_pos > 6) {
24
// should not have been called
25
return;
26
}
27
28
if (!sub.set_mode((Mode::Number)sub.flight_modes[new_pos].get(), ModeReason::RC_COMMAND)) {
29
return;
30
}
31
}
32
33
// init_aux_switch_function - initialize aux functions
34
void RC_Channel_Sub::init_aux_function(const AUX_FUNC ch_option, const AuxSwitchPos ch_flag)
35
{
36
RC_Channel::init_aux_function(ch_option, ch_flag);
37
}
38
39
bool RC_Channels_Sub::in_rc_failsafe() const
40
{
41
return sub.failsafe.radio;
42
}
43
44
bool RC_Channels_Sub::has_valid_input() const
45
{
46
if (in_rc_failsafe()) {
47
return false;
48
}
49
if (sub.failsafe.radio_counter != 0) {
50
return false;
51
}
52
return RC_Channels::has_valid_input();
53
}
54
55
56
// do_aux_function - implement the function invoked by auxiliary switches
57
bool RC_Channel_Sub::do_aux_function(const AuxFuncTrigger &trigger)
58
{
59
return RC_Channel::do_aux_function(trigger);
60
}
61
#else
62
// note that this callback is not presently used on Plane:
63
int8_t RC_Channels_Sub::flight_mode_channel_number() const
64
{
65
return 1; // sub does not have a flight mode channel
66
}
67
#endif
68
69
// returns true if min throttle arming checks should be run
70
bool RC_Channels_Sub::arming_check_throttle() const {
71
if (sub.g.thr_arming_position == WITHIN_THR_TRIM && RC_Channels::arming_check_throttle()) {
72
// center sprung/reversing throttle configured, dont run AP_Arming check for min position
73
// Sub already checks this case in its own arming checks
74
return false;
75
}
76
return RC_Channels::arming_check_throttle();
77
}
78
79