2015-05-13 00:16:45 -03:00
|
|
|
#include "Rover.h"
|
|
|
|
|
2014-02-16 19:08:59 -04:00
|
|
|
/*
|
2015-11-04 23:34:24 -04:00
|
|
|
work out if we are going to use pivot steering
|
|
|
|
*/
|
2017-06-29 04:18:08 -03:00
|
|
|
bool Rover::use_pivot_steering(void)
|
|
|
|
{
|
|
|
|
// check cases where we clearly cannot use pivot steering
|
2017-07-18 23:19:08 -03:00
|
|
|
if (control_mode->is_autopilot_mode() || !g2.motors.have_skid_steering() || g.pivot_turn_angle <= 0) {
|
2017-06-29 04:18:08 -03:00
|
|
|
pivot_steering_active = false;
|
|
|
|
return false;
|
2014-02-16 19:08:59 -04:00
|
|
|
}
|
2017-06-29 04:18:08 -03:00
|
|
|
|
|
|
|
// calc bearing error
|
|
|
|
const int16_t bearing_error = wrap_180_cd(nav_controller->target_bearing_cd() - ahrs.yaw_sensor) / 100;
|
|
|
|
|
|
|
|
// if error is larger than pivot_turn_angle start pivot steering
|
|
|
|
if (bearing_error > g.pivot_turn_angle) {
|
|
|
|
pivot_steering_active = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if within 10 degrees of the target heading, exit pivot steering
|
|
|
|
if (bearing_error < 10) {
|
|
|
|
pivot_steering_active = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// by default stay in
|
|
|
|
return pivot_steering_active;
|
2014-02-16 19:08:59 -04:00
|
|
|
}
|
|
|
|
|
2016-10-30 07:42:46 -03:00
|
|
|
/*
|
|
|
|
test if we are loitering AND should be stopped at a waypoint
|
|
|
|
*/
|
|
|
|
bool Rover::in_stationary_loiter()
|
|
|
|
{
|
|
|
|
// Confirm we are in AUTO mode and need to loiter for a time period
|
2017-07-18 23:19:08 -03:00
|
|
|
if ((loiter_start_time > 0) && (control_mode == &mode_auto)) {
|
2016-10-30 07:42:46 -03:00
|
|
|
// Check if active loiter is enabled AND we are outside the waypoint loiter radius
|
2016-12-19 23:31:42 -04:00
|
|
|
// then the vehicle still needs to move so return false
|
|
|
|
if (active_loiter && (wp_distance > g.waypoint_radius)) {
|
|
|
|
return false;
|
2016-10-30 07:42:46 -03:00
|
|
|
}
|
2016-12-19 23:31:42 -04:00
|
|
|
return true;
|
2016-10-30 07:42:46 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-21 19:38:25 -03:00
|
|
|
|
2012-04-30 04:17:14 -03:00
|
|
|
/*****************************************
|
2015-11-04 23:34:24 -04:00
|
|
|
Set the flight control servos based on the current calculated values
|
2012-04-30 04:17:14 -03:00
|
|
|
*****************************************/
|
2017-07-19 05:00:13 -03:00
|
|
|
void Rover::set_servos(void)
|
|
|
|
{
|
2017-07-06 00:06:20 -03:00
|
|
|
// send output signals to motors
|
2017-07-14 23:59:28 -03:00
|
|
|
if (motor_test) {
|
|
|
|
g2.motors.slew_limit_throttle(false);
|
|
|
|
motor_test_output();
|
|
|
|
} else {
|
|
|
|
g2.motors.output(arming.is_armed() && hal.util->get_soft_armed(), G_Dt);
|
|
|
|
}
|
2017-06-20 03:17:24 -03:00
|
|
|
}
|