Skip to content

Add two new MSP2 commands for GCS-initiated flight control#11462

Merged
sensei-hacker merged 3 commits intoiNavFlight:maintenance-9.xfrom
danarrib:bulletgcss/msp-set-wp-index-and-altitude
Apr 9, 2026
Merged

Add two new MSP2 commands for GCS-initiated flight control#11462
sensei-hacker merged 3 commits intoiNavFlight:maintenance-9.xfrom
danarrib:bulletgcss/msp-set-wp-index-and-altitude

Conversation

@danarrib
Copy link
Copy Markdown
Contributor

@danarrib danarrib commented Mar 29, 2026

Adds three new write-only MSP2 commands that allow a ground control station to interact with an active INAV navigation session without requiring direct RC transmitter input:

MSP2_INAV_SET_WP_INDEX (0x2221)
Jump to a specific waypoint during an active WP mission.
Payload: U8 wp_index (0-based, relative to mission start waypoint).
Preconditions: aircraft must be armed and NAV_WP_MODE must be active.
Transitions any active waypoint FSM state back to PRE_ACTION so
INAV re-initialises navigation for the new target waypoint.

MSP2_INAV_SET_CRUISE_HEADING (0x2223)
Set the heading target while Cruise or Course Hold mode is active.
Payload: I32 heading_centidegrees (0–35999).
Preconditions: aircraft must be armed and NAV_COURSE_HOLD_MODE must
be active. Sets both posControl.cruise.course and previousCourse to
prevent spurious heading adjustments on the next control cycle.

Implementation details:

  • New FSM event NAV_FSM_EVENT_SWITCH_TO_WAYPOINT_JUMP aliases NAV_FSM_EVENT_STATE_SPECIFIC_4 (safe: WP and RTH states never overlap so the same underlying integer can be reused in both groups).
  • FSM transitions added for PRE_ACTION, IN_PROGRESS, REACHED, HOLD_TIME and FINISHED states, all routing to PRE_ACTION.
  • Two new public functions declared in navigation.h and implemented in navigation.c: navSetActiveWaypointIndex() and navSetCruiseHeading().
  • MSP handlers added in fc_msp.c; all return MSP_RESULT_ERROR if the aircraft is not in a compatible state.

sensei-hacker and others added 2 commits March 22, 2026 14:25
Adds three new write-only MSP2 commands that allow a ground control
station to interact with an active INAV navigation session without
requiring direct RC transmitter input:

  MSP2_INAV_SET_WP_INDEX (0x2221)
    Jump to a specific waypoint during an active WP mission.
    Payload: U8 wp_index (0-based, relative to mission start waypoint).
    Preconditions: aircraft must be armed and NAV_WP_MODE must be active.
    Transitions any active waypoint FSM state back to PRE_ACTION so
    INAV re-initialises navigation for the new target waypoint.

  MSP2_INAV_SET_ALT_TARGET (0x2222)
    Set a new target altitude while altitude-controlled navigation is active.
    Payload: I32 altitude_cm (centimetres, relative to home).
    Preconditions: aircraft must be armed and NAV_CTL_ALT must be active.
    Calls updateClimbRateToAltitudeController() which works for both
    multicopter and fixed-wing platforms.

  MSP2_INAV_SET_CRUISE_HEADING (0x2223)
    Set the heading target while Cruise or Course Hold mode is active.
    Payload: I32 heading_centidegrees (0–35999).
    Preconditions: aircraft must be armed and NAV_COURSE_HOLD_MODE must
    be active. Sets both posControl.cruise.course and previousCourse to
    prevent spurious heading adjustments on the next control cycle.

Implementation details:
  - New FSM event NAV_FSM_EVENT_SWITCH_TO_WAYPOINT_JUMP aliases
    NAV_FSM_EVENT_STATE_SPECIFIC_4 (safe: WP and RTH states never
    overlap so the same underlying integer can be reused in both groups).
  - FSM transitions added for PRE_ACTION, IN_PROGRESS, REACHED,
    HOLD_TIME and FINISHED states, all routing to PRE_ACTION.
  - Three new public functions declared in navigation.h and implemented
    in navigation.c: navSetActiveWaypointIndex(), navSetDesiredAltitude(),
    navSetCruiseHeading().
  - MSP handlers added in fc_msp.c; all return MSP_RESULT_ERROR if the
    aircraft is not in a compatible state.
@github-actions
Copy link
Copy Markdown

Branch Targeting Suggestion

You've targeted the master branch with this PR. Please consider if a version branch might be more appropriate:

  • maintenance-9.x - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.

  • maintenance-10.x - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x

