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

AP_Mission: do not use float functions on integers #27788

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

peterbarker
Copy link
Contributor

pitch is int8_t, yaw is int16_t

Completely untested. Well, CI will make sure it compiles.

Copy link
Member

@IamPete1 IamPete1 left a comment

Choose a reason for hiding this comment

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

This must be correct. But I do wonder if this means were missing the NaN check on the command write. The incomming MAVLink could be NaN here:

case MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW:
cmd.content.gimbal_manager_pitchyaw.pitch_angle_deg = packet.param1;
cmd.content.gimbal_manager_pitchyaw.yaw_angle_deg = packet.param2;
cmd.content.gimbal_manager_pitchyaw.pitch_rate_degs = packet.param3;
cmd.content.gimbal_manager_pitchyaw.yaw_rate_degs = packet.param4;
cmd.content.gimbal_manager_pitchyaw.flags = packet.x;
cmd.content.gimbal_manager_pitchyaw.gimbal_id = packet.z;
break;

Presumably if NaN the intended behavior would be that it is not used. So we could set to a out of range value so it is ignored via the abs. I guess we would also have to return a NaN in the MAVLink read....

edit: It looks like NaNs are not in the spec, so we might be OK. https://mavlink.io/en/messages/common.html#MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW

@peterbarker
Copy link
Contributor Author

This is probably the wrong way to fix this. We should probably add a uint8_t field_invalid field to struct PACKED gimbal_manager_pitchyaw_Command.

We have the same problem with the handle-rate-commands block below the one I've modified here.

@rmackay9
Copy link
Contributor

I'm pretty sure that the caller is meant to set the unused fields to NaN

@@ -330,8 +330,8 @@ bool AP_Mission::start_command_do_gimbal_manager_pitchyaw(const AP_Mission::Miss
}

// handle angle target
const bool pitch_angle_valid = !isnan(cmd.content.gimbal_manager_pitchyaw.pitch_angle_deg) && (fabsF(cmd.content.gimbal_manager_pitchyaw.pitch_angle_deg) <= 90);
const bool yaw_angle_valid = !isnan(cmd.content.gimbal_manager_pitchyaw.yaw_angle_deg) && (fabsF(cmd.content.gimbal_manager_pitchyaw.yaw_angle_deg) <= 360);
const bool pitch_angle_valid = abs(cmd.content.gimbal_manager_pitchyaw.pitch_angle_deg) <= 90;
Copy link
Contributor

Choose a reason for hiding this comment

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

a simple change would be to use -128 as a magic value meaning invalid for int8 rates, and set to -128 for NaN in the mavlink msg. If someone asks for -128 then instead set -127

@nexton-winjeel
Copy link
Contributor

nexton-winjeel commented Aug 14, 2024

@IamPete1:

edit: It looks like NaNs are not in the spec, so we might be OK.

It's in the message description, not the field descriptions.

MAV_CMD_DO_GIMBAL_MANAGER_PITCHYAW (1000)

Set gimbal manager pitch/yaw setpoints (low rate command). It is possible to set combinations of the values below. E.g. an angle as well as a desired angular rate can be used to get to this angle at a certain angular rate, or an angular rate only will result in continuous turning. NaN is to be used to signal unset. Note: only the gimbal manager will react to this command - it will be ignored by a gimbal device. Use GIMBAL_MANAGER_SET_PITCHYAW if you need to stream pitch/yaw setpoints at higher rate.

@peterbarker
Copy link
Contributor Author

We currently bounce NaN values in mission upload. The Mount backend doesn't cope if either value is NaN.

I've created a branch which preserves NaN values in storage using INT8_MIN and INT16_MIN, but I reckon that's probably just a waste of flash space at this point.

@tridge tridge merged commit 7d426f4 into ArduPilot:master Nov 12, 2024
93 checks passed
@peterbarker peterbarker deleted the pr/mount-type-fix branch November 12, 2024 01:05
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.

6 participants