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

Copter : Command Go To Rally point : implementation #8624

Closed
wants to merge 2 commits into from
Closed

Copter : Command Go To Rally point : implementation #8624

wants to merge 2 commits into from

Conversation

Kiwa21
Copy link

@Kiwa21 Kiwa21 commented Jun 11, 2018

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)

@Kiwa21 Kiwa21 changed the title Command Go To Rally point : implementation Copter : Command Go To Rally point : implementation Jun 11, 2018
@khancyr khancyr added the Copter label Jun 11, 2018
@khancyr khancyr requested a review from rmackay9 June 11, 2018 12:48
#if AC_RALLY == ENABLED
case MAV_CMD_NAV_RALLY_POINT: //not including home

if(!is_zero(packet.param1)) { // Go to a specific rally ID
Copy link
Contributor

Choose a reason for hiding this comment

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

if (

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

} else if (

Copy link
Author

Choose a reason for hiding this comment

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

done

@@ -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(){
Copy link
Contributor

Choose a reason for hiding this comment

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

) { or
)
{

Copy link
Contributor

Choose a reason for hiding this comment

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

const

@@ -161,3 +172,40 @@ Location AP_Rally::calc_best_rally_or_home_location(const Location &current_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 &current_loc, float rtl_home_alt) const
Copy link
Contributor

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 ?

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

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 ?

@Kiwa21
Copy link
Author

Kiwa21 commented Jun 11, 2018

Reformatted commits and coding rules.

}

bool AP_Rally::increment_rally_point_total_count() {
return AP_Param::set_by_name("RALLY_TOTAL", _rally_point_total_count + 1);
Copy link
Member

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.

Copy link
Author

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);

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

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.

@@ -161,3 +172,40 @@ Location AP_Rally::calc_best_rally_or_home_location(const Location &current_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 &current_loc, float rtl_home_alt) const
Copy link
Member

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.

}

//return location of a specific id rally point
Location AP_Rally::go_to_rally_id_location(const Location &current_loc, uint8_t rally_id) const
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

Agree, the const Location &current_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

Copy link
Member

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.

Copy link
Author

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?).

// 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;
Copy link
Member

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.

Copy link
Author

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)
Copy link
Member

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

Copy link
Author

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

Copy link
Member

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
Copy link
Member

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.

Copy link
Author

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

Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

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 ?

Copy link
Member

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.

Copy link
Contributor

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?

copter.rally.go_to_rally_id = new_rally_id;
}

copter.set_mode(RTL, MODE_REASON_MISSION_END);
Copy link
Member

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.

Copy link
Author

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

Copy link
Member

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

Copy link
Author

@Kiwa21 Kiwa21 Jun 11, 2018

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.

Copy link
Member

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.

Copy link
Author

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!

Copy link
Member

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.

@peterbarker
Copy link
Contributor

Shouldn't this mavlink command be relevant on the other vehicle types, too?

@Kiwa21
Copy link
Author

Kiwa21 commented Jun 12, 2018

I've updated the commit with severals review.
@peterbarker I guess it could be directly used for other vehicles yes. I can do the others when this one is over.

@xcoder123
Copy link

will this change be also available for the ArduPlane? If so when can we expect it to be merged into the master?

@ArduPilot ArduPilot deleted a comment from paytufo Aug 20, 2018
@peterbarker
Copy link
Contributor

@Kiwa21 are you still interested in pursuing this PR?

@khancyr
Copy link
Contributor

khancyr commented Jul 14, 2021

This is heavily conflicting and need a full rework;
feel free to join a devcall, if you want to discuss this. thanks anyway

@khancyr khancyr closed this Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants