2012-04-30 04:17:14 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
//****************************************************************
|
|
|
|
// Function that will calculate the desired direction to fly and distance
|
|
|
|
//****************************************************************
|
|
|
|
static void navigate()
|
|
|
|
{
|
|
|
|
// do not navigate with corrupt data
|
|
|
|
// ---------------------------------
|
2012-11-28 07:44:03 -04:00
|
|
|
if (!have_position) {
|
2012-04-30 04:17:14 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-27 18:20:20 -04:00
|
|
|
if ((next_WP.lat == 0)||(home_is_set==false)){
|
2012-04-30 04:17:14 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-01 07:32:57 -04:00
|
|
|
// waypoint distance from rover
|
2012-04-30 04:17:14 -03:00
|
|
|
// ----------------------------
|
|
|
|
wp_distance = get_distance(¤t_loc, &next_WP);
|
|
|
|
|
|
|
|
if (wp_distance < 0){
|
|
|
|
gcs_send_text_P(SEVERITY_HIGH,PSTR("<navigate> WP error - distance < 0"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// target_bearing is where we should be heading
|
|
|
|
// --------------------------------------------
|
2012-08-07 03:03:36 -03:00
|
|
|
target_bearing = get_bearing_cd(¤t_loc, &next_WP);
|
2012-04-30 04:17:14 -03:00
|
|
|
|
|
|
|
// nav_bearing will includes xtrac correction
|
|
|
|
// ------------------------------------------
|
|
|
|
nav_bearing = target_bearing;
|
|
|
|
|
|
|
|
// control mode specific updates to nav_bearing
|
|
|
|
// --------------------------------------------
|
|
|
|
update_navigation();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void calc_bearing_error()
|
2012-05-20 12:45:07 -03:00
|
|
|
{
|
2013-02-07 19:21:30 -04:00
|
|
|
static butter10hz1_6 butter;
|
|
|
|
|
2013-03-28 23:14:14 -03:00
|
|
|
bearing_error_cd = wrap_180_cd(nav_bearing - ahrs.yaw_sensor);
|
2013-02-07 19:21:30 -04:00
|
|
|
bearing_error_cd = butter.filter(bearing_error_cd);
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void update_crosstrack(void)
|
|
|
|
{
|
|
|
|
// Crosstrack Error
|
|
|
|
// ----------------
|
2013-03-28 23:14:14 -03:00
|
|
|
if (abs(wrap_180_cd(target_bearing - crosstrack_bearing)) < 4500) { // If we are too far off or too close we don't do track following
|
2013-02-07 18:21:22 -04:00
|
|
|
crosstrack_error = sinf(radians((target_bearing - crosstrack_bearing) / (float)100)) * wp_distance; // Meters we are off track line
|
2013-05-01 21:26:12 -03:00
|
|
|
nav_bearing += constrain_float(crosstrack_error * g.crosstrack_gain, -g.crosstrack_entry_angle.get(), g.crosstrack_entry_angle.get());
|
2013-03-28 23:14:14 -03:00
|
|
|
nav_bearing = wrap_360_cd(nav_bearing);
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_crosstrack()
|
|
|
|
{
|
2012-08-07 03:03:36 -03:00
|
|
|
crosstrack_bearing = get_bearing_cd(&prev_WP, &next_WP); // Used for track following
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void reached_waypoint()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|