If master is the correct target for this change, no action is needed.


This is an automated suggestion to help route contributions to the appropriate branch.

@danarrib danarrib changed the base branch from master to maintenance-9.x March 29, 2026 16:33
@danarrib
Copy link
Copy Markdown
Contributor Author

danarrib commented Mar 29, 2026

Just a little bit of context:

Bullet GCSS (my internet-based Ground Station System) will have this feature of setting a new altitude, a new course and jump for waypoints during a mission.

image

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 29, 2026

Test firmware build ready — commit 25dd9dd

Download firmware for PR #11462

228 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

@sensei-hacker
Copy link
Copy Markdown
Member

@stronnag and @xznhj8129 have some deeper knowledge of MSP and any potential traps. Do either of you have any comment?

@xznhj8129
Copy link
Copy Markdown
Contributor

Oh this is awesome work you're doing, but we just did add SET_ALT_TARGET and SET_HEAD in 10.x #11230
https://github.com/iNavFlight/inav/tree/maintenance-10.x/docs/development/msp#msp2_inav_set_alt_target
https://github.com/iNavFlight/inav/tree/maintenance-10.x/docs/development/msp#msp_set_head I know this used to do nothing in cruise mode, but i updated it
https://github.com/iNavFlight/inav/pull/11230/changes#diff-e67741f944e959c3f68a81189a5fcd8be50f5e4e567c1fc68f50ac5e86d0a233L1962
Only MSP2_INAV_SET_WP_INDEX be new, that would be handy. I think you missed them because you are targeting 9.x-maintenance.

@danarrib
Copy link
Copy Markdown
Contributor Author

Oh this is awesome work you're doing, but we just did add SET_ALT_TARGET and SET_HEAD in 10.x #11230 https://github.com/iNavFlight/inav/tree/maintenance-10.x/docs/development/msp#msp2_inav_set_alt_target https://github.com/iNavFlight/inav/tree/maintenance-10.x/docs/development/msp#msp_set_head I know this used to do nothing in cruise mode, but i updated it https://github.com/iNavFlight/inav/pull/11230/changes#diff-e67741f944e959c3f68a81189a5fcd8be50f5e4e567c1fc68f50ac5e86d0a233L1962 Only MSP2_INAV_SET_WP_INDEX be new, that would be handy. I think you missed them because you are targeting 9.x-maintenance.

Ok, that's nice.

Yeah, I'm targeting 9.x-maintenance because none of the changes are breaking changes, so they could slip into a minor or patch release just fine.

What do you suggest me to do?

Should I change this PR to just add the MSP2_INAV_SET_WP_INDEX, and remove the other 2 commands (and then we wait for version 10 to use the feature)?

@xznhj8129
Copy link
Copy Markdown
Contributor

Ah i'm not sure myself, i struggle sometimes to figure out what's breaking or not, i targeted 10 to stay safe; maybe @sensei-hacker could enlighten us? I wonder if we could patch in the 10x part for next update

@danarrib
Copy link
Copy Markdown
Contributor Author

danarrib commented Mar 30, 2026

Biggest issue recycling the MSP_SET_HEAD command for the cruise mode COURSE, is that the SET HEAD is not exactly used to make the aircraft GO to a certain heading direction, but instead to LOOK to that direction. This is specially useful for multirotor aircraft, that can move in any direction (regardless of where it is looking at).

You guys are the experts of course, but my 2 cents on this topic is: We should have a separated command for setting the course direction.

