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
Copter : Command Go To Rally point : implementation #8624
Conversation
ArduCopter/GCS_Mavlink.cpp
Outdated
#if AC_RALLY == ENABLED | ||
case MAV_CMD_NAV_RALLY_POINT: //not including home | ||
|
||
if(!is_zero(packet.param1)) { // Go to a specific rally ID |
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 (
ArduCopter/mode_rtl.cpp
Outdated
if(copter.rally.cmd_go_to_rally_id) { | ||
rtl_path.return_target = copter.rally.go_to_rally_id_location(copter.current_loc,copter.rally.go_to_rally_id); | ||
copter.rally.cmd_go_to_rally_id = false; //only use once | ||
}else if(copter.rally.cmd_go_to_rally_only) { |
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.
} else if (
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
libraries/AP_Rally/AP_Rally.cpp
Outdated
@@ -55,6 +55,17 @@ AP_Rally::AP_Rally(AP_AHRS &ahrs) | |||
AP_Param::setup_object_defaults(this, var_info); | |||
} | |||
|
|||
// get a rally point total count from EEPROM | |||
uint8_t AP_Rally::get_rally_point_total_count(){ |
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.
) { or
)
{
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.
const
libraries/AP_Rally/AP_Rally.cpp
Outdated
@@ -161,3 +172,40 @@ Location AP_Rally::calc_best_rally_or_home_location(const Location ¤t_loc, | |||
|
|||
return return_loc; | |||
} | |||
// return best rally location from current position - not including home or km limit | |||
Location AP_Rally::calc_best_rally_location(const Location ¤t_loc, float rtl_home_alt) const |
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.
same calc_best_rally_or_home_location ?
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.
nope, this one exclude home from calc but it still verify its validity (rally point inside fence) otherwise it replace by 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.
If you don't want to include home then changing the methods to use an argument instead of directly using the parameter is better. find_nearest_rally_point
doesn't return false only when including home, there are other parameters in play.
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.
find_nearest_rally_point
returns false when home is nearest than any rally points or when all rally points are further than the _rally_limit_km
What do you mean by changing the methods instead of using the parameter?
Do you want me to change the find_nearest_rally_point
method to have an extra argument for including home or not ?
Reformatted commits and coding rules. |
libraries/AP_Rally/AP_Rally.cpp
Outdated
} | ||
|
||
bool AP_Rally::increment_rally_point_total_count() { | ||
return AP_Param::set_by_name("RALLY_TOTAL", _rally_point_total_count + 1); |
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.
This is a local parameter, there is no reason to be using this costly method. Just setting it like a normal variable works perfectly fine.
In any case, you should instead do a method to add a new rally point that does this 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.
Maybe I'm wrong but if I just increase _rally_point_total_count
, it will not be saved in the EEPROM ?
I'll add a method than does increment and add a new rally point in one go, it's what I was doing in GCS_Mavlink with :
uint8_t new_rally_id = copter.rally.get_rally_point_total_count(); copter.rally.increment_rally_point_total_count(); copter.rally.set_rally_point_with_index(new_rally_id, rally_location);
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 set_and_save_ifchanged()
https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Param/AP_Param.h#L674
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.
@Kiwa21 set_by_name doesn't save it either, which is why I suggested that was enough. As @WickedShell there are methods for setting and saving the parameter value.
libraries/AP_Rally/AP_Rally.cpp
Outdated
@@ -161,3 +172,40 @@ Location AP_Rally::calc_best_rally_or_home_location(const Location ¤t_loc, | |||
|
|||
return return_loc; | |||
} | |||
// return best rally location from current position - not including home or km limit | |||
Location AP_Rally::calc_best_rally_location(const Location ¤t_loc, float rtl_home_alt) const |
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 you don't want to include home then changing the methods to use an argument instead of directly using the parameter is better. find_nearest_rally_point
doesn't return false only when including home, there are other parameters in play.
libraries/AP_Rally/AP_Rally.cpp
Outdated
} | ||
|
||
//return location of a specific id rally point | ||
Location AP_Rally::go_to_rally_id_location(const Location ¤t_loc, uint8_t rally_id) const |
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 don't see any reason for this method, the caller can already get the specific rally point and if doesn't exist it can then choose what to do.
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.
Agree, the const Location ¤t_loc
is too much, it was a bad copy paste from other method. However, I think the rest of the function is fine.
Maybe I can rename to get_rally_location_with_index
to have better consistency with get_rally_point_with_index
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.
What is this needed for? I see no reason to be hard-coding the home behavior when the caller can do the same - if this was going to be repeated in a lot of places then it would make sense but this is going to be used in one place.
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.
Ok, I can do that. I thought it was cleaner to define an alternate method even though it's called once (for now?).
libraries/AP_Rally/AP_Rally.h
Outdated
// cmd_nav_rally parameters | ||
bool cmd_go_to_rally_only = false; | ||
bool cmd_go_to_rally_id = false; | ||
uint8_t go_to_rally_id = 0; |
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.
This is really bad, class variables shouldn't be public.
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.
Ok ! Will make them private and do method to access them
copter.rally.go_to_rally_id = (uint8_t)packet.param2; | ||
} else if (!is_zero(packet.param3)) { // Go to nearest rally from loc except home | ||
copter.rally.cmd_go_to_rally_only = true; | ||
} else if (!is_zero(packet.param4)) { // Go to new rally location (and save it in EEPROM) |
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.
Where are all these param definitions? I don't see them in MAVLink...
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 is nothing defined in MAVLink.. I can add a MAVLINK specific message to ardupilotmega.xml if you prefer but I don't see any sense to wait for MAVLINK to define all the messages before we can use them. When they'll be ready, we can always refractor
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.
Adding things to code before adding them to MAVLink is part of what has led to problems. Things should be discussed in MAVLink first then we can add them to code.
@@ -1062,6 +1062,38 @@ void GCS_MAVLINK_Copter::handleMessage(mavlink_message_t* msg) | |||
break; | |||
#endif | |||
|
|||
#if AC_RALLY == ENABLED | |||
case MAV_CMD_NAV_RALLY_POINT: //not including 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.
MAVLink documentation doesn't mention what this should be used for, but following the history it looks like it was added for the new rally protocol and not exactly to go to a rally point. I think this needs to be clarified in MAVLink first.
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.
Same nothing define.
How long should we wait for Mavlink then...?
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.
Is there any discussion in MAVLink about this?
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.
Nothing more than this mavlink/mavlink#683 from March 2017.
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.
As written in mavlink/mavlink#683 (comment), these new commands were intended to be used in MISSION_ITEM and not in COMMAND_LONG.
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'm happy to change the mavlink message transporting the info if you prefer.
We can define a new message in ardupilotmega.xml with a good definition and I'll rebase on that.
Should it be presented to the next dev call ?
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.
Changing the MAVLink message needs to be discussed in the MAVLink repo. We can add a new MAVLink message, but I don't think that's needed and will only bring more confusion.
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.
Is there some question here someone if looking for me to answer?
ArduCopter/GCS_Mavlink.cpp
Outdated
copter.rally.go_to_rally_id = new_rally_id; | ||
} | ||
|
||
copter.set_mode(RTL, MODE_REASON_MISSION_END); |
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.
This seems strange to me, it looks like Guided would be more appropriate, it's a request to go to a point, not an RTL.
Also, this certainly isn't reason mission end.
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 disagree, it's still a RTL for aborting / ending mission but with a special condition.
I can change to MODE_REASON_MISSION_COMMAND but I don't know where is the actual enum for this
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'm confused, this isn't handled in a mission...
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.
Sorry, I meant MODE_REASON_GCS_COMMAND. (again I don't know the enums, just found these in the ArduRover set_mode reason.. 23532bf ).
Still I think MISSION_END is not too far from the scope.
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.
Sorry, but I'm still confused, you said this is an RTL because it is for aborting/ending a mission, but this isn't handled as a command in a mission, this is handled as command coming from MAVLink, it doesn't matter what mode the vehicle is in.
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.
It's an outdated snippet of code, it was changed in the last update of this commit!
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.
It still does RTL which was my main point. Anyway, up to @rmackay9 to decide.
Shouldn't this mavlink command be relevant on the other vehicle types, too? |
I've updated the commit with severals review. |
will this change be also available for the ArduPlane? If so when can we expect it to be merged into the master? |
@Kiwa21 are you still interested in pursuing this PR? |
This is heavily conflicting and need a full rework; |
Using a command_long MAV_CMD_NAV_RALLY_POINT (5100) , this allow to send Copter to :
a specific rally point (defined with its ID) :
use param1 = 1
and param2 = rally_id
the closest rally point (excluding home) :
use param3 = 1
a new rally point ( lat/long/alt)
use param4 = 1
param5 = lat ( ex : -35.363785 )
param6 = lng ( ex : 149.165761 )
param7 = alt ( ex : 10 // meters above home)