-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
Conversation
* @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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 1e7
There was a problem hiding this comment.
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.
How does this differ from the intention of offboard control? ie should this be the unimplemented position setting part of offboard control? |
@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. |
plugins/action/action_impl.cpp
Outdated
{ | ||
float lat1e7 = (float) (latitude * 1E7); |
There was a problem hiding this comment.
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;
....
}
There was a problem hiding this comment.
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.
It would be more correct to use double precision for lat/lon. |
@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. |
plugins/action/action.cpp
Outdated
@@ -32,6 +32,11 @@ ActionResult Action::land() const | |||
return _impl->land(); | |||
} | |||
|
|||
ActionResult Action::goto_location(double latitude, double longitude, double altitude) |
There was a problem hiding this comment.
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
.
plugins/action/action_impl.cpp
Outdated
float lat1e7 = (float) (latitude * 1E7); | ||
float long1e7 = (float) (longitude * 1E7); | ||
|
||
MAVLinkCommands::CommandLong command{}; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mhkabir that's only possible in |
@julianoes I am not sure if PX4 uses So, in summary, what is required to merger this PR? |
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. |
@mzahana it looks to me like command int should be supported: |
plugins/action/action_impl.cpp
Outdated
ActionResult ActionImpl::goto_location(double latitude_deg, double longitude_deg, float altitude_amsl_m) | ||
{ | ||
|
||
MAVLinkCommands::CommandLong command{}; |
There was a problem hiding this comment.
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.
@julianoes |
There was a problem hiding this 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.
plugins/action/action.cpp
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
plugins/action/action_impl.cpp
Outdated
{ | ||
|
||
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@mzahana would be good if you could rebase this on develop and force push it. |
…e is changed to float;(3) Update functionbrief
@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. |
@TSC21 are you ok if we merge this for now, and then follow up with the firmware issues? |
Dismissing your review since the concerns have been addressed.
Thanks a lot @mzahana! |
@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 |
There was a problem hiding this comment.
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).
Add Goto Location Action
This PR adds
goto_location()
action which allows to send the vehicle to a specific WGS84 global position. It uses MAV_DO_REPOSITION