Skip to content

Commit

Permalink
Merge pull request #114 from blckmn/bf_merge_160315
Browse files Browse the repository at this point in the history
Betaflight changes to 160315
  • Loading branch information
blckmn committed Mar 17, 2016
2 parents 7ec7225 + 1afa103 commit 7250d5f
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*.dep
*.bak
*.uvgui.*
*.swp
*.save
.project
.settings
.cproject
Expand Down
11 changes: 10 additions & 1 deletion src/main/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@
#include "config/config_master.h"

#define BRUSHED_MOTORS_PWM_RATE 16000
#ifdef STM32F4
#define BRUSHLESS_MOTORS_PWM_RATE 2600
#else
#define BRUSHLESS_MOTORS_PWM_RATE 400
#endif // STM32F4


void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions, escAndServoConfig_t *escAndServoConfigToUse, pidProfile_t *pidProfileToUse);

Expand Down Expand Up @@ -200,7 +205,7 @@ void resetPidProfile(pidProfile_t *pidProfile)
pidProfile->dterm_lpf_hz = 0; // filtering ON by default
pidProfile->deltaMethod = DELTA_FROM_MEASUREMENT;

#if defined(STM32F411xE) || defined(STM32F40_41xxx)
#if defined(STM32F4)
pidProfile->dterm_lpf_hz = 60; // filtering ON by default
pidProfile->P_f[ROLL] = 5.012f; // new PID for raceflight. test carefully
pidProfile->I_f[ROLL] = 1.021f;
Expand Down Expand Up @@ -451,6 +456,10 @@ static void resetConf(void)
featureSet(FEATURE_FAILSAFE);
featureSet(FEATURE_ONESHOT125);
featureSet(FEATURE_SBUS_INVERTER);

#ifdef STM32F4
featureSet(FEATURE_USE_PWM_RATE);
#endif

// global settings
masterConfig.current_profile_index = 0; // default profile
Expand Down
1 change: 0 additions & 1 deletion src/main/drivers/light_ws2811strip_stm32f30x.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#define WS2811_IRQ DMA1_Channel3_IRQn
#define WS2811_DMA_TC_FLAG DMA1_FLAG_TC3
#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH3_HANDLER

#endif

void ws2811DMAHandler(DMA_Channel_TypeDef *channel) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/drivers/pwm_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#define MAX_INPUTS 8

#define PWM_TIMER_MHZ 1
#define ONESHOT_TIMER_MHZ 24
//these three have to be the same because of the ppmAvoidPWMTimerClash functions
#define ONESHOT_TIMER_MHZ 12
#define MULTISHOT_TIMER_MHZ 12
#define PWM_BRUSHED_TIMER_MHZ 12

Expand Down
8 changes: 3 additions & 5 deletions src/main/drivers/pwm_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "flight/failsafe.h" // FIXME dependency into the main code from a driver

#include "pwm_mapping.h"

#include "pwm_output.h"

typedef void (*pwmWriteFuncPtr)(uint8_t index, uint16_t value); // function pointer used to write motors
Expand Down Expand Up @@ -99,7 +98,6 @@ static pwmOutputPort_t *pwmOutConfig(const timerHardware_t *timerHardware, uint8
configTimeBase(timerHardware->tim, period, mhz);
pwmGPIOConfig(timerHardware->gpio, timerHardware->pin, Mode_AF_PP);


pwmOCConfig(timerHardware->tim, timerHardware->channel, value);
if (timerHardware->outputEnable)
TIM_CtrlPWMOutputs(timerHardware->tim, ENABLE);
Expand Down Expand Up @@ -134,6 +132,7 @@ static void pwmWriteStandard(uint8_t index, uint16_t value)
{
*motors[index]->ccr = value;
}

#if defined(STM32F10X) && !defined(CC3D)
static void pwmWriteOneshot125(uint8_t index, uint16_t value)
{
Expand All @@ -147,7 +146,7 @@ static void pwmWriteOneshot42(uint8_t index, uint16_t value)
#else
static void pwmWriteOneshot125(uint8_t index, uint16_t value)
{
*motors[index]->ccr = value * 3; // 24Mhz -> 8Mhz
*motors[index]->ccr = value * 3;
}

static void pwmWriteOneshot42(uint8_t index, uint16_t value)
Expand All @@ -158,7 +157,7 @@ static void pwmWriteOneshot42(uint8_t index, uint16_t value)

static void pwmWriteMultiShot(uint8_t index, uint16_t value)
{
*motors[index]->ccr = (uint16_t)((float)(value-1000) / 4.1666f)+ 60;
*motors[index]->ccr = (uint16_t)((float)(value-1000) / 4.1666f) + 60;
}

void pwmWriteMotor(uint8_t index, uint16_t value)
Expand Down Expand Up @@ -235,7 +234,6 @@ void pwmOneshotMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIn
} else {
motors[motorIndex]->pwmWritePtr = pwmWriteOneshot125;
}

}

void pwmMultiShotPwmRateMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, uint16_t idlePulse)
Expand Down
7 changes: 7 additions & 0 deletions src/main/drivers/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

#pragma once

#include <stdbool.h>
#include <stdint.h>

#include "platform.h"
#include "gpio.h"
#include "system.h"

#if !defined(USABLE_TIMER_CHANNEL_COUNT)
#define USABLE_TIMER_CHANNEL_COUNT 14
#endif
Expand Down
10 changes: 5 additions & 5 deletions src/main/flight/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,18 +828,18 @@ void mixTable(void)
int16_t throttleMin, throttleMax;
static int16_t throttlePrevious = 0; // Store the last throttle direction for deadband transitions

// Find min and max throttle based on condition. Use rcData for 3D to prevent loss of power due to min_check
// Find min and max throttle based on condition.
if (feature(FEATURE_3D)) {
if (!ARMING_FLAG(ARMED)) throttlePrevious = rxConfig->midrc; // When disarmed set to mid_rc. It always results in positive direction after arming.

if ((rcData[THROTTLE] <= (rxConfig->midrc - flight3DConfig->deadband3d_throttle))) { // Out of band handling
if ((rcCommand[THROTTLE] <= (rxConfig->midrc - flight3DConfig->deadband3d_throttle))) { // Out of band handling
throttleMax = flight3DConfig->deadband3d_low;
throttleMin = escAndServoConfig->minthrottle;
throttlePrevious = throttle = rcData[THROTTLE];
} else if (rcData[THROTTLE] >= (rxConfig->midrc + flight3DConfig->deadband3d_throttle)) { // Positive handling
throttlePrevious = throttle = rcCommand[THROTTLE];
} else if (rcCommand[THROTTLE] >= (rxConfig->midrc + flight3DConfig->deadband3d_throttle)) { // Positive handling
throttleMax = escAndServoConfig->maxthrottle;
throttleMin = flight3DConfig->deadband3d_high;
throttlePrevious = throttle = rcData[THROTTLE];
throttlePrevious = throttle = rcCommand[THROTTLE];
} else if ((throttlePrevious <= (rxConfig->midrc - flight3DConfig->deadband3d_throttle))) { // Deadband handling from negative to positive
throttle = throttleMax = flight3DConfig->deadband3d_low;
throttleMin = escAndServoConfig->minthrottle;
Expand Down
3 changes: 2 additions & 1 deletion src/main/io/rc_controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "drivers/system.h"
#include "drivers/sensor.h"
#include "drivers/accgyro.h"
#include "drivers/gyro_sync.h"

#include "sensors/barometer.h"
#include "sensors/battery.h"
Expand Down Expand Up @@ -215,7 +216,7 @@ void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStat

if (rcSticks == THR_LO + YAW_LO + PIT_LO + ROL_CE) {
// GYRO calibration
gyroSetCalibrationCycles(CALIBRATING_GYRO_CYCLES);
gyroSetCalibrationCycles(calculateCalibratingCycles());

#ifdef GPS
if (feature(FEATURE_GPS)) {
Expand Down
13 changes: 7 additions & 6 deletions src/main/io/rc_controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ typedef enum {
BOXBLACKBOX,
BOXFAILSAFE,
BOXAIRMODE,
BOXACROPLUS,
BOXALWAYSSTABILIZED,
BOXTEST1,
BOXTEST2,
BOXTEST3,
CHECKBOX_ITEM_COUNT
BOXACROPLUS,
BOX3DDISABLESWITCH,
BOXALWAYSSTABILIZED,
BOXTEST1,
BOXTEST2,
BOXTEST3,
CHECKBOX_ITEM_COUNT
} boxId_e;

extern uint32_t rcModeActivationMask;
Expand Down
5 changes: 4 additions & 1 deletion src/main/io/rc_curves.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "io/rc_curves.h"

#include "config/config.h"

int16_t lookupPitchRollRC[PITCH_LOOKUP_LENGTH]; // lookup table for expo & RC rate PITCH+ROLL
int16_t lookupYawRC[YAW_LOOKUP_LENGTH]; // lookup table for expo & RC rate YAW
int16_t lookupThrottleRC[THROTTLE_LOOKUP_LENGTH]; // lookup table for expo & mid THROTTLE
Expand All @@ -48,6 +50,7 @@ void generateYawCurve(controlRateConfig_t *controlRateConfig)
void generateThrottleCurve(controlRateConfig_t *controlRateConfig, escAndServoConfig_t *escAndServoConfig)
{
uint8_t i;
uint16_t minThrottle = (feature(FEATURE_3D && IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH)) ? PWM_RANGE_MIN : escAndServoConfig->minthrottle);

for (i = 0; i < THROTTLE_LOOKUP_LENGTH; i++) {
int16_t tmp = 10 * i - controlRateConfig->thrMid8;
Expand All @@ -57,6 +60,6 @@ void generateThrottleCurve(controlRateConfig_t *controlRateConfig, escAndServoCo
if (tmp < 0)
y = controlRateConfig->thrMid8;
lookupThrottleRC[i] = 10 * controlRateConfig->thrMid8 + tmp * (100 - controlRateConfig->thrExpo8 + (int32_t) controlRateConfig->thrExpo8 * (tmp * tmp) / (y * y)) / 10;
lookupThrottleRC[i] = escAndServoConfig->minthrottle + (int32_t) (escAndServoConfig->maxthrottle - escAndServoConfig->minthrottle) * lookupThrottleRC[i] / 1000; // [MINTHROTTLE;MAXTHROTTLE]
lookupThrottleRC[i] = minThrottle + (int32_t) (escAndServoConfig->maxthrottle - minThrottle) * lookupThrottleRC[i] / 1000; // [MINTHROTTLE;MAXTHROTTLE]
}
}
60 changes: 45 additions & 15 deletions src/main/io/serial_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ static void cliAdjustmentRange(char *cmdline);
static void cliMotorMix(char *cmdline);
static void cliDefaults(char *cmdline);
static void cliDump(char *cmdLine);
void cliDumpProfile(uint8_t profileIndex);
void cliDumpRateProfile(uint8_t rateProfileIndex) ;
static void cliExit(char *cmdline);
static void cliFeature(char *cmdline);
static void cliMotor(char *cmdline);
Expand Down Expand Up @@ -1841,8 +1843,6 @@ typedef enum {
DUMP_RATES = (1 << 2),
} dumpFlags_e;

#define DUMP_ALL (DUMP_MASTER | DUMP_PROFILE | DUMP_RATES)


static const char* const sectionBreak = "\r\n";

Expand All @@ -1858,7 +1858,7 @@ static void cliDump(char *cmdline)
float thr, roll, pitch, yaw;
#endif

uint8_t dumpMask = DUMP_ALL;
uint8_t dumpMask = DUMP_MASTER;
if (strcasecmp(cmdline, "master") == 0) {
dumpMask = DUMP_MASTER; // only
}
Expand Down Expand Up @@ -1953,7 +1953,7 @@ static void cliDump(char *cmdline)
if (mask & (1 << i))
cliPrintf("beeper -%s\r\n", beeperNameForTableIndex(i));
else
cliPrintf("beeper %s\r\n", beeperNameForTableIndex(i));
cliPrintf("beeper %s\r\n", beeperNameForTableIndex(i));
}
#endif

Expand Down Expand Up @@ -2010,27 +2010,57 @@ static void cliDump(char *cmdline)

cliPrint("\r\n# rxfail\r\n");
cliRxFail("");

uint8_t activeProfile = masterConfig.current_profile_index;
uint8_t i;
for (i=0; i<MAX_PROFILE_COUNT;i++)
cliDumpProfile(i);

changeProfile(activeProfile);

}

if (dumpMask & DUMP_PROFILE) {
cliPrint("\r\n# dump profile\r\n");
cliDumpProfile(masterConfig.current_profile_index);
}

if (dumpMask & DUMP_RATES) {
cliDumpRateProfile(currentProfile->activeRateProfile);
}

}

void cliDumpProfile(uint8_t profileIndex) {
if (profileIndex >= MAX_PROFILE_COUNT) // Faulty values
return;

changeProfile(profileIndex);
cliPrint("\r\n# profile\r\n");
cliProfile("");

printSectionBreak();

dumpValues(PROFILE_VALUE);

cliPrint("\r\n# rateprofile\r\n");
cliRateProfile("");

printSectionBreak();

dumpValues(PROFILE_RATE_VALUE);
}
uint8_t currentRateIndex = currentProfile->activeRateProfile;
uint8_t i;
for (i=0; i<MAX_RATEPROFILES; i++)
cliDumpRateProfile(i);

changeControlRateProfile(currentRateIndex);
cliPrintf("\r\n# Active rateprofile for profile %d, \r\n", profileIndex); // output rateprofile again to mark "active rateprofile"
cliRateProfile("");
}

void cliDumpRateProfile(uint8_t rateProfileIndex) {
if (rateProfileIndex >= MAX_RATEPROFILES) // Faulty values
return;

changeControlRateProfile(rateProfileIndex);
cliPrint("\r\n# rateprofile\r\n");
cliRateProfile("");
printSectionBreak();

dumpValues(PROFILE_RATE_VALUE);

}
void cliEnter(serialPort_t *serialPort)
{
cliMode = 1;
Expand Down
12 changes: 6 additions & 6 deletions src/main/io/serial_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ static const box_t boxes[CHECKBOX_ITEM_COUNT + 1] = {
{ BOXFAILSAFE, "FAILSAFE;", 27 },
{ BOXAIRMODE, "AIR MODE;", 28 },
{ BOXACROPLUS, "ACRO PLUS;", 29 },
{ BOXALWAYSSTABILIZED, "ALWAYS STABILIZED;", 30 },
{ BOXTEST1, "TEST 1;", 31 },
{ BOXTEST2, "TEST 2;", 32 },
{ BOX3DDISABLESWITCH, "DISABLE 3D SWITCH;", 30},
{ BOXALWAYSSTABILIZED, "ALWAYS STABILIZED;", 31 },
{ BOXTEST1, "TEST 1;", 32 },
{ BOXTEST2, "TEST 2;", 33 },
{ CHECKBOX_ITEM_COUNT, NULL, 0xFF }
};

Expand Down Expand Up @@ -554,7 +555,7 @@ void mspInit(serialConfig_t *serialConfig)

#ifdef BARO
activeBoxIds[activeBoxIdCount++] = BOXACROPLUS;

activeBoxIds[activeBoxIdCount++] = BOX3DDISABLESWITCH;
if (sensors(SENSOR_BARO)) {
activeBoxIds[activeBoxIdCount++] = BOXBARO;
}
Expand Down Expand Up @@ -670,8 +671,7 @@ static uint32_t packFlightModeFlags(void)
IS_ENABLED(IS_RC_MODE_ACTIVE(BOXAIRMODE)) << BOXAIRMODE|
IS_ENABLED(IS_RC_MODE_ACTIVE(BOXACROPLUS)) << BOXACROPLUS|
IS_ENABLED(IS_RC_MODE_ACTIVE(BOXALWAYSSTABILIZED)) << BOXALWAYSSTABILIZED|
IS_ENABLED(IS_RC_MODE_ACTIVE(BOXTEST1)) << BOXTEST1|
IS_ENABLED(IS_RC_MODE_ACTIVE(BOXTEST2)) << BOXTEST2;
IS_ENABLED(IS_RC_MODE_ACTIVE(BOXTEST1)) << BOXTEST1;

for (i = 0; i < activeBoxIdCount; i++) {
int flag = (tmp & (1 << activeBoxIds[i]));
Expand Down
2 changes: 1 addition & 1 deletion src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ void init(void)
if (masterConfig.mixerMode == MIXER_GIMBAL) {
accSetCalibrationCycles(CALIBRATING_ACC_CYCLES);
}
gyroSetCalibrationCycles(CALIBRATING_GYRO_CYCLES);
gyroSetCalibrationCycles(calculateCalibratingCycles());
#ifdef BARO
baroSetCalibrationCycles(CALIBRATING_BARO_CYCLES);
#endif
Expand Down
Loading

0 comments on commit 7250d5f

Please sign in to comment.