Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Stop gimbal from spinning when an angular velocity setpoint stream times out #23825

Merged
merged 3 commits into from
Oct 30, 2024

Conversation

MaEtUgR
Copy link
Member

@MaEtUgR MaEtUgR commented Oct 17, 2024

Solved Problem

When an angular velocity setpoint (gimbal_manager_set_manual_control) stops streaming while still commanding non-zero velocity, the gimbal continues turning indefinitely.

Context:
I found this when working with a gimbal that can be steered by a lever but also a "level out" button it's crucial to not constantly send the lever-based angular velocity setpoint (gimbal_manager_set_manual_control) because that overrides any button-based attitude setpoint (gimbal_manager_set_attitude) immediately again. Solution: only send angular velocity setpoints when the lever is actually deflected and stop sending them when they are zero. But what happens if you lose connection?

Solution

  1. Little refactor (optional)
  2. Save the timestamp of the last received setpoint for every single input case.
  3. Implement a timeout to stop the gimbal if the last non-zero angular velocity setpoint was too long ago

Changelog Entry

Fix: Stop gimbal from spinning when an angular velocity setpoint stream times out

Alternatives

@julianoes I'm eager to find out if you have any better idea or implementation architecture in mind to solve this problem.

Test coverage

I tested using MAVLink gimbal V2 as in- and output. I mapped a lever to gimbal pitch-rate and shut the input MAVLink connection while the lever was deflected and gimbal moving. Before the change it would continue spinning indefinitely, with my pr there is no update anymore for 2 seconds and then there is one single update that commands the gimbal to 0 pitch-rate and it stops. Note: When I tried NAN that caused the gimbal to reset its orientation which I consider undesired e.g. during connection dropouts.

@MaEtUgR MaEtUgR requested a review from julianoes October 17, 2024 16:33
@MaEtUgR MaEtUgR self-assigned this Oct 17, 2024
@julianoes
Copy link
Contributor

julianoes commented Oct 21, 2024

Thanks @MaEtUgR. I'll review this asap with fresh eyes.

FYI, some other open loop on gimbals that I ought to close:

Copy link
Contributor

@julianoes julianoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments, otherwise it makes sense.

src/modules/gimbal/output.cpp Show resolved Hide resolved
src/modules/gimbal/output.cpp Outdated Show resolved Hide resolved
To enable implementing a timeout when there's no new setpoint coming in.
The gimbal would otherwise continue to spin with whatever velocity was commanded
before the input connection was lost.
@MaEtUgR MaEtUgR force-pushed the maetugr/gimbal-timeout branch from f8a1fc4 to cb7a83f Compare October 29, 2024 15:15
@MaEtUgR
Copy link
Member Author

MaEtUgR commented Oct 29, 2024

I rebased on main and applied the suggestion #23825 (comment)

Copy link
Contributor

@julianoes julianoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on top of #23476, works for me, thanks!

@julianoes julianoes merged commit 219c9d6 into main Oct 30, 2024
55 of 57 checks passed
@julianoes julianoes deleted the maetugr/gimbal-timeout branch October 30, 2024 02:12
@DronecodeBot
Copy link

This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:

https://discuss.px4.io/t/px4-sync-q-a-oct-30-2024/42184/1

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