What I think we should so is:

  • I change my PR to remove the MSP2_INAV_SET_ALT_TARGET command, as your code already pushed to the maintenance-10.x branch already covers everything (and it's actually better than my implementation).
  • We keep both MSP2_INAV_SET_CRUISE_HEADING and MSP2_INAV_SET_WP_INDEX from my PR.

What do you guys think?

@stronnag
Copy link
Copy Markdown
Collaborator

Biggest issue recycling the MSP_SET_HEAD command for the cruise mode heading, is that the SET HEAD is not exactly used to make the aircraft GO to a certain heading direction, but instead to LOOK to that direction. This is specially useful for multirotor aircraft, that can move in any direction (regardless of where it is looking at).

You guys are the experts of course, but my 2 cents on this topic is: We should have a separated command for setting the course direction.

What I think we should so is:

  • I change my PR to remove the MSP2_INAV_SET_ALT_TARGET command, as your code already pushed to the maintenance-10.x branch already covers everything (and it's actually better than my implementation).
  • We keep both MSP2_INAV_SET_CRUISE_HEADING and MSP2_INAV_SET_WP_INDEX from my PR.

What do you guys think?

I would prefer we keep the MSP_SET_HEAD and MSP2_INAV_SET_CRUISE_HEADING items separate, as @danarrib 's PR.

…lementation

The set-altitude functionality is already covered by a more mature existing
implementation in INAV. Remove the MSP2_INAV_SET_ALT_TARGET command added in
the previous commit, keeping only MSP2_INAV_SET_WP_INDEX (0x2221) and
MSP2_INAV_SET_CRUISE_HEADING (0x2223).

Removes: define in msp_protocol_v2_inav.h, navSetDesiredAltitude() in
navigation.c/.h, the MSP handler in fc_msp.c, and the docs section.
@danarrib danarrib changed the title Add three new MSP2 commands for GCS-initiated flight control Add two new MSP2 commands for GCS-initiated flight control Mar 30, 2026
@xznhj8129
Copy link
Copy Markdown
Contributor

I agree now that i know the intent of SET_HEAD, i think we should revert the changes i made to SET_HEAD, so that an old message behaves as it always did. AFAIK cruise mode is the only nav mode where setting a heading would be relevant? All the others are GPS based.

And to be clear, this is meant to set the aircraft's ground course, even if the compass heading is different due to ie wind?

@danarrib
Copy link
Copy Markdown
Contributor Author

danarrib commented Apr 1, 2026

And to be clear, this is meant to set the aircraft's ground course, even if the compass heading is different due to ie wind?

Yes, it's ground course, regardless of heading.

@sensei-hacker sensei-hacker merged commit f0f41be into iNavFlight:maintenance-9.x Apr 9, 2026
24 checks passed
@sensei-hacker
Copy link
Copy Markdown
Member

sensei-hacker commented Apr 9, 2026

Ah i'm not sure myself, i struggle sometimes to figure out what's breaking or not, i targeted 10 to stay safe; maybe @sensei-hacker could enlighten us?

Yeah it can be tricky. The overall way I think about it is:
Consider a user has a certain version of a ground control station. And a certain version of Configurator. And the other things that interact with INAV -- maybe a Lua script.

Version 9.x of INAV should be compatible with version X of the GCS, of Configurator, and of the Lua script.
That is, if you write a tool that works with INAV 9.0, it should still work with 9.1, 9.2.1, etc.
The Speedybee app is another example - their app for INAV 9 should work for all INAV 9 -- we shouldn't break it.

Also, we tell people that when they upgrade to a new major version, they should do full erase because the binary representation of the settings in the EEPROM may have changed. So anything that changes the settings (PG templates) should probably be a major version.

Stronnag has been involved for a lot more versions than I have and may have a more experienced viewpoint.

@xznhj8129
Copy link
Copy Markdown
Contributor

Um, problem, i just realized that this commit adds the commands, and manually adjusts the documentation; not the actual msp_messages.json spec. That means the documentation is gone on the next msp/gen_docs.sh and the messages are never actually registered in the spec

@sensei-hacker
Copy link
Copy Markdown
Member

Um, problem, i just realized that this commit adds the commands, and manually adjusts the documentation; not the actual msp_messages.json spec. That means the documentation is gone on the next msp/gen_docs.sh and the messages are never actually registered in the spec

Whatever you just said, I'm sure I or someone else will make the same mistake in the future. Is the proper way of doing this clearly documented somewhere? I may make a GitHub action that check for it.

@xznhj8129
Copy link
Copy Markdown
Contributor

Um, problem, i just realized that this commit adds the commands, and manually adjusts the documentation; not the actual msp_messages.json spec. That means the documentation is gone on the next msp/gen_docs.sh and the messages are never actually registered in the spec

Whatever you just said, I'm sure I or someone else will make the same mistake in the future. Is the proper way of doing this clearly documented somewhere? I may make a GitHub action that check for it.

docs/development/msp/README.md does say "This page is auto-generated from the master INAV MSP definitions file"; but there's actually no explicit "you MUST define new MSP messages here first and run gen_docs.sh to generate the new readme** as there is for settings.yaml; that was on the "i'll get to it" pile, the next step was to get rid of current checksum/rev file nag which i've removed with msp_versioning; it was complicating merges. gen_docs.sh should be run on every code merge to ensure the documentation is up to date (which includes enums); otherwise they go stale and the next guy who remembers to run it is looking at a huge git diff wondering where all those changes come from; the way it's currently organized is very unoptimal and is just where i left them, not where they might belong as fitting part of the build check system...

I was making a PR to add MSP2_INAV_GET_LINK_STATS (#10522), so i'll include these two missing messages at the same time

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.

4 participants