Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into abo_acro_attitude…
Browse files Browse the repository at this point in the history
…_hold
  • Loading branch information
breadoven committed Oct 26, 2023
2 parents c775c29 + 692c61c commit 98f7f43
Show file tree
Hide file tree
Showing 142 changed files with 438 additions and 862 deletions.
36 changes: 23 additions & 13 deletions docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -1312,16 +1312,6 @@ Iterm is not allowed to grow when stick position is above threshold. This solves

---

### fw_iterm_throw_limit

Limits max/min I-term value in stabilization PID controller in case of Fixed Wing. It solves the problem of servo saturation before take-off/throwing the airplane into the air. By default, error accumulated in I-term can not exceed 1/3 of servo throw (around 165us). Set 0 to disable completely.

| Default | Min | Max |
| --- | --- | --- |
| 165 | FW_ITERM_THROW_LIMIT_MIN | FW_ITERM_THROW_LIMIT_MAX |

---

### fw_level_pitch_gain

I-gain for the pitch trim for self-leveling flight modes. Higher values means that AUTOTRIM will be faster but might introduce oscillations
Expand Down Expand Up @@ -4482,9 +4472,9 @@ LQ % indicator blinks below this value. For Crossfire use 70%, for Tracer use 50

---

### osd_mah_used_precision
### osd_mah_precision

Number of digits used to display mAh used.
Number of digits used for mAh precision. Currently used by mAh Used and Battery Remaining Capacity

| Default | Min | Max |
| --- | --- | --- |
Expand Down Expand Up @@ -4892,6 +4882,16 @@ Video system used. Possible values are `AUTO`, `PAL`, `NTSC`, `HDZERO`, 'DJIWTF'

---

### pid_iterm_limit_percent

Limits max/min I-term value in stabilization PID controller. It solves the problem of servo saturation before take-off/throwing the airplane into the air. Or multirotors with low authority. By default, error accumulated in I-term can not exceed 33% of total pid throw (around 165us on deafult pidsum_limit of pitch/roll). Set 0 to disable completely.

| Default | Min | Max |
| --- | --- | --- |
| 33 | 0 | 200 |

---

### pid_type

Allows to set type of PID controller used in control loop. Possible values: `NONE`, `PID`, `PIFF`, `AUTO`. Change only in case of experimental platforms like VTOL, tailsitters, rovers, boats, etc. Airplanes should always use `PIFF` and multirotors `PID`
Expand Down Expand Up @@ -5792,9 +5792,19 @@ See tpa_rate.

---

### tpa_on_yaw

Throttle PID attenuation also reduces influence on YAW for multi-rotor, Should be set to ON for tilting rotors.

| Default | Min | Max |
| --- | --- | --- |
| OFF | OFF | ON |

---

### tpa_rate

Throttle PID attenuation reduces influence of P on ROLL and PITCH as throttle increases. For every 1% throttle after the TPA breakpoint, P is reduced by the TPA rate.
Throttle PID attenuation reduces influence of PDFF on ROLL and PITCH of multi-rotor, PIDFF on ROLL,PITCH,YAW OF fixed_wing as throttle increases. For every 1% throttle after the TPA breakpoint, P is reduced by the TPA rate.

| Default | Min | Max |
| --- | --- | --- |
Expand Down
4 changes: 2 additions & 2 deletions src/main/drivers/accgyro/accgyro_bmi270.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static void bmi270AccAndGyroInit(gyroDev_t *gyro)
delay(1);

// Configure the accelerometer full-scale range
busWrite(busDev, BMI270_REG_ACC_RANGE, BMI270_ACC_RANGE_8G);
busWrite(busDev, BMI270_REG_ACC_RANGE, BMI270_ACC_RANGE_16G);
delay(1);

// Configure the gyro
Expand Down Expand Up @@ -301,7 +301,7 @@ static void bmi270GyroInit(gyroDev_t *gyro)
static void bmi270AccInit(accDev_t *acc)
{
// sensor is configured during gyro init
acc->acc_1G = 4096; // 8G sensor scale
acc->acc_1G = 2048; // 16G sensor scale
}

bool bmi270AccDetect(accDev_t *acc)
Expand Down
13 changes: 12 additions & 1 deletion src/main/drivers/accgyro/accgyro_icm42605.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@
#define ICM42605_INT_TPULSE_DURATION_100 (0 << ICM42605_INT_TPULSE_DURATION_BIT)
#define ICM42605_INT_TPULSE_DURATION_8 (1 << ICM42605_INT_TPULSE_DURATION_BIT)


#define ICM42605_RA_INT_SOURCE0 0x65
#define ICM42605_UI_DRDY_INT1_EN_DISABLED (0 << 3)
#define ICM42605_UI_DRDY_INT1_EN_ENABLED (1 << 3)

#define ICM42605_INTF_CONFIG1 0x4D
#define ICM42605_INTF_CONFIG1_AFSR_MASK 0xC0
#define ICM42605_INTF_CONFIG1_AFSR_DISABLE 0x40

static void icm42605AccInit(accDev_t *acc)
{
Expand Down Expand Up @@ -190,6 +192,15 @@ static void icm42605AccAndGyroInit(gyroDev_t *gyro)
busWrite(dev, ICM42605_RA_INT_CONFIG1, intConfig1Value);
delay(15);

//Disable AFSR as in BF and Ardupilot
uint8_t intfConfig1Value;
busRead(dev, ICM42605_INTF_CONFIG1, &intfConfig1Value);
intfConfig1Value &= ~ICM42605_INTF_CONFIG1_AFSR_MASK;
intfConfig1Value |= ICM42605_INTF_CONFIG1_AFSR_DISABLE;
busWrite(dev, ICM42605_INTF_CONFIG1, intfConfig1Value);

delay(15);

busSetSpeed(dev, BUS_SPEED_FAST);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/drivers/bus_i2c_at32f43x.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void i2cUnstick(IO_t scl, IO_t sda);

//Define thi I2C hardware map
static i2cDevice_t i2cHardwareMap[I2CDEV_COUNT] = {
{ .dev = I2C1, .scl = IO_TAG(I2C1_SCL), .sda = IO_TAG(I2C1_SDA), .rcc = RCC_APB1(I2C1), .speed = I2C_SPEED_400KHZ, .ev_irq = I2C1_EVT_IRQn, .er_irq = I2C1_ERR_IRQn, .af = GPIO_MUX_8 },
{ .dev = I2C1, .scl = IO_TAG(I2C1_SCL), .sda = IO_TAG(I2C1_SDA), .rcc = RCC_APB1(I2C1), .speed = I2C_SPEED_400KHZ, .ev_irq = I2C1_EVT_IRQn, .er_irq = I2C1_ERR_IRQn, .af = GPIO_MUX_4 },
{ .dev = I2C2, .scl = IO_TAG(I2C2_SCL), .sda = IO_TAG(I2C2_SDA), .rcc = RCC_APB1(I2C2), .speed = I2C_SPEED_400KHZ, .ev_irq = I2C2_EVT_IRQn, .er_irq = I2C2_ERR_IRQn, .af = GPIO_MUX_4 },
{ .dev = I2C3, .scl = IO_TAG(I2C3_SCL), .sda = IO_TAG(I2C3_SDA), .rcc = RCC_APB1(I2C3), .speed = I2C_SPEED_400KHZ, .ev_irq = I2C3_EVT_IRQn, .er_irq = I2C3_ERR_IRQn, .af = GPIO_MUX_4 },
};
Expand Down
1 change: 1 addition & 0 deletions src/main/fc/controlrate_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void pgResetFn_controlRateProfiles(controlRateConfig_t *instance)
.rcMid8 = SETTING_THR_MID_DEFAULT,
.rcExpo8 = SETTING_THR_EXPO_DEFAULT,
.dynPID = SETTING_TPA_RATE_DEFAULT,
.dynPID_on_YAW = SETTING_TPA_ON_YAW_DEFAULT,
.pa_breakpoint = SETTING_TPA_BREAKPOINT_DEFAULT,
.fixedWingTauMs = SETTING_FW_TPA_TIME_CONSTANT_DEFAULT
},
Expand Down
1 change: 1 addition & 0 deletions src/main/fc/controlrate_profile_config_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef struct controlRateConfig_s {
uint8_t rcMid8;
uint8_t rcExpo8;
uint8_t dynPID;
bool dynPID_on_YAW;
uint16_t pa_breakpoint; // Breakpoint where TPA is activated
uint16_t fixedWingTauMs; // Time constant of airplane TPA PT1-filter
} throttle;
Expand Down
5 changes: 4 additions & 1 deletion src/main/fc/fc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,10 @@ void taskMainPidLoop(timeUs_t currentTimeUs)
if (!ARMING_FLAG(ARMED)) {
armTime = 0;

processDelayedSave();
// Delay saving for 0.5s to allow other functions to process save actions on disarm
if (currentTimeUs - lastDisarmTimeUs > USECS_PER_SEC / 2) {
processDelayedSave();
}
}

