Skip to content

Add CLI setting to adjust Programming Framework update rate - #12276

Open
KyokushinPL wants to merge 4 commits into
iNavFlight:maintenance-10.xfrom
KyokushinPL:maintenance-10.x
Open

KyokushinPL wants to merge 4 commits into
iNavFlight:maintenance-10.xfrom
KyokushinPL:maintenance-10.x

Conversation

@KyokushinPL

Copy link
Copy Markdown

Adds a new CLI setting to control the update rate of the Programming Framework task (Logic Conditions, GVARs, RC channel overrides, etc.).

  • Range: 10–100 Hz
  • Default: 10 Hz

The previous hardcoded 10 Hz rate is too low for use cases that require smoother response, such as:
RC channel overrides

  • Using GVARs as a source for servo control (e.g. camera pan)
  • Headtracking with a re-center / offset feature

In these scenarios the low update rate causes visible stepping or lag. Making the rate configurable allows users to raise it (up to 100 Hz) on capable flight controllers when smoother behavior is needed.

@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add CLI setting to adjust Programming Framework update rate

✨ Enhancement ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Adds programmingFrameworkRateHz to systemConfig_t, default 10 Hz, range 10–100 Hz.
• Reschedules the Programming Framework task at init using the configured rate instead of the fixed
 10 Hz.
• Registers the new setting in settings.yaml. The systemConfig PG version bump only covers the
 non-auto-transition branch.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed scheduler setting feeds one task whose end-to-end behavior jointly updates programming PIDs, output-profile transitions, and logic conditions; these are related operations within the same bounded programming-framework integration rather than separate technical-layer capabilities.
Sources

src/main/fc/fc_tasks.c[474-477]

#ifdef USE_PROGRAMMING_FRAMEWORK
    setTaskEnabled(TASK_PROGRAMMING_FRAMEWORK, true);
    rescheduleTask(TASK_PROGRAMMING_FRAMEWORK,
                   TASK_PERIOD_HZ(systemConfig()->programmingFrameworkRateHz));
Behavioral complexity 🟢 Low 🧩 Straightforward

  • Before, the programming framework ran at a fixed 10 Hz period.
  • After, a persisted, bounded configuration value selects the task period during initialization.
  • The new correctness condition is that the selected cadence remains valid for all three existing task consumers, while the scheduler and their internal update logic remain unchanged.
  • This is a direct scheduling-parameter transformation, not a new algorithm, concurrent protocol, or interacting state machine.
Sources

src/main/fc/fc_tasks.c[474-477]

#ifdef USE_PROGRAMMING_FRAMEWORK
    setTaskEnabled(TASK_PROGRAMMING_FRAMEWORK, true);
    rescheduleTask(TASK_PROGRAMMING_FRAMEWORK,
                   TASK_PERIOD_HZ(systemConfig()->programmingFrameworkRateHz));

src/main/fc/settings.yaml[4314-4321]

      - name: programming_framework_rate_hz
        description: "Programming Framework / Logic Conditions update rate in Hz (10-100)"
        default_value: 10
        min: 10
        max: 100
        field: programmingFrameworkRateHz
        type: uint8_t
        condition: USE_PROGRAMMING_FRAMEWORK

src/main/programming/programming_task.c[31-35]

void programmingFrameworkUpdateTask(timeUs_t currentTimeUs) {
    programmingPidUpdateTask(currentTimeUs);
    outputProfileUpdateTask(currentTimeUs);
    logicConditionUpdateTask(currentTimeUs);
}
Potential damage 🟡 Medium 🩹 Recoverable

  • If the configured cadence is wrong or the scheduling change regresses, programmed PID, output-profile, and logic-condition updates can become stale, delayed, or consume more scheduler time.
  • Reverting the setting or code stops new cadence-related effects; no changed path writes external state or performs an irreversible side effect.
  • Persistent configuration may need to be restored to a suitable rate, but the source provides no automatic repair beyond the stored default and setting bounds.
  • Code or setting rollback restores the prior 10 Hz schedule for subsequent updates.
  • Any transient control or logic state produced at the wrong cadence is not shown to be automatically backfilled; operators may need to restore the rate and reinitialize or reconfigure affected programming behavior.
Sources

src/main/programming/programming_task.c[31-35]

void programmingFrameworkUpdateTask(timeUs_t currentTimeUs) {
    programmingPidUpdateTask(currentTimeUs);
    outputProfileUpdateTask(currentTimeUs);
    logicConditionUpdateTask(currentTimeUs);
}

