APM:Libraries
AP_BoardConfig.cpp
Go to the documentation of this file.
1 /*
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License as published by
4  the Free Software Foundation, either version 3 of the License, or
5  (at your option) any later version.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 /*
16  * AP_BoardConfig - board specific configuration
17  */
18 
19 #include <AP_HAL/AP_HAL.h>
20 #include <AP_Common/AP_Common.h>
21 #include <GCS_MAVLink/GCS.h>
22 #include "AP_BoardConfig.h"
23 #include <stdio.h>
24 
25 #if HAL_WITH_UAVCAN
26 #include <AP_UAVCAN/AP_UAVCAN.h>
27 #if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
28 #include <AP_HAL_Linux/CAN.h>
29 #endif
30 #endif
31 
32 #if CONFIG_HAL_BOARD == HAL_BOARD_PX4
33 # define BOARD_SAFETY_ENABLE_DEFAULT 1
34 #if defined(CONFIG_ARCH_BOARD_PX4FMU_V1)
35 #define BOARD_PWM_COUNT_DEFAULT 2
36 #define BOARD_SER1_RTSCTS_DEFAULT 0 // no flow control on UART5 on FMUv1
37 #elif defined(CONFIG_ARCH_BOARD_PX4FMU_V4)
38 #define BOARD_PWM_COUNT_DEFAULT 6
39 #define BOARD_SER1_RTSCTS_DEFAULT 2
40 #elif defined(CONFIG_ARCH_BOARD_AEROFC_V1)
41 #define BOARD_PWM_COUNT_DEFAULT 0
42 #define BOARD_SER1_RTSCTS_DEFAULT 0
43 # undef BOARD_SAFETY_ENABLE_DEFAULT
44 # define BOARD_SAFETY_ENABLE_DEFAULT 0
45 #else // V2
46 #define BOARD_PWM_COUNT_DEFAULT 4
47 #define BOARD_SER1_RTSCTS_DEFAULT 2
48 #endif
49 #define BOARD_TYPE_DEFAULT PX4_BOARD_AUTO
50 
51 #elif CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
52 # define BOARD_SAFETY_ENABLE_DEFAULT 0
53 # define BOARD_PWM_COUNT_DEFAULT 8
54 # if defined(CONFIG_ARCH_BOARD_VRBRAIN_V51)
55 # define BOARD_TYPE_DEFAULT VRX_BOARD_BRAIN51
56 # elif defined(CONFIG_ARCH_BOARD_VRBRAIN_V52)
57 # define BOARD_TYPE_DEFAULT VRX_BOARD_BRAIN52
58 # elif defined(CONFIG_ARCH_BOARD_VRBRAIN_V52E)
59 # define BOARD_TYPE_DEFAULT VRX_BOARD_BRAIN52E
60 # elif defined(CONFIG_ARCH_BOARD_VRUBRAIN_V51)
61 # define BOARD_TYPE_DEFAULT VRX_BOARD_UBRAIN51
62 # elif defined(CONFIG_ARCH_BOARD_VRUBRAIN_V52)
63 # define BOARD_TYPE_DEFAULT VRX_BOARD_UBRAIN52
64 # elif defined(CONFIG_ARCH_BOARD_VRCORE_V10)
65 # define BOARD_TYPE_DEFAULT VRX_BOARD_CORE10
66 # elif defined(CONFIG_ARCH_BOARD_VRBRAIN_V54)
67 # define BOARD_TYPE_DEFAULT VRX_BOARD_BRAIN54
68 # endif
69 
70 #elif CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
71 # define BOARD_SAFETY_ENABLE_DEFAULT 1
72 #ifndef BOARD_PWM_COUNT_DEFAULT
73 # define BOARD_PWM_COUNT_DEFAULT 6
74 #endif
75 #ifndef BOARD_SER1_RTSCTS_DEFAULT
76 # define BOARD_SER1_RTSCTS_DEFAULT 2
77 #endif
78 # define BOARD_TYPE_DEFAULT PX4_BOARD_AUTO
79 #endif
80 
81 #ifndef HAL_IMU_TEMP_DEFAULT
82 #define HAL_IMU_TEMP_DEFAULT -1 // disabled
83 #endif
84 
85 #if AP_FEATURE_SAFETY_BUTTON
86 #ifndef BOARD_SAFETY_OPTION_DEFAULT
87 #define BOARD_SAFETY_OPTION_DEFAULT (BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_OFF|BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_ON)
88 #endif
89 #endif
90 
91 #ifndef BOARD_PWM_COUNT_DEFAULT
92 #define BOARD_PWM_COUNT_DEFAULT 8
93 #endif
94 
95 extern const AP_HAL::HAL& hal;
97 
98 // table of user settable parameters
100  // @Param: PWM_COUNT
101  // @DisplayName: Auxiliary pin config
102  // @Description: Control assigning of FMU pins to PWM output, timer capture and GPIO. All unassigned pins can be used for GPIO
103  // @Values: 0:No PWMs,2:Two PWMs,4:Four PWMs,6:Six PWMs,7:Three PWMs and One Capture
104  // @RebootRequired: True
105  // @User: Advanced
106  AP_GROUPINFO("PWM_COUNT", 0, AP_BoardConfig, pwm_count, BOARD_PWM_COUNT_DEFAULT),
107 
108 #if AP_FEATURE_RTSCTS
109  // @Param: SER1_RTSCTS
110  // @DisplayName: Serial 1 flow control
111  // @Description: Enable flow control on serial 1 (telemetry 1) on Pixhawk. You must have the RTS and CTS pins connected to your radio. The standard DF13 6 pin connector for a 3DR radio does have those pins connected. If this is set to 2 then flow control will be auto-detected by checking for the output buffer filling on startup. Note that the PX4v1 does not have hardware flow control pins on this port, so you should leave this disabled.
112  // @Values: 0:Disabled,1:Enabled,2:Auto
113  // @RebootRequired: True
114  // @User: Advanced
115  AP_GROUPINFO("SER1_RTSCTS", 1, AP_BoardConfig, state.ser1_rtscts, BOARD_SER1_RTSCTS_DEFAULT),
116 
117  // @Param: SER2_RTSCTS
118  // @DisplayName: Serial 2 flow control
119  // @Description: Enable flow control on serial 2 (telemetry 2) on Pixhawk and STATE. You must have the RTS and CTS pins connected to your radio. The standard DF13 6 pin connector for a 3DR radio does have those pins connected. If this is set to 2 then flow control will be auto-detected by checking for the output buffer filling on startup.
120  // @Values: 0:Disabled,1:Enabled,2:Auto
121  // @RebootRequired: True
122  // @User: Advanced
123  AP_GROUPINFO("SER2_RTSCTS", 2, AP_BoardConfig, state.ser2_rtscts, 2),
124 #endif
125 
126 #if AP_FEATURE_SAFETY_BUTTON
127  // @Param: SAFETYENABLE
128  // @DisplayName: Enable use of safety arming switch
129  // @Description: This controls the default state of the safety switch at startup. When set to 1 the safety switch will start in the safe state (flashing) at boot. When set to zero the safety switch will start in the unsafe state (solid) at startup. Note that if a safety switch is fitted the user can still control the safety state after startup using the switch. The safety state can also be controlled in software using a MAVLink message.
130  // @Values: 0:Disabled,1:Enabled
131  // @RebootRequired: True
132  // @User: Standard
133  AP_GROUPINFO("SAFETYENABLE", 3, AP_BoardConfig, state.safety_enable, BOARD_SAFETY_ENABLE_DEFAULT),
134 #endif
135 
136 #if AP_FEATURE_SBUS_OUT
137  // @Param: SBUS_OUT
138  // @DisplayName: SBUS output rate
139  // @Description: This sets the SBUS output frame rate in Hz
140  // @Values: 0:Disabled,1:50Hz,2:75Hz,3:100Hz,4:150Hz,5:200Hz,6:250Hz,7:300Hz
141  // @RebootRequired: True
142  // @User: Advanced
143  AP_GROUPINFO("SBUS_OUT", 4, AP_BoardConfig, state.sbus_out_rate, 0),
144 #endif
145 
146  // @Param: SERIAL_NUM
147  // @DisplayName: User-defined serial number
148  // @Description: User-defined serial number of this vehicle, it can be any arbitrary number you want and has no effect on the autopilot
149  // @Range: -32768 32767
150  // @User: Standard
151  AP_GROUPINFO("SERIAL_NUM", 5, AP_BoardConfig, vehicleSerialNumber, 0),
152 
153 #if AP_FEATURE_SAFETY_BUTTON
154  // @Param: SAFETY_MASK
155  // @DisplayName: Channels to which ignore the safety switch state
156  // @Description: A bitmask which controls what channels can move while the safety switch has not been pressed
157  // @Values: 0:Disabled,1:Enabled
158  // @Bitmask: 0:Ch1,1:Ch2,2:Ch3,3:Ch4,4:Ch5,5:Ch6,6:Ch7,7:Ch8,8:Ch9,9:Ch10,10:Ch11,11:Ch12,12:Ch13,13:Ch14
159  // @RebootRequired: True
160  // @User: Advanced
161  AP_GROUPINFO("SAFETY_MASK", 7, AP_BoardConfig, state.ignore_safety_channels, 0),
162 #endif
163 
164 #if HAL_HAVE_IMU_HEATER
165  // @Param: IMU_TARGTEMP
166  // @DisplayName: Target IMU temperature
167  // @Description: This sets the target IMU temperature for boards with controllable IMU heating units. DO NOT SET -1 on The Cube. A value of -1 sets PH1 behaviour
168  // @Range: -1 80
169  // @Units: degC
170  // @User: Advanced
171  AP_GROUPINFO("IMU_TARGTEMP", 8, AP_BoardConfig, _imu_target_temperature, HAL_IMU_TEMP_DEFAULT),
172 #endif
173 
174 #if AP_FEATURE_BOARD_DETECT
175  // @Param: TYPE
176  // @DisplayName: Board type
177  // @Description: This allows selection of a PX4 or VRBRAIN board type. If set to zero then the board type is auto-detected (PX4)
178  // @Values: 0:AUTO,1:PX4V1,2:Pixhawk,3:Cube/Pixhawk2,4:Pixracer,5:PixhawkMini,6:Pixhawk2Slim,7:VRBrain 5.1,8:VRBrain 5.2,9:VR Micro Brain 5.1,10:VR Micro Brain 5.2,11:VRBrain Core 1.0,12:VRBrain 5.4,13:Intel Aero FC,20:AUAV2.1
179  // @RebootRequired: True
180  // @User: Advanced
181  AP_GROUPINFO("TYPE", 9, AP_BoardConfig, state.board_type, BOARD_TYPE_DEFAULT),
182 #endif
183 
184 #if AP_FEATURE_BOARD_DETECT
185 #if HAL_PX4_HAVE_PX4IO || HAL_WITH_IO_MCU
186  // @Param: IO_ENABLE
187  // @DisplayName: Enable IO co-processor
188  // @Description: This allows for the IO co-processor on FMUv1 and FMUv2 to be disabled
189  // @Values: 0:Disabled,1:Enabled
190  // @RebootRequired: True
191  // @User: Advanced
192  AP_GROUPINFO("IO_ENABLE", 10, AP_BoardConfig, state.io_enable, 1),
193 #endif
194 #endif
195 
196 #if HAL_RCINPUT_WITH_AP_RADIO
197  // @Group: RADIO
198  // @Path: ../AP_Radio/AP_Radio.cpp
199  AP_SUBGROUPINFO(_radio, "RADIO", 11, AP_BoardConfig, AP_Radio),
200 #endif
201 
202 #if defined(HAL_NEEDS_PARAM_HELPER)
203  // @Group: ""
204  // @Path: ../libraries/AP_Param_Helper/AP_Param_Helper.cpp
205  AP_SUBGROUPINFO(param_helper, "", 12, AP_BoardConfig, AP_Param_Helper),
206 #endif
207 
208 #if AP_FEATURE_SAFETY_BUTTON
209  // @Param: SAFETYOPTION
210  // @DisplayName: Options for safety button behavior
211  // @Description: This controls the activation of the safety button. It allows you to control if the safety button can be used for safety enable and/or disable, and whether the button is only active when disarmed
212  // @Bitmask: 0:ActiveForSafetyEnable,1:ActiveForSafetyDisable,2:ActiveWhenArmed
213  // @User: Standard
214  AP_GROUPINFO("SAFETYOPTION", 13, AP_BoardConfig, state.safety_option, BOARD_SAFETY_OPTION_DEFAULT),
215 #endif
216 
218 };
219 
221 {
222  board_setup();
223 
224 #if HAL_HAVE_IMU_HEATER
225  // let the HAL know the target temperature. We pass a pointer as
226  // we want the user to be able to change the parameter without
227  // rebooting
229 #endif
230 }
231 
232 // set default value for BRD_SAFETY_MASK
234 {
235 #if AP_FEATURE_SAFETY_BUTTON
236  state.ignore_safety_channels.set_default(mask);
237 #if CONFIG_HAL_BOARD == HAL_BOARD_PX4
239 #endif
240 #endif
241 }
242 
244 {
245 #if AP_FEATURE_SAFETY_BUTTON
247 #endif
248 }
249 
250 /*
251  notify user of a fatal startup error related to available sensors.
252 */
254 
255 void AP_BoardConfig::sensor_config_error(const char *reason)
256 {
258  /*
259  to give the user the opportunity to connect to USB we keep
260  repeating the error. The mavlink delay callback is initialised
261  before this, so the user can change parameters (and in
262  particular BRD_TYPE if needed)
263  */
264  while (true) {
265  printf("Sensor failure: %s\n", reason);
266  gcs().send_text(MAV_SEVERITY_ERROR, "Check BRD_TYPE: %s", reason);
267  hal.scheduler->delay(3000);
268  }
269 }
int printf(const char *fmt,...)
Definition: stdio.c:113
void board_init_safety(void)
Interface definition for the various Ground Control System.
AP_Int8 _imu_target_temperature
#define AP_GROUPINFO(name, idx, clazz, element, def)
Definition: AP_Param.h:102
const AP_HAL::HAL & hal
Definition: AC_PID_test.cpp:14
virtual void set_imu_target_temp(int8_t *target)
Definition: Util.h:91
AP_HAL::Util * util
Definition: HAL.h:115
void set_default_safety_ignore_mask(uint16_t mask)
GCS & gcs()
struct AP_BoardConfig::@14 state
#define HAL_IMU_TEMP_DEFAULT
void px4_setup_safety_mask(void)
Definition: px4_drivers.cpp:96
virtual void delay(uint16_t ms)=0
void board_setup(void)
static const struct AP_Param::GroupInfo var_info[]
#define BOARD_SAFETY_OPTION_DEFAULT
static int state
Definition: Util.cpp:20
#define BOARD_SER1_RTSCTS_DEFAULT
void send_text(MAV_SEVERITY severity, const char *fmt,...)
Definition: GCS.cpp:8
Common definitions and utility routines for the ArduPilot libraries.
#define BOARD_TYPE_DEFAULT
#define BOARD_SAFETY_ENABLE_DEFAULT
static bool _in_sensor_config_error
#define BOARD_PWM_COUNT_DEFAULT
static AP_BoardConfig * instance
#define AP_SUBGROUPINFO(element, name, idx, thisclazz, elclazz)
Definition: AP_Param.h:109
void init_safety(void)
#define AP_GROUPEND
Definition: AP_Param.h:121
AP_HAL::Scheduler * scheduler
Definition: HAL.h:114
static void sensor_config_error(const char *reason)