Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into cc3d
Browse files Browse the repository at this point in the history
  • Loading branch information
thenickdude committed Feb 27, 2015
2 parents 57fcde0 + ed434dd commit af68517
Show file tree
Hide file tree
Showing 20 changed files with 265 additions and 73 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ COMMON_SRC = build_config.c \
common/maths.c \
common/printf.c \
common/typeconversion.c \
common/encoding.c \
main.c \
mw.c \
flight/altitudehold.c \
Expand Down
2 changes: 1 addition & 1 deletion docs/Cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Re-apply any new defaults as desired.
| failsafe_min_usec | | 100 | 2000 | 985 | Profile | UINT16 |
| failsafe_max_usec | | 100 | 3000 | 2115 | Profile | UINT16 |
| gimbal_flags | When feature SERVO_TILT is enabled, this can be a combination of the following numbers: 1=normal gimbal (default), 2=tiltmix gimbal, 4=in PPM (or SERIALRX) input mode, this will forward AUX1..4 RC inputs to PWM5..8 pins | 0 | 255 | 1 | Profile | UINT8 |
| acc_hardware | This is used to suggest which accelerometer driver should load, or to force no accelerometer in case gyro-only flight is needed. Default (0) will attempt to auto-detect among enabled drivers. Otherwise, to force a particular device, set it to 1 for ADXL345, 2 for MPU6050 integrated accelerometer, 3 for MMA8452, 4 for BMA280, or 5 to disable accelerometer alltogether - resulting in gyro-only operation. | 0 | 9 | 0 | Master | UINT8 |
| acc_hardware | This is used to suggest which accelerometer driver should load, or to force no accelerometer in case gyro-only flight is needed. Default (0) will attempt to auto-detect among enabled drivers. Otherwise, to force a particular device, set it to 2 for ADXL345, 3 for MPU6050 integrated accelerometer, 4 for MMA8452, 5 for BMA280, 6 for LSM303DLHC, 7 for SPI_MPU6000, 8 for SPI_MPU6500 or 1 to disable accelerometer alltogether - resulting in gyro-only operation. | 0 | 9 | 0 | Master | UINT8 |
| acc_lpf_factor | | 0 | 250 | 4 | Profile | UINT8 |
| accxy_deadband | | 0 | 100 | 40 | Profile | UINT8 |
| accz_deadband | | 0 | 100 | 40 | Profile | UINT8 |
Expand Down
2 changes: 1 addition & 1 deletion docs/LedStrip.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ led 27 2,9:S:FWT:0
```
16-18 9-11
19-21 \ / 6-8
\ 13-16 /
\ 12-15 /
\ FRONT /
/ BACK \
/ \
Expand Down
9 changes: 2 additions & 7 deletions src/main/blackbox/blackbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "common/maths.h"
#include "common/axis.h"
#include "common/color.h"
#include "common/encoding.h"

#include "drivers/gpio.h"
#include "drivers/sensor.h"
Expand Down Expand Up @@ -878,11 +879,6 @@ static bool sendFieldDefinition(const char * const *headerNames, unsigned int he
*/
static bool blackboxWriteSysinfo()
{
union floatConvert_t {
float f;
uint32_t u;
} floatConvert;

if (xmitState.headerIndex == 0) {
xmitState.u.serialBudget = 0;
xmitState.headerIndex = 1;
Expand Down Expand Up @@ -937,8 +933,7 @@ static bool blackboxWriteSysinfo()
xmitState.u.serialBudget -= strlen("H maxthrottle:%d\n");
break;
case 8:
floatConvert.f = gyro.scale;
blackboxPrintf("H gyro.scale:0x%x\n", floatConvert.u);
blackboxPrintf("H gyro.scale:0x%x\n", castFloatBytesToInt(gyro.scale));

xmitState.u.serialBudget -= strlen("H gyro.scale:0x\n") + 6;
break;
Expand Down
15 changes: 2 additions & 13 deletions src/main/blackbox/blackbox_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

#include "blackbox_io.h"

#include "platform.h"
#include "version.h"
#include "build_config.h"

#include "common/maths.h"
#include "common/axis.h"
#include "common/color.h"
#include "common/encoding.h"

#include "drivers/gpio.h"
#include "drivers/sensor.h"
Expand Down Expand Up @@ -144,18 +145,6 @@ void blackboxWriteUnsignedVB(uint32_t value)
blackboxWrite(value);
}

/**
* ZigZag encoding maps all values of a signed integer into those of an unsigned integer in such
* a way that numbers of small absolute value correspond to small integers in the result.
*
* (Compared to just casting a signed to an unsigned which creates huge resulting numbers for
* small negative integers).
*/
static uint32_t zigzagEncode(int32_t value)
{
return (uint32_t)((value << 1) ^ (value >> 31));
}

/**
* Write a signed integer to the blackbox serial port using ZigZig and variable byte encoding.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/blackbox/blackbox_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <stdint.h>
#include <stdbool.h>

#include "target.h"
#include "platform.h"

typedef enum BlackboxDevice {
BLACKBOX_DEVICE_SERIAL = 0,
Expand Down
31 changes: 31 additions & 0 deletions src/main/common/encoding.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "encoding.h"

/**
* Cast the in-memory representation of the given float directly to an int.
*
* This is useful for printing the hex representation of a float number (which is considerably cheaper
* than a full decimal float formatter, in both code size and output length).
*/
uint32_t castFloatBytesToInt(float f)
{
union floatConvert_t {
float f;
uint32_t u;
} floatConvert;

floatConvert.f = f;

return floatConvert.u;
}

/**
* ZigZag encoding maps all values of a signed integer into those of an unsigned integer in such
* a way that numbers of small absolute value correspond to small integers in the result.
*
* (Compared to just casting a signed to an unsigned which creates huge resulting numbers for
* small negative integers).
*/
uint32_t zigzagEncode(int32_t value)
{
return (uint32_t)((value << 1) ^ (value >> 31));
}
23 changes: 23 additions & 0 deletions src/main/common/encoding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <stdint.h>

uint32_t castFloatBytesToInt(float f);
uint32_t zigzagEncode(int32_t value);
4 changes: 3 additions & 1 deletion src/main/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ profile_t *currentProfile;
static uint8_t currentControlRateProfileIndex = 0;
controlRateConfig_t *currentControlRateProfile;

static const uint8_t EEPROM_CONF_VERSION = 92;
static const uint8_t EEPROM_CONF_VERSION = 93;

static void resetAccelerometerTrims(flightDynamicsTrims_t *accelerometerTrims)
{
Expand Down Expand Up @@ -620,6 +620,8 @@ void activateConfig(void)

activateControlRateConfig();

resetAdjustmentStates();

useRcControlsConfig(
currentProfile->modeActivationConditions,
&masterConfig.escAndServoConfig,
Expand Down
60 changes: 39 additions & 21 deletions src/main/flight/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "common/axis.h"
#include "common/maths.h"

#include "drivers/system.h"
#include "drivers/gpio.h"
#include "drivers/timer.h"
#include "drivers/pwm_output.h"
Expand Down Expand Up @@ -487,6 +488,13 @@ void writeAllMotors(int16_t mc)
writeMotors();
}

void stopMotors(void)
{
writeAllMotors(escAndServoConfig->mincommand);

delay(50); // give the timers and ESCs a chance to react.
}

#ifndef USE_QUAD_MIXER_ONLY
static void airplaneMixer(void)
{
Expand Down Expand Up @@ -537,7 +545,6 @@ static void airplaneMixer(void)

void mixTable(void)
{
int16_t maxMotor;
uint32_t i;

if (motorCount > 3) {
Expand Down Expand Up @@ -655,29 +662,40 @@ void mixTable(void)
}
#endif

maxMotor = motor[0];
for (i = 1; i < motorCount; i++)
if (motor[i] > maxMotor)
maxMotor = motor[i];
for (i = 0; i < motorCount; i++) {
if (maxMotor > escAndServoConfig->maxthrottle) // this is a way to still have good gyro corrections if at least one motor reaches its max.
motor[i] -= maxMotor - escAndServoConfig->maxthrottle;
if (feature(FEATURE_3D)) {
if ((rcData[THROTTLE]) > rxConfig->midrc) {
motor[i] = constrain(motor[i], flight3DConfig->deadband3d_high, escAndServoConfig->maxthrottle);
} else {
motor[i] = constrain(motor[i], escAndServoConfig->mincommand, flight3DConfig->deadband3d_low);
if (ARMING_FLAG(ARMED)) {

int16_t maxMotor = motor[0];
for (i = 1; i < motorCount; i++) {
if (motor[i] > maxMotor) {
maxMotor = motor[i];
}
} else {
motor[i] = constrain(motor[i], escAndServoConfig->minthrottle, escAndServoConfig->maxthrottle);
if ((rcData[THROTTLE]) < rxConfig->mincheck) {
if (!feature(FEATURE_MOTOR_STOP))
motor[i] = escAndServoConfig->minthrottle;
else
motor[i] = escAndServoConfig->mincommand;
}

for (i = 0; i < motorCount; i++) {
if (maxMotor > escAndServoConfig->maxthrottle) {
// this is a way to still have good gyro corrections if at least one motor reaches its max.
motor[i] -= maxMotor - escAndServoConfig->maxthrottle;
}

if (feature(FEATURE_3D)) {
if ((rcData[THROTTLE]) > rxConfig->midrc) {
motor[i] = constrain(motor[i], flight3DConfig->deadband3d_high, escAndServoConfig->maxthrottle);
} else {
motor[i] = constrain(motor[i], escAndServoConfig->mincommand, flight3DConfig->deadband3d_low);
}
} else {
motor[i] = constrain(motor[i], escAndServoConfig->minthrottle, escAndServoConfig->maxthrottle);
if ((rcData[THROTTLE]) < rxConfig->mincheck) {
if (!feature(FEATURE_MOTOR_STOP))
motor[i] = escAndServoConfig->minthrottle;
else
motor[i] = escAndServoConfig->mincommand;
}
}
}
if (!ARMING_FLAG(ARMED)) {

} else {
for (i = 0; i < motorCount; i++) {
motor[i] = motor_disarmed[i];
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/flight/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ void mixerLoadMix(int index, motorMixer_t *customMixers);
void mixerResetMotors(void);
void mixTable(void);
void writeMotors(void);
void stopMotors(void);
6 changes: 6 additions & 0 deletions src/main/io/rc_controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,9 @@ void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions, es
}
}
}

void resetAdjustmentStates(void)
{
memset(adjustmentStates, 0, sizeof(adjustmentStates));
}

1 change: 1 addition & 0 deletions src/main/io/rc_controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ typedef struct adjustmentState_s {

#define MAX_ADJUSTMENT_RANGE_COUNT 12 // enough for 2 * 6pos switches.

void resetAdjustmentStates(void);
void configureAdjustment(uint8_t index, uint8_t auxChannelIndex, const adjustmentConfig_t *adjustmentConfig);
void updateAdjustmentStates(adjustmentRange_t *adjustmentRanges);
void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rxConfig);
Expand Down
5 changes: 2 additions & 3 deletions src/main/io/serial_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,11 @@ static const char * const sensorTypeNames[] = {
"GYRO", "ACC", "BARO", "MAG", "SONAR", "GPS", "GPS+MAG", NULL
};

// FIXME the next time the EEPROM is bumped change the order of acc and gyro names so that "None" is second.

#define SENSOR_NAMES_MASK (SENSOR_GYRO | SENSOR_ACC | SENSOR_BARO | SENSOR_MAG)

static const char * const sensorHardwareNames[4][11] = {
{ "", "None", "MPU6050", "L3G4200D", "MPU3050", "L3GD20", "MPU6000", "MPU6500", "FAKE", NULL },
{ "", "ADXL345", "MPU6050", "MMA845x", "BMA280", "LSM303DLHC", "MPU6000", "MPU6500", "FAKE", "None", NULL },
{ "", "None", "ADXL345", "MPU6050", "MMA845x", "BMA280", "LSM303DLHC", "MPU6000", "MPU6500", "FAKE", NULL },
{ "", "None", "BMP085", "MS5611", NULL },
{ "", "None", "HMC5883", "AK8975", NULL }
};
Expand Down Expand Up @@ -1344,6 +1342,7 @@ static void cliRateProfile(char *cmdline)
static void cliReboot(void) {
cliPrint("\r\nRebooting");
waitForSerialPortToFinishTransmitting(cliPort);
stopMotors();
systemReset();
}

Expand Down
1 change: 1 addition & 0 deletions src/main/io/serial_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,7 @@ void mspProcess(void)
while (!isSerialTransmitBufferEmpty(candidatePort->port)) {
delay(50);
}
stopMotors();
systemReset();
}
}
Expand Down
Loading

0 comments on commit af68517

Please sign in to comment.