From b0eab0cc9e44251a89da4a52db580dcacf922dd2 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Sun, 12 Oct 2014 19:32:55 +0100 Subject: [PATCH] Update the cli AUX command to take range parameters - see docs/Modes.md --- docs/Modes.md | 70 +++++++++++++++++++++++++++++++++++++++ src/main/io/rc_controls.h | 3 ++ src/main/io/serial_cli.c | 48 ++++++++++++++++++++++++--- 3 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 docs/Modes.md diff --git a/docs/Modes.md b/docs/Modes.md new file mode 100644 index 000000000..52fcf6ae2 --- /dev/null +++ b/docs/Modes.md @@ -0,0 +1,70 @@ +# Modes + +Cleanflight has various modes that can be toggled on or off. Modes can be enabled/disabled by stick positions, +auxillary receiver channels and other events such as failsafe detection. + +| Id | Short Name | Function | +| 0 | ARM | Enables motors and flight stabilisation | +| 1 | ANGLE | Legacy auto-level flight mode | +| 2 | HORIZON | Auto-level flight mode | +| 3 | BARO | Altitude hold mode (Requires barometer sensor) | +| 4 | MAG | Heading lock | +| 5 | HEADFREE | Head Free - When enabled rotation has no effect on pitch/roll inputs | +| 6 | HEADADJ | Heading Adjust - Sets a new yaw origin for HEADFREE mode | +| 7 | CAMSTAB | Camera Stabilisation | +| 8 | CAMTRIG | | +| 9 | GPSHOME | Autonomous flight to HOME position | +| 10 | GPSHOLD | Maintain the same longitude/lattitude | +| 11 | PASSTHRU | +| 12 | BEEPERON | Enable beeping - useful for locating a crashed aircraft | +| 13 | LEDMAX | | +| 14 | LEDLOW | | +| 15 | LLIGHTS | | +| 16 | CALIB | | +| 17 | GOV | | +| 18 | OSD | Enable/Disable On-Screen-Display (OSD) | +| 19 | TELEMETRY | Enable telemetry via switch | +| 20 | AUTOTUNE | Autotune Pitch/Roll PIDs | +| 21 | SONAR | Altitude hold mode (sonar sensor only)| + +## Mode details + +### Headfree + +In this mode, the "head" of the multicopter is always pointing to the same direction as when the feature was activated. This means that when the multicopter rotates around the Z axis (yaw), the controls will always respond according the same "head" direction. + +With this mode is easier to control the multicopter, even fly it with the physical head towards you since the controls always respond the same. This is a friendly mode to new users of multicopters and can prevent losing the control when you don't know the head direction. + +## Auxillary Configuration + +Spare auxillary receiver channels can be used to enable/disable modes. Some modes can only be enabled this way. + +Configure your transmitter so that switches or dial (pots) send channel data on channels 5 upwards. +e.g. You can configure a 3 position switch to send 1000 when the switch is low, 1500 when the switch is in the middle and 2000 when the switch is high. + +Configure your tx/rx channel limits to use values between 1000 and 2000. + +When a channel is within a specifed range the corresponding mode is enabled. + +Use the GUI configuration tool to allow easy configuration when channel. + +### CLI + +There is a CLI command, `aux` that allows auxillary configuration. It takes 5 arguments as follows: + +* AUD range slot number (0 - 39) +* mode id (see mode list above) +* AUX channel index (AUX1 = 0, AUX2 = 1,... etc) +* low position, from 900 to 2100. Should be a multiple of 25. +* high position, from 900 to 2100. Should be a multiple of 25. + +If the low and high position are the same then the values are ignored. + +e.g. + +Configure AUX range slot 0 to enable ARM when AUX1 is withing 1700 and 2100. + +```aux 0 0 0 1700 2100``` + +You can display the aux configuration by using the `aux` command with no arguments. + diff --git a/src/main/io/rc_controls.h b/src/main/io/rc_controls.h index 12959982f..458b1d573 100644 --- a/src/main/io/rc_controls.h +++ b/src/main/io/rc_controls.h @@ -95,6 +95,9 @@ typedef enum { #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + 25 * step) #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25) +#define MIN_MODE_RANGE_STEP 0 +#define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25) + typedef struct modeActivationCondition_s { boxId_e modeId; uint8_t auxChannelIndex; diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index d1f1946db..7ff3b31b2 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -29,6 +29,7 @@ #include "build_config.h" #include "common/axis.h" +#include "common/maths.h" #include "common/color.h" #include "common/typeconversion.h" @@ -396,7 +397,7 @@ static int cliCompare(const void *a, const void *b) static void cliAux(char *cmdline) { - int i = 0; + int i, val = 0; uint8_t len; char *ptr; @@ -405,7 +406,7 @@ static void cliAux(char *cmdline) // print out aux channel settings for (i = 0; i < MAX_MODE_ACTIVATION_CONDITION_COUNT; i++) { modeActivationCondition_t *mac = ¤tProfile->modeActivationConditions[i]; - printf("aux %u %u\r\n", + printf("aux %u %u %u %u %u\r\n", i, mac->modeId, mac->auxChannelIndex, @@ -415,10 +416,47 @@ static void cliAux(char *cmdline) } } else { ptr = cmdline; - i = atoi(ptr); + i = atoi(ptr++); if (i < MAX_MODE_ACTIVATION_CONDITION_COUNT) { - ptr = strchr(cmdline, ' '); - // FIXME implement setting currentProfile->modeActivationConditions based on remaining string + modeActivationCondition_t *mac = ¤tProfile->modeActivationConditions[i]; + uint8_t validArgumentCount = 0; + ptr = strchr(ptr, ' '); + if (ptr) { + val = atoi(++ptr); + if (val >= 0 && val < CHECKBOX_ITEM_COUNT) { + mac->modeId = val; + validArgumentCount++; + } + } + ptr = strchr(ptr, ' '); + if (ptr) { + val = atoi(++ptr); + if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) { + mac->auxChannelIndex = val; + validArgumentCount++; + } + } + ptr = strchr(ptr, ' '); + if (ptr) { + val = atoi(++ptr); + val = CHANNEL_VALUE_TO_STEP(val); + if (val >= MIN_MODE_RANGE_STEP && val < MAX_MODE_RANGE_STEP) { + mac->rangeStartStep = val; + validArgumentCount++; + } + } + ptr = strchr(ptr, ' '); + if (ptr) { + val = atoi(++ptr); + val = CHANNEL_VALUE_TO_STEP(val); + if (val >= MIN_MODE_RANGE_STEP && val < MAX_MODE_RANGE_STEP) { + mac->rangeEndStep = val; + validArgumentCount++; + } + } + if (validArgumentCount != 4) { + memset(mac, 0, sizeof(modeActivationCondition_t)); + } } else { printf("index: must be < %u\r\n", MAX_MODE_ACTIVATION_CONDITION_COUNT); }