src/main/fc/fc_tasks.c[474-477]

#ifdef USE_PROGRAMMING_FRAMEWORK
    setTaskEnabled(TASK_PROGRAMMING_FRAMEWORK, true);
    rescheduleTask(TASK_PROGRAMMING_FRAMEWORK,
                   TASK_PERIOD_HZ(systemConfig()->programmingFrameworkRateHz));

src/main/fc/settings.yaml[4314-4321]

      - name: programming_framework_rate_hz
        description: "Programming Framework / Logic Conditions update rate in Hz (10-100)"
        default_value: 10
        min: 10
        max: 100
        field: programmingFrameworkRateHz
        type: uint8_t
        condition: USE_PROGRAMMING_FRAMEWORK
Assessed commit 6e528fa
Diagram

graph TD
  A["settings.yaml"] --> B["systemConfig_t"] --> C["fcTasksInit"] --> D["rescheduleTask"] --> E["Programming Framework task"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Clamp the value at runtime and bump PG version in all branches
  • ➕ Protects against corrupted or zero EEPROM values
  • ➕ Keeps the stored layout in sync across build variants
  • ➖ Adds a small amount of validation code
2. Apply the new rate live via rescheduleTask on CLI set
  • ➕ No reboot needed to test different rates
  • ➖ Needs a setting-change callback, which adds complexity for a rarely changed value

Recommendation: The approach fits the codebase: a PG setting plus a settings.yaml entry, applied at task init. Two fixes are needed before merge. (1) Bump the PG version in the USE_AUTO_TRANSITION branch too (11 to 12), so every build that changes the struct layout resets stale EEPROM data. (2) Guard against a zero or out-of-range stored value, by clamping to 10–100 in fcTasksInit or in the settings validator, so TASK_PERIOD_HZ never sees 0. The rate also only applies at boot, so the CLI change needs a reboot; the PR should say so. Because this is a maintenance-10.x branch, the struct change and PG bump also need checking for backport compatibility.

Files changed (4) +14 / -2

Enhancement (3) +6 / -2
config.cAdd default rate and bump systemConfig PG version +3/-2

Add default rate and bump systemConfig PG version

• Sets the default programmingFrameworkRateHz to 10 in the systemConfig reset template. Bumps the PG version from 7 to 8 in the non-auto-transition branch only; the auto-transition branch stays at 11, so it does not trigger a reset for the new field.

src/main/fc/config.c

config.hAdd programmingFrameworkRateHz to systemConfig_t +1/-0

Add programmingFrameworkRateHz to systemConfig_t

• Adds a uint8_t field for the Programming Framework task rate in Hz at the end of systemConfig_t. Appending keeps the existing field offsets unchanged.

src/main/fc/config.h

fc_tasks.cReschedule Programming Framework task from configured rate +2/-0

Reschedule Programming Framework task from configured rate

• Calls rescheduleTask with TASK_PERIOD_HZ(systemConfig()->programmingFrameworkRateHz) after enabling the task in fcTasksInit. This replaces the hardcoded 10 Hz period. A stored value of 0 would reach TASK_PERIOD_HZ unchecked.

src/main/fc/fc_tasks.c

Other (1) +8 / -0
settings.yamlRegister programming_framework_rate_hz setting with 10–100 range +8/-0

Register programming_framework_rate_hz setting with 10–100 range

• Adds the programming_framework_rate_hz setting mapped to programmingFrameworkRateHz, with default 10, min 10, max 100, and the USE_PROGRAMMING_FRAMEWORK condition. The CLI setting is generated from this entry.

src/main/fc/settings.yaml

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Upgraded boards on auto-transition builds read a bogus task rate 🐞 Bug ≡ Correctness
Description
The USE_AUTO_TRANSITION branch of the systemConfig_t PG registration keeps version 11 while only
the #else branch was bumped (7 -> 8), so an existing version-11 EEPROM image skips the reset
template and leaves the new programmingFrameworkRateHz field holding 0 or leftover bytes.
fcTasksInit then passes that raw value into TASK_PERIOD_HZ(hz), which computes 1000000 / (hz)
without clamping to the documented 10-100 Hz range, so every upgraded board of that class divides by
zero at boot. The settings.yaml min/max bounds only constrain the CLI set path, so hand-edited or
stored out-of-range values reach the macro unchecked.
Code

src/main/fc/config.c[110]

+PG_REGISTER_WITH_RESET_TEMPLATE(systemConfig_t, systemConfig, PG_SYSTEM_CONFIG, 8);
Evidence
The comment at config.c:106 states that the version split exists because the stored layout differs
per build, so any layout change requires a version bump. The PR adds the field to systemConfig_t for
both builds but bumps only the non-auto-transition version, leaving USE_AUTO_TRANSITION at 11, so
the reset template (which sets the field to 10) is not applied to existing 11 images. The value then
flows unchecked into TASK_PERIOD_HZ at fc_tasks.c:477, and that macro is a raw integer division
(scheduler.h:200) whose result reaches rescheduleTask, so neither the version mismatch nor the
missing guard is caught before boot.

src/main/fc/config.c[106-110]
src/main/fc/config.c[125-138]
src/main/fc/fc_tasks.c[475-478]
src/main/fc/settings.yaml[4314-4321]
src/main/scheduler/scheduler.h[200]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
In `src/main/fc/config.c`, the `systemConfig_t` PG version is bumped only in the `#else` branch (7 -> 8). The `USE_AUTO_TRANSITION` branch still registers version 11 even though the struct gained `programmingFrameworkRateHz`. Existing version-11 EEPROM images skip the reset template and keep whatever bytes sit past the old layout, often 0. `fcTasksInit` then passes that raw value into `TASK_PERIOD_HZ(hz)` (`1000000 / (hz)`) without clamping to the documented 10-100 Hz range, causing a divide by zero at boot. The settings.yaml min/max only guard the CLI set path, so hand-edited or stored out-of-range values are also unguarded.

## Fix Focus Areas
- src/main/fc/config.c[106-110]
- src/main/fc/fc_tasks.c[475-478]
- src/main/scheduler/scheduler.h[200]

## Recommended Fix
1. In the `USE_AUTO_TRANSITION` branch of the systemConfig_t PG registration, increment the version (11 -> 12) so the reset template applies to stored images that lack the new field. Keep the `#else` branch at 8. Confirm the new number does not collide with other configs or with any migration logic keyed on the PG version.
2. In `fcTasksInit`, clamp `systemConfig()->programmingFrameworkRateHz` to [10, 100] (for example with `constrain()`) before passing it to `TASK_PERIOD_HZ`, or fall back to the default when it is 0. Keep the clamp next to the reschedule call so the boot path is covered regardless of how the stored value was written.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Rate change from the CLI waits for a reboot 🐞 Bug ≡ Correctness
Description
The new rate is applied only once, in fcTasksInit, through rescheduleTask, so editing
programming_framework_rate_hz in the CLI does not change the running task period. Users who raise
the rate for smoother RC or GVAR response see no effect until the flight controller restarts, and
nothing in the PR tells them so.
Code

src/main/fc/fc_tasks.c[R476-477]

+    rescheduleTask(TASK_PROGRAMMING_FRAMEWORK,
+                   TASK_PERIOD_HZ(systemConfig()->programmingFrameworkRateHz));
Evidence
The only call that reads the setting is in fcTasksInit, and the settings.yaml entry has no hook that
reschedules the task on change. The PR description presents the setting as a tuning knob to raise on
capable flight controllers, which implies live use, but the code takes effect only on reboot.

src/main/fc/fc_tasks.c[475-478]
src/main/fc/settings.yaml[4314-4321]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The `programming_framework_rate_hz` setting is read only in `fcTasksInit` (`src/main/fc/fc_tasks.c`), so a CLI change does not alter the running `TASK_PROGRAMMING_FRAMEWORK` period until the next boot. Users who change the value will think it has no effect.

## Fix Focus Areas
- src/main/fc/fc_tasks.c[475-478]
- src/main/fc/settings.yaml[4314-4321]

## Recommended Fix
Either hook the setting's change path (a CLI or settings-update callback) to call `rescheduleTask` again with the new period, or, if that is out of scope, state in the setting description and release notes that a reboot is required for the new rate to take effect.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Cross-repo context — repo relationships
Review mode: Auto: 🚀 Fast: Localized task-rate configuration change with limited behavioral surface.

Grey Divider

Tip of the day
💡 Did you know, you can move or hide resolved findings to focus on what still needs action

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@error414

error414 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Have you tried if 100hz is ok even for F4? If there will be many rules in programming framework?

@KyokushinPL

KyokushinPL commented Dec 3, 2026 •

Copy link
Copy Markdown
Author

Have you tried if 100hz is ok even for F4? If there will be many rules in programming framework?

No, i tested on TBS Lucid Wing Mini AIO, and it does handle that easily.
I suggest to keep 10 Hz value as default, and change it only if you need more, with testing on own controller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants