Skip to content

examples: add gimbal_manager example#2921

Open
julianoes wants to merge 6 commits into
mainfrom
pr-gimbal-manager
Open

examples: add gimbal_manager example#2921
julianoes wants to merge 6 commits into
mainfrom
pr-gimbal-manager

Conversation

@julianoes

Copy link
Copy Markdown
Collaborator

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.

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.
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.

1 participant