APM:Copter
toy_mode.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*
4  class to support "toy" mode for simplified user interaction for
5  large volume consumer vehicles
6  */
7 
8 class ToyMode
9 {
10 public:
11  friend class Copter;
12 
13  ToyMode();
14  bool enabled(void) const {
15  return enable.get() != 0;
16  }
17 
18  void update(void);
19 
20  // get throttle mid-point
21  int16_t get_throttle_mid(void) {
22  return throttle_mid;
23  }
24 
25  // adjust throttle for throttle takeoff
26  void throttle_adjust(float &throttle_control);
27 
28  // handle mavlink message
29  void handle_message(mavlink_message_t *msg);
30 
31  void load_test_run(void);
32 
33  static const struct AP_Param::GroupInfo var_info[];
34 
35 private:
36 
37  void trim_update(void);
38  void action_arm(void);
39  void blink_update(void);
40  void send_named_int(const char *name, int32_t value);
42 
43  void thrust_limiting(float *thrust, uint8_t num_motors);
44  void arm_check_compass(void);
45 
46  // work out type of button setup
47  bool is_v2450_buttons(void) const {
48  return enable == 1;
49  }
50  bool is_f412_buttons(void) const {
51  return enable == 2;
52  }
53 
54  enum toy_action {
80  };
81 
83 
84  // these are bitmask indexes for TMODE_FLAGS
85  enum toy_flags {
86  FLAG_THR_DISARM = 1<<0, // disarm on low throttle
87  FLAG_THR_ARM = 1<<1, // arm on high throttle
88  FLAG_UPGRADE_LOITER = 1<<2, // auto upgrade from ALT_HOLD to LOITER
89  FLAG_RTL_CANCEL = 1<<3, // cancel RTL on large stick input
90  };
91 
93  BLINK_FULL = 0xFFFF,
94  BLINK_OFF = 0x0000,
95  BLINK_1 = 0xBFFF,
96  BLINK_2 = 0xAFFF,
97  BLINK_3 = 0xABFF,
98  BLINK_4 = 0xAAFF,
99  BLINK_6 = 0xAAAF,
100  BLINK_8 = 0xAAAA,
101  BLINK_NO_RX = 0x1111,
102  BLINK_SLOW_1 = 0xF0FF,
103  BLINK_VSLOW = 0xF000,
104  BLINK_MED_1 = 0xF0F0,
105  };
106 
108  AP_Int8 enable;
109  AP_Int8 primary_mode[2];
110  AP_Int8 actions[9];
111  AP_Int8 trim_auto;
112  AP_Int16 flags;
113 
114  struct {
115  uint32_t start_ms;
116  uint16_t chan[4];
117  } trim;
118 
119  uint32_t power_counter;
122  uint16_t last_ch5;
128  int16_t throttle_mid = 500;
129  uint32_t throttle_arm_ms;
131  uint32_t last_action_ms;
133 
134  // time when we were last told we are recording video
135  uint32_t last_video_ms;
136 
137  // current blink indexes
142  uint16_t red_blink_count;
144  uint8_t blink_disarm;
145 
146  struct {
147  AP_Float volt_min;
148  AP_Float volt_max;
149  AP_Float thrust_min;
150  AP_Float thrust_max;
151  } filter;
152 
153  // low-pass voltage
154  float filtered_voltage = 4.0;
155 
157 
158  // remember the last mode we set
160 
161  struct load_data {
162  uint16_t m[4];
163  };
164 
165  enum load_type {
169  };
170 
171  struct {
172  bool running;
173  uint32_t row;
174  uint8_t filter_counter;
175  AP_Float load_mul;
176  AP_Int8 load_filter;
177  AP_Int8 load_type;
178  } load_test;
179 
180  static const struct load_data load_data1[];
181 };
AP_Float thrust_max
Definition: toy_mode.h:150
int32_t right_press_counter
Definition: toy_mode.h:126
AP_Int8 load_type
Definition: toy_mode.h:177
uint32_t row
Definition: toy_mode.h:173
control_mode_t
Definition: defines.h:91
void trim_update(void)
float filtered_voltage
Definition: toy_mode.h:154
int32_t left_press_counter
Definition: toy_mode.h:125
uint32_t last_video_ms
Definition: toy_mode.h:135
uint32_t throttle_low_counter
Definition: toy_mode.h:120
void thrust_limiting(float *thrust, uint8_t num_motors)
uint32_t throttle_high_counter
Definition: toy_mode.h:121
Definition: Copter.h:180
AP_Int8 enable
Definition: toy_mode.h:108
uint16_t green_blink_pattern
Definition: toy_mode.h:139
bool enabled(void) const
Definition: toy_mode.h:14
void handle_message(mavlink_message_t *msg)
int16_t throttle_mid
Definition: toy_mode.h:128
mode_reason_t
Definition: defines.h:115
void blink_update(void)
uint32_t throttle_arm_ms
Definition: toy_mode.h:129
toy_flags
Definition: toy_mode.h:85
void arm_check_compass(void)
int16_t get_throttle_mid(void)
Definition: toy_mode.h:21
AP_Int16 flags
Definition: toy_mode.h:112
control_mode_t last_set_mode
Definition: toy_mode.h:159
struct ToyMode::@19 filter
uint32_t reset_turtle_start_ms
Definition: toy_mode.h:132
uint8_t filter_counter
Definition: toy_mode.h:174
void send_named_int(const char *name, int32_t value)
bool done_first_update
Definition: toy_mode.h:107
uint32_t last_action_ms
Definition: toy_mode.h:131
AP_Float volt_min
Definition: toy_mode.h:147
uint16_t green_blink_count
Definition: toy_mode.h:143
void update(void)
bool ignore_left_change
Definition: toy_mode.h:127
uint8_t green_blink_index
Definition: toy_mode.h:141
static const struct AP_Param::GroupInfo var_info[]
Definition: toy_mode.h:33
uint8_t blink_disarm
Definition: toy_mode.h:144
const char * name
Definition: defines.h:97
toy_action
Definition: toy_mode.h:54
uint8_t motor_log_counter
Definition: toy_mode.h:156
AP_Int8 actions[9]
Definition: toy_mode.h:110
struct ToyMode::@20 load_test
bool last_left_button
Definition: toy_mode.h:123
AP_Float volt_max
Definition: toy_mode.h:148
AP_Int8 load_filter
Definition: toy_mode.h:176
bool is_v2450_buttons(void) const
Definition: toy_mode.h:47
void throttle_adjust(float &throttle_control)
AP_Int8 trim_auto
Definition: toy_mode.h:111
uint8_t red_blink_index
Definition: toy_mode.h:140
uint32_t power_counter
Definition: toy_mode.h:119
void load_test_run(void)
AP_Int8 primary_mode[2]
Definition: toy_mode.h:109
void action_arm(void)
bool upgrade_to_loiter
Definition: toy_mode.h:130
uint16_t last_ch5
Definition: toy_mode.h:122
uint32_t start_ms
Definition: toy_mode.h:115
static const struct load_data load_data1[]
Definition: toy_mode.h:180
blink_patterns
Definition: toy_mode.h:92
bool running
Definition: toy_mode.h:172
uint16_t chan[4]
Definition: toy_mode.h:116
AP_Float thrust_min
Definition: toy_mode.h:149
uint8_t last_mode_choice
Definition: toy_mode.h:124
AP_Float load_mul
Definition: toy_mode.h:175
bool is_f412_buttons(void) const
Definition: toy_mode.h:50
enum toy_action last_action
Definition: toy_mode.h:82
uint16_t red_blink_count
Definition: toy_mode.h:142
struct ToyMode::@18 trim
bool set_and_remember_mode(control_mode_t mode, mode_reason_t reason)
uint16_t red_blink_pattern
Definition: toy_mode.h:138