Skip to content

Commit

Permalink
Merge pull request #136 from rtlopez/reconf
Browse files Browse the repository at this point in the history
Config refactor
  • Loading branch information
rtlopez authored Oct 29, 2024
2 parents 9b58c55 + 3323292 commit 81f58d6
Show file tree
Hide file tree
Showing 46 changed files with 1,634 additions and 1,805 deletions.
46 changes: 16 additions & 30 deletions .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,28 @@ on:

jobs:
test:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Cache pip
- name: Cache Pio
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v4
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install platformio
run: pip install --upgrade platformio
- name: Run PlatformIO Test
run: platformio test -e native

build:
needs: test
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
matrix:
target: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp8266', 'rp2040', 'rp2350']
Expand All @@ -61,26 +54,19 @@ jobs:
echo NAME: ${{ env.build_name }}
echo DEVEL: ${{ env.build_file_devel }}
echo RELEASE: ${{ env.build_file_release }}
- name: Cache pip
- name: Cache Pio
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v4
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install platformio
run: pip install --upgrade platformio


- name: Build Development Target
Expand Down
72 changes: 36 additions & 36 deletions lib/Espfc/src/Actuator.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ class Actuator

int begin()
{
_model.state.modeMask = 0;
_model.state.modeMaskPrev = 0;
_model.state.modeMaskPresent = 0;
_model.state.modeMaskSwitch = 0;
_model.state.mode.mask = 0;
_model.state.mode.maskPrev = 0;
_model.state.mode.maskPresent = 0;
_model.state.mode.maskSwitch = 0;
for(size_t i = 0; i < ACTUATOR_CONDITIONS; i++)
{
const auto &c = _model.config.conditions[i];
if(!(c.min < c.max)) continue; // inactive
if(c.ch < AXIS_AUX_1 || c.ch >= AXIS_COUNT) continue; // invalid channel
_model.state.modeMaskPresent |= 1 << c.id;
_model.state.mode.maskPresent |= 1 << c.id;
}
_model.state.airmodeAllowed = false;
_model.state.rescueConfigMode = RESCUE_CONFIG_PENDING;
_model.state.mode.airmodeAllowed = false;
_model.state.mode.rescueConfigMode = RESCUE_CONFIG_PENDING;
return 1;
}

Expand All @@ -42,7 +42,7 @@ class Actuator
updateDynLpf();
updateRescueConfig();

if(_model.config.debugMode == DEBUG_PIDLOOP)
if(_model.config.debug.mode == DEBUG_PIDLOOP)
{
_model.state.debug[4] = micros() - startTime;
}
Expand All @@ -64,11 +64,11 @@ class Actuator
short c = _model.config.scaler[i].channel;
if(c < AXIS_AUX_1) continue;

float v = _model.state.input[c];
float v = _model.state.input.ch[c];
float min = _model.config.scaler[i].minScale * 0.01f;
float max = _model.config.scaler[i].maxScale * 0.01f;
float scale = Math::map3(v, -1.f, 0.f, 1.f, min, min < 0 ? 0.f : 1.f, max);
for(size_t x = 0; x < AXES; x++)
for(size_t x = 0; x < AXIS_COUNT_RPYT; x++)
{
if(
(x == AXIS_ROLL && (mode & ACT_AXIS_ROLL)) ||
Expand Down Expand Up @@ -98,13 +98,13 @@ class Actuator
int errors = _model.state.i2cErrorDelta;
_model.state.i2cErrorDelta = 0;

_model.setArmingDisabled(ARMING_DISABLED_NO_GYRO, !_model.state.gyroPresent || errors);
_model.setArmingDisabled(ARMING_DISABLED_NO_GYRO, !_model.state.gyro.present || errors);
_model.setArmingDisabled(ARMING_DISABLED_FAILSAFE, _model.state.failsafe.phase != FC_FAILSAFE_IDLE);
_model.setArmingDisabled(ARMING_DISABLED_RX_FAILSAFE, _model.state.inputRxLoss || _model.state.inputRxFailSafe);
_model.setArmingDisabled(ARMING_DISABLED_RX_FAILSAFE, _model.state.input.rxLoss || _model.state.input.rxFailSafe);
_model.setArmingDisabled(ARMING_DISABLED_THROTTLE, !_model.isThrottleLow());
_model.setArmingDisabled(ARMING_DISABLED_CALIBRATING, _model.calibrationActive());
_model.setArmingDisabled(ARMING_DISABLED_MOTOR_PROTOCOL, _model.config.output.protocol == ESC_PROTOCOL_DISABLED);
_model.setArmingDisabled(ARMING_DISABLED_REBOOT_REQUIRED, _model.state.rescueConfigMode == RESCUE_CONFIG_ACTIVE);
_model.setArmingDisabled(ARMING_DISABLED_REBOOT_REQUIRED, _model.state.mode.rescueConfigMode == RESCUE_CONFIG_ACTIVE);
}

void updateModeMask()
Expand All @@ -120,7 +120,7 @@ class Actuator
size_t ch = c->ch; // + AXIS_AUX_1;
if(ch < AXIS_AUX_1 || ch >= AXIS_COUNT) continue; // invalid channel

int16_t val = _model.state.inputUs[ch];
int16_t val = _model.state.input.us[ch];
if(val > min && val < max)
{
newMask |= 1 << c->id;
Expand All @@ -141,7 +141,7 @@ class Actuator
for(size_t i = 0; i < MODE_COUNT; i++)
{
bool newVal = newMask & (1 << i);
bool oldVal = _model.state.modeMask & (1 << i);
bool oldVal = _model.state.mode.mask & (1 << i);
if(newVal == oldVal) continue; // mode unchanged
if(newVal && !canActivateMode((FlightMode)i))
{
Expand All @@ -161,7 +161,7 @@ class Actuator
case MODE_ANGLE:
return _model.accelActive();
case MODE_AIRMODE:
return _model.state.airmodeAllowed;
return _model.state.mode.airmodeAllowed;
default:
return true;
}
Expand All @@ -174,12 +174,12 @@ class Actuator
bool armed = _model.isModeActive(MODE_ARMED);
if(armed)
{
_model.state.disarmReason = DISARM_REASON_SYSTEM;
_model.state.rescueConfigMode = RESCUE_CONFIG_DISABLED;
_model.state.mode.disarmReason = DISARM_REASON_SYSTEM;
_model.state.mode.rescueConfigMode = RESCUE_CONFIG_DISABLED;
}
else if(!armed && _model.state.disarmReason == DISARM_REASON_SYSTEM)
else if(!armed && _model.state.mode.disarmReason == DISARM_REASON_SYSTEM)
{
_model.state.disarmReason = DISARM_REASON_SWITCH;
_model.state.mode.disarmReason = DISARM_REASON_SWITCH;
}
}
}
Expand All @@ -189,11 +189,11 @@ class Actuator
bool armed = _model.isModeActive(MODE_ARMED);
if(!armed)
{
_model.state.airmodeAllowed = false;
_model.state.mode.airmodeAllowed = false;
}
if(armed && !_model.state.airmodeAllowed && _model.state.inputUs[AXIS_THRUST] > 1400) // activate airmode in the air
if(armed && !_model.state.mode.airmodeAllowed && _model.state.input.us[AXIS_THRUST] > 1400) // activate airmode in the air
{
_model.state.airmodeAllowed = true;
_model.state.mode.airmodeAllowed = true;
}
}

Expand All @@ -203,7 +203,7 @@ class Actuator
{
_model.state.buzzer.play(BUZZER_RX_LOST);
}
if(_model.state.battery.warn(_model.config.vbatCellWarning))
if(_model.state.battery.warn(_model.config.vbat.cellWarning))
{
_model.state.buzzer.play(BUZZER_BAT_LOW);
}
Expand All @@ -220,34 +220,34 @@ class Actuator
void updateDynLpf()
{
return; // temporary disable
int scale = Math::clamp((int)_model.state.inputUs[AXIS_THRUST], 1000, 2000);
if(_model.config.gyroDynLpfFilter.cutoff > 0) {
int gyroFreq = Math::map(scale, 1000, 2000, _model.config.gyroDynLpfFilter.cutoff, _model.config.gyroDynLpfFilter.freq);
for(size_t i = 0; i <= AXIS_YAW; i++) {
_model.state.gyroFilter[i].reconfigure(gyroFreq);
int scale = Math::clamp((int)_model.state.input.us[AXIS_THRUST], 1000, 2000);
if(_model.config.gyro.dynLpfFilter.cutoff > 0) {
int gyroFreq = Math::map(scale, 1000, 2000, _model.config.gyro.dynLpfFilter.cutoff, _model.config.gyro.dynLpfFilter.freq);
for(size_t i = 0; i < AXIS_COUNT_RPY; i++) {
_model.state.gyro.filter[i].reconfigure(gyroFreq);
}
}
if(_model.config.dtermDynLpfFilter.cutoff > 0) {
int dtermFreq = Math::map(scale, 1000, 2000, _model.config.dtermDynLpfFilter.cutoff, _model.config.dtermDynLpfFilter.freq);
for(size_t i = 0; i <= AXIS_YAW; i++) {
if(_model.config.dterm.dynLpfFilter.cutoff > 0) {
int dtermFreq = Math::map(scale, 1000, 2000, _model.config.dterm.dynLpfFilter.cutoff, _model.config.dterm.dynLpfFilter.freq);
for(size_t i = 0; i < AXIS_COUNT_RPY; i++) {
_model.state.innerPid[i].dtermFilter.reconfigure(dtermFreq);
}
}
}

void updateRescueConfig()
{
switch(_model.state.rescueConfigMode)
switch(_model.state.mode.rescueConfigMode)
{
case RESCUE_CONFIG_PENDING:
// if some rc frames are received, disable to prevent activate later
if(_model.state.inputFrameCount > 100)
if(_model.state.input.frameCount > 100)
{
_model.state.rescueConfigMode = RESCUE_CONFIG_DISABLED;
_model.state.mode.rescueConfigMode = RESCUE_CONFIG_DISABLED;
}
if(_model.state.failsafe.phase != FC_FAILSAFE_IDLE && _model.config.rescueConfigDelay > 0 && millis() > _model.config.rescueConfigDelay * 1000)
{
_model.state.rescueConfigMode = RESCUE_CONFIG_ACTIVE;
_model.state.mode.rescueConfigMode = RESCUE_CONFIG_ACTIVE;
}
break;
case RESCUE_CONFIG_ACTIVE:
Expand Down
Loading

0 comments on commit 81f58d6

Please sign in to comment.