Skip to content

Conversation

@deepak61296
Copy link

Handle param1 (gimbal device id) for DO_SET_ROI_LOCATION and DO_SET_ROI_NONE immediate commands. Previously these commands always targeted the primary gimbal regardless of the device id.

@peterbarker peterbarker force-pushed the fix-roi-gimbal-device-id branch from daad512 to b5a5f90 Compare December 17, 2025 21:55
Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

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

This should be at least two commits.

One which moves the code into AP_Mount and then one which adds the functionality.

And I do mean move.

And I'm very much not impressed with the population of the Location object in the mount library when you discovered that location_from_command_t wasn't available.

// 2nd gimbal, etc
const uint8_t gimbal_device_id = packet.param1;

Location target_loc;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use location_from_command_t here.

You can't assume the pass-in location's altitude is relative-to-home.

Copy link
Author

Choose a reason for hiding this comment

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

Reworked as two commits:

  1. separate handlers for DO_SET_ROI_LOCATION/NONE using location_from_command_t
  2. add gimbal device id support

tested in SITL with MNT1_TYPE=1.

@deepak61296 deepak61296 force-pushed the fix-roi-gimbal-device-id branch from b5a5f90 to 7df7126 Compare December 19, 2025 05:40
Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

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

This is much better than the first one, thanks!

I think you're breaking ArduCopter's "yaw the vehicle if the mount can't yaw" behaviour here, and at the very least not supporting that in your new functions here.

That's the reason that MAV_CMD_DO_SET_ROI_LOCATION and NONE don't require mount to be enabled....

// x : lat
// y : lon
// z : alt
const uint8_t gimbal_device_id = packet.param1;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit tricky as NaN can be passed in these packets. If a GCS does then SITL will blow up here with a numeric exception of some type or another.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback!

fixed both issues:

  1. vehicle yaw behavior preserved - the new handlers now fall back to handle_command_do_set_roi(Location) when gimbal_device_id is 0/unspecified, so ROI commands work even without HAL_MOUNT_ENABLED (vehicle can still yaw toward ROI).

  2. NaN protection added** - Added !isnan(packet.param1) check before using param1 as gimbal_device_id to prevent SITL crashes.

the gimbal-specific path (mount->set_roi_target()) is only taken when param1 >= 1 AND is not NaN.

Tested in SITL with and without MNT1_TYPE enabled - all commands return ACCEPTED.

deepak61296 added 2 commits December 19, 2025 18:04
Split DO_SET_ROI_LOCATION and DO_SET_ROI_NONE handling from
DO_SET_ROI. These commands have different param1 semantics:
- DO_SET_ROI: param1 is ROI mode
- DO_SET_ROI_LOCATION/NONE: param1 is gimbal device id

This commit adds dedicated handlers but still falls back to the
existing handle_command_do_set_roi(Location) for vehicle handling.
Gimbal device id support will be added separately.
Handle param1 (gimbal device id) for DO_SET_ROI_LOCATION and
DO_SET_ROI_NONE commands when a specific gimbal is targeted
(gimbal_device_id >= 1).

When param1 is 0, NaN, or negative, fall back to vehicle ROI
handling via the existing virtual handle_command_do_set_roi(Location)
function. This preserves ArduCopter's ability to yaw the vehicle
toward an ROI even when no gimbal is present.

The NaN check prevents crashes in SITL when a GCS sends NaN as
the gimbal device id parameter.
@deepak61296 deepak61296 force-pushed the fix-roi-gimbal-device-id branch from 7df7126 to 311e56e Compare December 19, 2025 16:19
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.

2 participants