if (armTime > 1 * USECS_PER_SEC) { // reset in flight emerg rearm flag 1 sec after arming once it's served its purpose
Expand Down
81 changes: 57 additions & 24 deletions src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
sbufWriteU16(dst, packSensorStatus());
sbufWriteU16(dst, averageSystemLoadPercent);
sbufWriteU8(dst, (getConfigBatteryProfile() << 4) | getConfigProfile());
sbufWriteU8(dst, getConfigMixerProfile());
sbufWriteU32(dst, armingFlags);
sbufWriteData(dst, &mspBoxModeFlags, sizeof(mspBoxModeFlags));
}
Expand Down Expand Up @@ -523,6 +524,18 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
sbufWriteU8(dst, -1);
#endif
}
if(MAX_MIXER_PROFILE_COUNT==1) break;
for (int i = 0; i < MAX_SERVO_RULES; i++) {
sbufWriteU8(dst, mixerServoMixersByIndex(nextMixerProfileIndex)[i].targetChannel);
sbufWriteU8(dst, mixerServoMixersByIndex(nextMixerProfileIndex)[i].inputSource);
sbufWriteU16(dst, mixerServoMixersByIndex(nextMixerProfileIndex)[i].rate);
sbufWriteU8(dst, mixerServoMixersByIndex(nextMixerProfileIndex)[i].speed);
#ifdef USE_PROGRAMMING_FRAMEWORK
sbufWriteU8(dst, mixerServoMixersByIndex(nextMixerProfileIndex)[i].conditionId);
#else
sbufWriteU8(dst, -1);
#endif
}
break;
#ifdef USE_PROGRAMMING_FRAMEWORK
case MSP2_INAV_LOGIC_CONDITIONS:
Expand Down Expand Up @@ -568,11 +581,18 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
#endif
case MSP2_COMMON_MOTOR_MIXER:
for (uint8_t i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
sbufWriteU16(dst, primaryMotorMixer(i)->throttle * 1000);
sbufWriteU16(dst, constrainf(primaryMotorMixer(i)->throttle + 2.0f, 0.0f, 4.0f) * 1000);
sbufWriteU16(dst, constrainf(primaryMotorMixer(i)->roll + 2.0f, 0.0f, 4.0f) * 1000);
sbufWriteU16(dst, constrainf(primaryMotorMixer(i)->pitch + 2.0f, 0.0f, 4.0f) * 1000);
sbufWriteU16(dst, constrainf(primaryMotorMixer(i)->yaw + 2.0f, 0.0f, 4.0f) * 1000);
}
if (MAX_MIXER_PROFILE_COUNT==1) break;
for (uint8_t i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
sbufWriteU16(dst, constrainf(mixerMotorMixersByIndex(nextMixerProfileIndex)[i].throttle + 2.0f, 0.0f, 4.0f) * 1000);
sbufWriteU16(dst, constrainf(mixerMotorMixersByIndex(nextMixerProfileIndex)[i].roll + 2.0f, 0.0f, 4.0f) * 1000);
sbufWriteU16(dst, constrainf(mixerMotorMixersByIndex(nextMixerProfileIndex)[i].pitch + 2.0f, 0.0f, 4.0f) * 1000);
sbufWriteU16(dst, constrainf(mixerMotorMixersByIndex(nextMixerProfileIndex)[i].yaw + 2.0f, 0.0f, 4.0f) * 1000);
}
break;

