examples: add gimbal_manager example#2921
Open
julianoes wants to merge 6 commits into
Open
Conversation
Implement a MAVLink gimbal manager (gimbal protocol v2) with an internally simulated gimbal device, based on MavlinkDirectServer and nlohmann::json. It identifies as a MAVLink gimbal with built-in gimbal manager (sysid 1/compid 154), answers MAV_CMD_REQUEST_MESSAGE for GIMBAL_MANAGER_INFORMATION and GIMBAL_DEVICE_INFORMATION, streams GIMBAL_MANAGER_STATUS and GIMBAL_DEVICE_ATTITUDE_STATUS, accepts setpoints via GIMBAL_MANAGER_SET_ATTITUDE, GIMBAL_MANAGER_SET_PITCHYAW and MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW, and tracks control ownership via MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE. The example is skipped if nlohmann_json is not found, and nlohmann-json3-dev is added to the Linux CI example dependencies.
Use Quaternion, EulerAngle and the angle conversions from <mavsdk/math_utils.hpp> instead of local helpers, and drop the HAS_PITCH_FOLLOW capability flag: the simulated gimbal always stabilizes pitch, so it should only advertise pitch lock.
Handle MAV_CMD_DO_SET_ROI_LOCATION and MAV_CMD_DO_SET_ROI_NONE and advertise GIMBAL_MANAGER_CAP_FLAGS_CAN_POINT_LOCATION_GLOBAL. The gimbal manager subscribes to the vehicle's GLOBAL_POSITION_INT and ATTITUDE and computes the pitch and yaw to point at the ROI location using a flat-earth approximation. Manual setpoints cancel an active ROI, and ROI none returns the gimbal to neutral. Note that the ROI altitude is assumed to be AMSL, the frame field of COMMAND_INT is not taken into account.
Convert the ROI altitude to AMSL according to the COMMAND_INT frame field: global frames are taken as is, relative-alt frames are converted using the vehicle's relative_alt from GLOBAL_POSITION_INT, and other frames (e.g. terrain) are denied.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new example implementing a MAVLink gimbal manager (gimbal protocol v2) with an internally simulated gimbal device, based on MavlinkDirectServer and nlohmann::json.
It identifies as a MAVLink gimbal with built-in gimbal manager (sysid 1/compid 154), answers MAV_CMD_REQUEST_MESSAGE for GIMBAL_MANAGER_INFORMATION and GIMBAL_DEVICE_INFORMATION, streams GIMBAL_MANAGER_STATUS (5 Hz) and GIMBAL_DEVICE_ATTITUDE_STATUS (10 Hz), accepts setpoints via GIMBAL_MANAGER_SET_ATTITUDE, GIMBAL_MANAGER_SET_PITCHYAW and MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW (COMMAND_LONG and COMMAND_INT), and tracks control ownership via MAV_CMD_DO_GIMBAL_MANAGER_CONFIGURE including the -1/-2/-3 special values.
The example is skipped if nlohmann_json is not found (e.g. on the Windows examples build), and nlohmann-json3-dev is added to the Linux CI example dependencies.
Tested end-to-end against the Gimbal client plugin: discovery, take/release control, angle setpoints (slewing at the rate limit), and rate setpoints all work. The intended next step (separately) is to use this with PX4 SITL with PX4's own gimbal manager disabled.
Note: this branch includes the jsoncpp→nlohmann/json switch commit, which the example depends on.