Skip to content

Conversation

hamishwillee
Copy link
Contributor

@hamishwillee hamishwillee commented Apr 10, 2025

This adds support for MAV_CMD_DO_SET_MODE, which replaces SET_MODE (though I have not removed support for that)

Literally all it does is publish the command, which is all that the SET_MODE message hander does in https://github.com/PX4/PX4-Autopilot/blob/main/src/modules/mavlink/mavlink_receiver.cpp#L920-L946 too (after you factor out conversions).

I have tested this and the mode can be changed. An ACK is received.

@julianoes would appreciate your advice here. The ACK is always accepted, even though it should be denied in some cases.
For example, I tried to trigger the default path here by passing an auto mode with an invalid submode - in this case: mode: 29, custom_mode: 4,custom_sub_mode: 20 (20 is greater than the mode.

When I run logging I can see that this is triggered, and main_ret = TRANSITION_DENIED;

However further down this is tested to set the return value:

			if (main_ret != TRANSITION_DENIED) {
				cmd_result = vehicle_command_ack_s::VEHICLE_CMD_RESULT_ACCEPTED;

			} else {
				cmd_result = vehicle_command_ack_s::VEHICLE_CMD_RESULT_TEMPORARILY_REJECTED;
			}

At this point main_ret has magically changed -1, which is why this is accepted. I can't see it being set - advice?

Upshot, I think my changes are good, but there is something wrong with the existing code.

@hamishwillee hamishwillee marked this pull request as ready for review April 10, 2025 23:48
@hamishwillee hamishwillee requested a review from julianoes April 10, 2025 23:48
@hamishwillee
Copy link
Contributor Author

hamishwillee commented Apr 30, 2025

@julianoes This now passes the formatting tests and build tests.

Would be great if you could help me debug why it isn't returning the right ACK, as per #24704 (comment) (specifically, the code detects that a mode can't be sent, and then ACKs anyway).

@hamishwillee hamishwillee force-pushed the pr_mav_cmd_set_mode branch from 5d1ed5f to 6681636 Compare May 14, 2025 05:32
@dakejahl
Copy link
Contributor

bump, what is the impetus? Should we merge?

@hamishwillee hamishwillee force-pushed the pr_mav_cmd_set_mode branch from 6681636 to 39f47b4 Compare July 23, 2025 06:58
@hamishwillee
Copy link
Contributor Author

The blocker is that it returns the wrong ACK in the pre-existing checker code #24704 (comment)

I was hoping for debug help from @julianoes to get this in since I can't see how it can be being set.

I'll have another look though.

@julianoes
Copy link
Contributor

How do I reproduce the problem?

@hamishwillee hamishwillee force-pushed the pr_mav_cmd_set_mode branch from 39f47b4 to 8a73f79 Compare July 27, 2025 21:29
@hamishwillee
Copy link
Contributor Author

@julianoes Actually this does work. I was confused. I can set modes quite happy. It will return accepted for modes you might not expect, but I'm pretty sure that's because the base modes are valid.

@julianoes julianoes merged commit bae1b25 into main Jul 28, 2025
70 checks passed
@julianoes julianoes deleted the pr_mav_cmd_set_mode branch July 28, 2025 00:50
@hamishwillee
Copy link
Contributor Author

Do you think we might get this in v1.16 @julianoes - or is that really heading towards stable?

@julianoes
Copy link
Contributor

Do you think we might get this in v1.16 @julianoes - or is that really heading towards stable?

I wouldn't know. If this is tested and low risk, then just make a backport pull request and tag me.

@hamishwillee
Copy link
Contributor Author

Thanks! Done #25334

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.

3 participants