case MSP_MOTOR:
Expand Down Expand Up @@ -2121,7 +2141,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
case MSP2_COMMON_SET_MOTOR_MIXER:
sbufReadU8Safe(&tmp_u8, src);
if ((dataSize == 9) && (tmp_u8 < MAX_SUPPORTED_MOTORS)) {
primaryMotorMixerMutable(tmp_u8)->throttle = constrainf(sbufReadU16(src) / 1000.0f, 0.0f, 1.0f);
primaryMotorMixerMutable(tmp_u8)->throttle = constrainf(sbufReadU16(src) / 1000.0f, 0.0f, 4.0f) - 2.0f;
primaryMotorMixerMutable(tmp_u8)->roll = constrainf(sbufReadU16(src) / 1000.0f, 0.0f, 4.0f) - 2.0f;
primaryMotorMixerMutable(tmp_u8)->pitch = constrainf(sbufReadU16(src) / 1000.0f, 0.0f, 4.0f) - 2.0f;
primaryMotorMixerMutable(tmp_u8)->yaw = constrainf(sbufReadU16(src) / 1000.0f, 0.0f, 4.0f) - 2.0f;
Expand Down Expand Up @@ -3015,6 +3035,14 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
}
break;

case MSP2_INAV_SELECT_MIXER_PROFILE:
if (!ARMING_FLAG(ARMED) && sbufReadU8Safe(&tmp_u8, src)) {
setConfigMixerProfileAndWriteEEPROM(tmp_u8);
} else {
return MSP_RESULT_ERROR;
}
break;

#ifdef USE_TEMPERATURE_SENSOR
case MSP2_INAV_SET_TEMP_SENSOR_CONFIG:
if (dataSize == sizeof(tempSensorConfig_t) * MAX_TEMP_SENSORS) {
Expand Down Expand Up @@ -3369,7 +3397,7 @@ bool isOSDTypeSupportedBySimulator(void)
{
#ifdef USE_OSD
displayPort_t *osdDisplayPort = osdGetDisplayPort();
return (osdDisplayPort && osdDisplayPort->cols == 30 && (osdDisplayPort->rows == 13 || osdDisplayPort->rows == 16));
return (!!osdDisplayPort && !!osdDisplayPort->vTable->readChar);
#else
return false;
#endif
Expand All @@ -3381,18 +3409,25 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
//scan displayBuffer iteratively
//no more than 80+3+2 bytes output in single run
//0 and 255 are special symbols
//255 - font bank switch
//0 - font bank switch, blink switch and character repeat
//255 [char] - font bank switch
//0 [flags,count] [char] - font bank switch, blink switch and character repeat
//original 0 is sent as 32
//original 0xff, 0x100 and 0x1ff are forcibly sent inside command 0

static uint8_t osdPos_y = 0;
static uint8_t osdPos_x = 0;

//indicate new format hitl 1.4.0
sbufWriteU8(dst, 255);

if (isOSDTypeSupportedBySimulator())
{
displayPort_t *osdDisplayPort = osdGetDisplayPort();

sbufWriteU8(dst, osdPos_y | (osdDisplayPort->rows == 16 ? 128: 0));
sbufWriteU8(dst, osdDisplayPort->rows);
sbufWriteU8(dst, osdDisplayPort->cols);

sbufWriteU8(dst, osdPos_y);
sbufWriteU8(dst, osdPos_x);

int bytesCount = 0;
Expand All @@ -3403,7 +3438,7 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
bool blink = false;
int count = 0;

int processedRows = 16;
int processedRows = osdDisplayPort->rows;

while (bytesCount < 80) //whole response should be less 155 bytes at worst.
{
Expand All @@ -3414,7 +3449,7 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
while ( true )
{
displayReadCharWithAttr(osdDisplayPort, osdPos_x, osdPos_y, &c, &attr);
if (c == 0 || c == 255) c = 32;
if (c == 0) c = 32;

//REVIEW: displayReadCharWithAttr() should return mode with _TEXT_ATTRIBUTES_BLINK_BIT !
//for max7456 it returns mode with MAX7456_MODE_BLINK instead (wrong)
Expand All @@ -3429,27 +3464,28 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
lastChar = c;
blink1 = blink2;
}
else if (lastChar != c || blink2 != blink1 || count == 63)
else if ((lastChar != c) || (blink2 != blink1) || (count == 63))
{
break;
}

count++;

osdPos_x++;
if (osdPos_x == 30)
if (osdPos_x == osdDisplayPort->cols)
{
osdPos_x = 0;
osdPos_y++;
processedRows--;
if (osdPos_y == 16)
if (osdPos_y == osdDisplayPort->rows)
{
osdPos_y = 0;
}
}
}

uint8_t cmd = 0;
uint8_t lastCharLow = (uint8_t)(lastChar & 0xff);
if (blink1 != blink)
{
cmd |= 128;//switch blink attr
Expand All @@ -3465,27 +3501,27 @@ void mspWriteSimulatorOSD(sbuf_t *dst)

if (count == 1 && cmd == 64)
{
sbufWriteU8(dst, 255); //short command for bank switch
sbufWriteU8(dst, 255); //short command for bank switch with char following
sbufWriteU8(dst, lastChar & 0xff);
bytesCount += 2;
}
else if (count > 2 || cmd !=0 )
else if ((count > 2) || (cmd !=0) || (lastChar == 255) || (lastChar == 0x100) || (lastChar == 0x1ff))
{
cmd |= count; //long command for blink/bank switch and symbol repeat
sbufWriteU8(dst, 0);
sbufWriteU8(dst, cmd);
sbufWriteU8(dst, lastChar & 0xff);
sbufWriteU8(dst, lastCharLow);
bytesCount += 3;
}
else if (count == 2) //cmd == 0 here
{
sbufWriteU8(dst, lastChar & 0xff);
sbufWriteU8(dst, lastChar & 0xff);
sbufWriteU8(dst, lastCharLow);
sbufWriteU8(dst, lastCharLow);
bytesCount+=2;
}
else
{
sbufWriteU8(dst, lastChar & 0xff);
sbufWriteU8(dst, lastCharLow);
bytesCount++;
}

Expand All @@ -3499,7 +3535,7 @@ void mspWriteSimulatorOSD(sbuf_t *dst)
}
else
{
sbufWriteU8(dst, 255);
sbufWriteU8(dst, 0);
}
}
#endif
Expand Down Expand Up @@ -3633,6 +3669,7 @@ bool mspFCProcessInOutCommand(uint16_t cmdMSP, sbuf_t *dst, sbuf_t *src, mspResu
}
#endif
ENABLE_ARMING_FLAG(SIMULATOR_MODE_HITL);
ENABLE_STATE(ACCELEROMETER_CALIBRATED);
LOG_DEBUG(SYSTEM, "Simulator enabled");
}

Expand Down Expand Up @@ -3709,15 +3746,11 @@ bool mspFCProcessInOutCommand(uint16_t cmdMSP, sbuf_t *dst, sbuf_t *src, mspResu
sbufAdvance(src, sizeof(uint16_t) * XYZ_AXIS_COUNT);
}

#if defined(USE_FAKE_BATT_SENSOR)
if (SIMULATOR_HAS_OPTION(HITL_EXT_BATTERY_VOLTAGE)) {
fakeBattSensorSetVbat(sbufReadU8(src) * 10);
simulatorData.vbat = sbufReadU8(src);
} else {
#endif
fakeBattSensorSetVbat((uint16_t)(SIMULATOR_FULL_BATTERY * 10.0f));
#if defined(USE_FAKE_BATT_SENSOR)
simulatorData.vbat = SIMULATOR_FULL_BATTERY;
}
#endif

if (SIMULATOR_HAS_OPTION(HITL_AIRSPEED)) {
simulatorData.airSpeed = sbufReadU16(src);
Expand Down
5 changes: 3 additions & 2 deletions src/main/fc/runtime_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ flightModeForTelemetry_e getFlightModeForTelemetry(void)

#ifdef USE_SIMULATOR
simulatorData_t simulatorData = {
.flags = 0,
.debugIndex = 0
.flags = 0,
.debugIndex = 0,
.vbat = 0
};
#endif
Loading

0 comments on commit 98f7f43

Please sign in to comment.