AP_SmartRTL: peek_point method peeks at next point

includes peek point takes semaphore
This commit is contained in:
Randy Mackay 2020-01-08 20:18:20 +09:00
parent 64ae08a925
commit 193799346c
2 changed files with 32 additions and 0 deletions

View File

@ -170,6 +170,33 @@ bool AP_SmartRTL::pop_point(Vector3f& point)
return true; return true;
} }
// peek at next point on the path without removing it form the path. Returns true on success
bool AP_SmartRTL::peek_point(Vector3f& point)
{
// check we are active
if (!_active) {
return false;
}
// get semaphore
if (!_path_sem.take_nonblocking()) {
log_action(SRTL_PEEK_FAILED_NO_SEMAPHORE);
return false;
}
// check we have another point
if (_path_points_count == 0) {
_path_sem.give();
return false;
}
// return last point
point = _path[_path_points_count-1];
_path_sem.give();
return true;
}
// clear return path and set home location. This should be called as part of the arming procedure // clear return path and set home location. This should be called as part of the arming procedure
void AP_SmartRTL::set_home(bool position_ok) void AP_SmartRTL::set_home(bool position_ok)
{ {

View File

@ -43,6 +43,10 @@ public:
// get next point on the path to home, returns true on success // get next point on the path to home, returns true on success
bool pop_point(Vector3f& point); bool pop_point(Vector3f& point);
// peek at next point on the path without removing it form the path. Returns true on success
// this may fail if the IO thread has taken the path semaphore
bool peek_point(Vector3f& point);
// clear return path and set return location if position_ok is true. This should be called as part of the arming procedure // clear return path and set return location if position_ok is true. This should be called as part of the arming procedure
// if position_ok is false, SmartRTL will not be available. // if position_ok is false, SmartRTL will not be available.
// example sketches use the method that allows providing vehicle position directly // example sketches use the method that allows providing vehicle position directly
@ -90,6 +94,7 @@ private:
SRTL_ADD_FAILED_NO_SEMAPHORE, SRTL_ADD_FAILED_NO_SEMAPHORE,
SRTL_ADD_FAILED_PATH_FULL, SRTL_ADD_FAILED_PATH_FULL,
SRTL_POP_FAILED_NO_SEMAPHORE, SRTL_POP_FAILED_NO_SEMAPHORE,
SRTL_PEEK_FAILED_NO_SEMAPHORE,
SRTL_DEACTIVATED_INIT_FAILED, SRTL_DEACTIVATED_INIT_FAILED,
SRTL_DEACTIVATED_BAD_POSITION, SRTL_DEACTIVATED_BAD_POSITION,
SRTL_DEACTIVATED_BAD_POSITION_TIMEOUT, SRTL_DEACTIVATED_BAD_POSITION_TIMEOUT,