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

Add Goto Location Action #485

Merged
merged 8 commits into from
Aug 18, 2018
Merged

Add Goto Location Action #485

merged 8 commits into from
Aug 18, 2018

Conversation

mzahana
Copy link
Contributor

@mzahana mzahana commented Aug 8, 2018

This PR adds goto_location() action which allows to send the vehicle to a specific WGS84 global position. It uses MAV_DO_REPOSITION

* @brief Send command to reposition the vehicle to a specific WGS84 global position
*
* This sends the vehicle to a specified lattitude/longitude/altitude coordinates.
* @param latitude deg * 1E7
Copy link
Member

Choose a reason for hiding this comment

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

Why not pass the latitude and longitude as normal coordinates and then multiply by 1E7 on the ActionResult code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possible. I guess that requires to use double instead of float and then multiply by 1E7, then cast to float when passing to command.params, no?

Copy link
Member

Choose a reason for hiding this comment

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

Use 1e7

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lat/long can be entered in degrees now.

@hamishwillee
Copy link
Collaborator

How does this differ from the intention of offboard control? ie should this be the unimplemented position setting part of offboard control?

@mzahana
Copy link
Contributor Author

mzahana commented Aug 8, 2018

@hamishwillee Offboard does not have GPS setpoints. It's in local frame. So, conversions need to happen. Also, the flight controller already provides this functionality without much coding.

TSC21
TSC21 previously requested changes Aug 8, 2018
{
float lat1e7 = (float) (latitude * 1E7);
Copy link
Member

Choose a reason for hiding this comment

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

you don't need this. You can use a floating point literal:

ActionResult ActionImpl::goto_location(float latitude, float longitude, float altitude)
{
        ....
        command.params.param5 = latitude * 1E7F;
        command.params.param6 =  longitude * 1E7F;
        ....
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if I keep latitude and longitude as float, I get warnings when I enter big values like 48.1234567 for loosing precision.

@mhkabir
Copy link
Member

mhkabir commented Aug 9, 2018

It would be more correct to use double precision for lat/lon.

@julianoes
Copy link
Collaborator

@mzahana cool, thanks for the contribution! I think that's a handy feature and while it might be overlapping with offboard it's still useful.

@@ -32,6 +32,11 @@ ActionResult Action::land() const
return _impl->land();
}

ActionResult Action::goto_location(double latitude, double longitude, double altitude)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please always add units if possible. Here I suggest to use latitude_deg, and relative_altitude_m.

float lat1e7 = (float) (latitude * 1E7);
float long1e7 = (float) (longitude * 1E7);

MAVLinkCommands::CommandLong command{};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this was already said but I this should be a CommandInt for better accuracy.

* This sends the vehicle to a specified lattitude/longitude/altitude coordinates.
* @param latitude in degrees
* @param longitude in degrees
* @param altitude Altitude AMSL (meters)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, so this is absolute altitude? Are you sure about that?

Copy link
Member

Choose a reason for hiding this comment

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

@julianoes seems like it is always AMSL: PX4/PX4-Autopilot#8502

Copy link
Member

Choose a reason for hiding this comment

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

@TSC21
Copy link
Member

TSC21 commented Aug 9, 2018

It would be more correct to use double precision for lat/lon.

@mhkabir that's only possible in COMMAND_INT. This is using COMMAND_LONG. Though, as @julianoes, the COMMAND_INT can be used for this case.

@mzahana
Copy link
Contributor Author

mzahana commented Aug 9, 2018

@julianoes I am not sure if PX4 uses COMMAND_INT to parse MAV_CMD_DO_REPOSITION.

So, in summary, what is required to merger this PR?

@mzahana
Copy link
Contributor Author

mzahana commented Aug 9, 2018

So, this is what I have so far.

ActionResult ActionImpl::goto_location(double latitude_deg, double longitude_deg, float altitude_amsl_m)
{

    MAVLinkCommands::CommandLong command{};

    command.command = MAV_CMD_DO_REPOSITION;
    command.target_component_id = _parent->get_autopilot_id();
    command.params.param1 = -1; /* default speed */
    command.params.param2 = MAV_DO_REPOSITION_FLAGS_CHANGE_MODE;
    // command.param4 = NaN /* Yaw Unchanged */
    command.params.param5 = (float)latitude_deg * 1E7F;
    command.params.param6 = (float)longitude_deg * 1E7F;
    command.params.param7 = altitude_amsl_m;

    return action_result_from_command_result(_parent->send_command(command));
}

Let me know your feedback.

@julianoes
Copy link
Collaborator

ActionResult ActionImpl::goto_location(double latitude_deg, double longitude_deg, float altitude_amsl_m)
{

MAVLinkCommands::CommandLong command{};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest you change it to CommandInt and try it in SITL.

@mzahana
Copy link
Contributor Author

mzahana commented Aug 14, 2018

@julianoes CommandInt is used and tested in SITL. Works fine.

Copy link
Collaborator

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

Just a small change and a question. Thanks for the changes.

@@ -32,6 +32,11 @@ ActionResult Action::land() const
return _impl->land();
}

ActionResult Action::goto_location(double latitude_deg, double longitude_deg, float altitude_amsl_m, float yaw_rad)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please expose yaw in degrees and convert it to rad internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

* This sends the vehicle to a specified lattitude/longitude/altitude coordinates.
* @param latitude_deg Latitude in degrees
* @param longitude_deg Longitude in degrees
* @param altitude_amsl_m Altitude AMSL in meters
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure that this command is in absolute altitude and not relative? Could it be that we need to specify the frame when sending the command int?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! It's weird though as the frame component in CommandInt is defined as MAV_FRAME_GLOBAL_RELATIVE_ALT. According to the description in here, the altitude should be relative to home, not MSL!

When I try in the SITL, I had to command 500m to get 10m above home!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, so the implementation in PX4 is wrong? Could you check that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My guess is yes. It needs to be fixed on the PX4 side. I just have not figured out yet where it is exactly consumed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right, I filed an issue: PX4/PX4-Autopilot#10246.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mzahana oh yes that should be _INT, thanks for the note!

{

MAVLinkCommands::CommandInt command{};

command.command = MAV_CMD_DO_REPOSITION;
command.target_component_id = _parent->get_autopilot_id();
command.params.param4 = yaw_rad;
command.params.param4 = to_rad_from_deg(yaw_deg);
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@julianoes
Copy link
Collaborator

@mzahana would be good if you could rebase this on develop and force push it.

@julianoes
Copy link
Collaborator

@mzahana I hope you don't mind that I rebased and force pushed your branch. I also fixed the style issues and added an integration test.

@julianoes
Copy link
Collaborator

julianoes commented Aug 17, 2018

@TSC21 are you ok if we merge this for now, and then follow up with the firmware issues?

@julianoes julianoes dismissed TSC21’s stale review August 18, 2018 11:17

Dismissing your review since the concerns have been addressed.

@julianoes julianoes merged commit 4029526 into mavlink:develop Aug 18, 2018
@julianoes
Copy link
Collaborator

Thanks a lot @mzahana!

@mzahana
Copy link
Contributor Author

mzahana commented Aug 18, 2018

@julianoes Thanks for merging. Sorry I didn't have time to make the last changes rapidly.

* @brief Send command to reposition the vehicle to a specific WGS84 global position
*
* This sends the vehicle to a specified lattitude/longitude/altitude coordinates.
* @param latitude_deg Latitude in degrees
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI, I wouldn't necessarily change this now, but one of the benefits of naming with units is that you don't necessarily have to spell everything out in the description. So normally I'd just have Latitude. (and yes, arguably you don't even need that, but good to have something because it shows that you have thought about docs).

rt-2pm2 pushed a commit to rt-2pm2/DronecodeSDK that referenced this pull request Nov 27, 2018
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