49 #include "flightstatus.h"
50 #include "manualcontrolcommand.h"
51 #include "manualcontrolsettings.h"
52 #include "systemalarms.h"
55 #if defined(PIOS_MANUAL_STACK_SIZE)
56 #define STACK_SIZE_BYTES PIOS_MANUAL_STACK_SIZE
58 #define STACK_SIZE_BYTES 1200
61 #define TASK_PRIORITY PIOS_THREAD_PRIO_HIGHEST
62 #define UPDATE_PERIOD_MS 20
115 FlightStatusData flightStatus;
116 FlightStatusGet(&flightStatus);
117 flightStatus.Armed = FLIGHTSTATUS_ARMED_DISARMED;
118 FlightStatusSet(&flightStatus);
123 uint32_t arm_time = 1000;
131 } arm_state = ARM_STATE_SAFETY;
133 uint32_t arm_state_time = 0;
145 static FlightStatusControlSourceOptions last_control_selection = -1;
148 FlightStatusControlSourceOptions control_selection =
150 bool reset_controller = control_selection != last_control_selection;
159 switch(control_selection) {
160 case FLIGHTSTATUS_CONTROLSOURCE_TRANSMITTER:
163 case FLIGHTSTATUS_CONTROLSOURCE_TABLET:
166 case FLIGHTSTATUS_CONTROLSOURCE_GEOFENCE:
176 FLIGHTSTATUS_CONTROLSOURCE_FAILSAFE);
177 control_selection = FLIGHTSTATUS_CONTROLSOURCE_FAILSAFE;
180 if (control_selection != last_control_selection) {
181 FlightStatusControlSourceSet(&control_selection);
182 last_control_selection = control_selection;
187 #define GO_STATE(x) \
190 arm_state_time = (now); \
205 if (!
ok_to_arm() && (arm_state != ARM_STATE_ARMED)) {
210 case ARM_STATE_SAFETY:
225 case ARM_STATE_DISARMED:
240 ManualControlSettingsArmTimeOptions arm_enum;
241 ManualControlSettingsArmTimeGet(&arm_enum);
243 arm_time = (arm_enum == MANUALCONTROLSETTINGS_ARMTIME_250) ? 250 :
244 (arm_enum == MANUALCONTROLSETTINGS_ARMTIME_500) ? 500 :
245 (arm_enum == MANUALCONTROLSETTINGS_ARMTIME_1000) ? 1000 :
246 (arm_enum == MANUALCONTROLSETTINGS_ARMTIME_2000) ? 2000 : 1000;
249 case ARM_STATE_ARMING:
271 case ARM_STATE_HOLDING:
291 case ARM_STATE_ARMED:
303 FlightStatusArmedOptions armed, prev_armed;
305 FlightStatusArmedGet(&prev_armed);
309 case ARM_STATE_SAFETY:
310 case ARM_STATE_DISARMED:
311 armed = FLIGHTSTATUS_ARMED_DISARMED;
314 case ARM_STATE_ARMING:
315 armed = FLIGHTSTATUS_ARMED_ARMING;
317 case ARM_STATE_HOLDING:
326 case ARM_STATE_ARMED:
327 armed = FLIGHTSTATUS_ARMED_ARMED;
332 if (armed != prev_armed) {
333 FlightStatusArmedSet(&armed);
360 return FLIGHTSTATUS_CONTROLSOURCE_GEOFENCE;
363 ManualControlCommandData
cmd;
364 ManualControlCommandGet(&cmd);
365 if (cmd.Connected != MANUALCONTROLCOMMAND_CONNECTED_TRUE) {
366 return FLIGHTSTATUS_CONTROLSOURCE_FAILSAFE;
368 MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_TABLETCONTROL) {
369 return FLIGHTSTATUS_CONTROLSOURCE_TABLET;
371 return FLIGHTSTATUS_CONTROLSOURCE_TRANSMITTER;
382 SystemAlarmsData alarms;
383 SystemAlarmsGet(&alarms);
386 for (
int i = 0;
i < SYSTEMALARMS_ALARM_NUMELEM;
i++)
388 if (alarms.Alarm[
i] >= SYSTEMALARMS_ALARM_ERROR &&
389 i != SYSTEMALARMS_ALARM_GPS &&
390 i != SYSTEMALARMS_ALARM_TELEMETRY)
397 FlightStatusFlightModeGet(&flight_mode);
399 if (flight_mode == FLIGHTSTATUS_FLIGHTMODE_FAILSAFE) {
Use tablet for control source.
static void manualControlTask(void *parameters)
uint32_t PIOS_Thread_Systime(void)
Disconnected timeout has occurred.
User requested disarm, or low throt timeout.
int32_t ManualControlStart()
Process transmitter inputs and use as control source.
static struct pios_thread * taskHandle
int32_t failsafe_control_select(bool reset_controller)
Use failsafe mode.
bool PIOS_WDG_RegisterFlag(uint16_t flag_requested)
Register a module against the watchdog.
bool ok_to_arm(void)
Determine if the aircraft is safe to arm based on alarms.
bool PIOS_WDG_UpdateFlag(uint16_t flag)
Function called by modules to indicate they are still running.
int32_t tablet_control_update()
Process updates for the tablet controller.
int32_t transmitter_control_select(bool reset_controller)
Select and use transmitter control.
Geofence controller that is enabled when out of zone.
int32_t failsafe_control_update()
Perform any updates to the failsafe controller.
enum control_status transmitter_control_get_status()
Get any control events.
int32_t geofence_control_update()
Perform any updates to the geofence controller.
int32_t geofence_control_select(bool reset_controller)
Use geofence control mode.
int32_t ManualControlInitialize()
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
int32_t TaskMonitorAdd(TaskInfoRunningElem task, struct pios_thread *threadp)
Something is fundamentally wrong.
Failsafe controller when transmitter control is lost.
RCVR layer functions header.
bool PIOS_Thread_Period_Elapsed(const uint32_t prev_systime, const uint32_t increment_ms)
Determine if a period has elapsed since a datum.
bool geofence_control_activate()
Query if out of bounds and the geofence controller should take over.
int32_t tablet_control_initialize()
Initialize the tablet controller.
User requested arm, controls in valid pos.
bool PIOS_RCVR_WaitActivity(uint32_t timeout_ms)
Includes PiOS and core architecture components.
int32_t transmitter_control_update()
Process inputs and arming.
static FlightStatusControlSourceOptions control_source_select()
control_source_select Determine which sub-module to use for the main control source of the flight con...
int32_t failsafe_control_initialize()
Initialize the failsafe controller.
User requested arm, controls in invalid pos.
int32_t transmitter_control_initialize()
Initialize the transmitter control mode.
Arming switch is in a state that doesn't.
For corners. Request we be the "opposite" mode.
static ManualControlCommandData cmd
uint8_t transmitter_control_get_flight_mode()
Query what the flight mode would be if this is selected.
int32_t tablet_control_select(bool reset_controller)
Use the values for the tablet controller.
MODULE_HIPRI_INITCALL(ManualControlInitialize, ManualControlStart)
int32_t geofence_control_initialize()
Initialize the geofence controller.