2012-04-30 04:17:14 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2015-05-13 00:16:45 -03:00
|
|
|
#include "Rover.h"
|
|
|
|
|
2012-04-30 04:17:14 -03:00
|
|
|
/* Functions in this file:
|
2014-03-10 05:45:26 -03:00
|
|
|
void set_next_WP(const AP_Mission::Mission_Command& cmd)
|
2012-04-30 04:17:14 -03:00
|
|
|
void set_guided_WP(void)
|
|
|
|
void init_home()
|
2012-05-14 12:47:08 -03:00
|
|
|
void restart_nav()
|
2012-04-30 04:17:14 -03:00
|
|
|
************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2014-03-17 04:44:25 -03:00
|
|
|
* set_next_WP - sets the target location the vehicle should fly to
|
|
|
|
*/
|
2015-05-12 02:03:23 -03:00
|
|
|
void Rover::set_next_WP(const struct Location& loc)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
|
|
|
// copy the current WP into the OldWP slot
|
|
|
|
// ---------------------------------------
|
|
|
|
prev_WP = next_WP;
|
|
|
|
|
|
|
|
// Load the next_WP slot
|
|
|
|
// ---------------------
|
2014-03-17 04:44:25 -03:00
|
|
|
next_WP = loc;
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2012-11-18 01:07:50 -04:00
|
|
|
// are we already past the waypoint? This happens when we jump
|
|
|
|
// waypoints, and it can cause us to skip a waypoint. If we are
|
|
|
|
// past the waypoint when we start on a leg, then use the current
|
|
|
|
// location as the previous waypoint, to prevent immediately
|
|
|
|
// considering the waypoint complete
|
2014-03-17 04:44:25 -03:00
|
|
|
if (location_passed_point(current_loc, prev_WP, next_WP)) {
|
2015-11-18 14:53:14 -04:00
|
|
|
gcs_send_text(MAV_SEVERITY_NOTICE, "Resetting previous WP");
|
2014-03-17 04:44:25 -03:00
|
|
|
prev_WP = current_loc;
|
2012-11-18 01:07:50 -04:00
|
|
|
}
|
|
|
|
|
2012-04-30 04:17:14 -03:00
|
|
|
// this is handy for the groundstation
|
2014-03-17 04:44:25 -03:00
|
|
|
wp_totalDistance = get_distance(current_loc, next_WP);
|
2012-04-30 04:17:14 -03:00
|
|
|
wp_distance = wp_totalDistance;
|
|
|
|
}
|
|
|
|
|
2015-05-12 02:03:23 -03:00
|
|
|
void Rover::set_guided_WP(void)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
|
|
|
// copy the current location into the OldWP slot
|
|
|
|
// ---------------------------------------
|
2014-03-17 04:44:25 -03:00
|
|
|
prev_WP = current_loc;
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
// Load the next_WP slot
|
|
|
|
// ---------------------
|
2014-03-17 04:44:25 -03:00
|
|
|
next_WP = guided_WP;
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
// this is handy for the groundstation
|
2014-03-17 04:44:25 -03:00
|
|
|
wp_totalDistance = get_distance(current_loc, next_WP);
|
2012-04-30 04:17:14 -03:00
|
|
|
wp_distance = wp_totalDistance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// run this at setup on the ground
|
|
|
|
// -------------------------------
|
2015-05-12 04:00:25 -03:00
|
|
|
void Rover::init_home()
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2012-11-28 07:44:03 -04:00
|
|
|
if (!have_position) {
|
|
|
|
// we need position information
|
|
|
|
return;
|
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2015-11-18 14:53:14 -04:00
|
|
|
gcs_send_text(MAV_SEVERITY_INFO, "Init HOME");
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2014-03-30 22:01:54 -03:00
|
|
|
ahrs.set_home(gps.location());
|
2015-10-30 02:41:06 -03:00
|
|
|
home_is_set = HOME_SET_NOT_LOCKED;
|
2015-07-06 01:17:05 -03:00
|
|
|
Log_Write_Home_And_Origin();
|
2015-10-02 08:34:44 -03:00
|
|
|
GCS_MAVLINK::send_home_all(gps.location());
|
2012-04-30 04:17:14 -03:00
|
|
|
|
2014-03-10 05:45:26 -03:00
|
|
|
// Save Home to EEPROM
|
|
|
|
mission.write_home_to_storage();
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
// Save prev loc
|
|
|
|
// -------------
|
2014-03-17 04:44:25 -03:00
|
|
|
next_WP = prev_WP = home;
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
// Load home for a default guided_WP
|
|
|
|
// -------------
|
|
|
|
guided_WP = home;
|
|
|
|
}
|
|
|
|
|
2015-05-12 02:03:23 -03:00
|
|
|
void Rover::restart_nav()
|
2012-05-14 12:47:08 -03:00
|
|
|
{
|
2013-02-07 19:21:30 -04:00
|
|
|
g.pidSpeedThrottle.reset_I();
|
2014-03-17 04:44:25 -03:00
|
|
|
prev_WP = current_loc;
|
2014-05-07 19:35:22 -03:00
|
|
|
mission.start_or_resume();
|
2012-05-14 12:47:08 -03:00
|
|
|
}
|
2015-10-30 02:41:06 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
update home location from GPS
|
|
|
|
this is called as long as we have 3D lock and the arming switch is
|
|
|
|
not pushed
|
|
|
|
*/
|
|
|
|
void Rover::update_home()
|
|
|
|
{
|
|
|
|
if (home_is_set == HOME_SET_NOT_LOCKED) {
|
|
|
|
ahrs.set_home(gps.location());
|
|
|
|
Log_Write_Home_And_Origin();
|
|
|
|
GCS_MAVLINK::send_home_all(gps.location());
|
|
|
|
}
|
|
|
|
barometer.update_calibration();
|
|
|
|
}
|