2017-11-28 02:59:13 -04:00
|
|
|
#include "mode.h"
|
|
|
|
#include "Rover.h"
|
|
|
|
|
|
|
|
void ModeAcro::update()
|
|
|
|
{
|
|
|
|
// get speed forward
|
|
|
|
float speed;
|
|
|
|
if (!attitude_control.get_forward_speed(speed)) {
|
|
|
|
// no valid speed so stop
|
|
|
|
g2.motors.set_throttle(0.0f);
|
|
|
|
g2.motors.set_steering(0.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-28 22:55:11 -04:00
|
|
|
// convert pilot stick input into desired steering and throttle
|
|
|
|
float desired_steering, desired_throttle;
|
|
|
|
get_pilot_desired_steering_and_throttle(desired_steering, desired_throttle);
|
|
|
|
|
2018-03-14 03:29:19 -03:00
|
|
|
// convert pilot throttle input to desired speed
|
2017-12-13 05:17:42 -04:00
|
|
|
float target_speed = desired_throttle * 0.01f * calc_speed_max(g.speed_cruise, g.throttle_cruise * 0.01f);
|
2017-11-28 22:55:11 -04:00
|
|
|
|
|
|
|
// convert pilot steering input to desired turn rate in radians/sec
|
2017-12-05 21:37:31 -04:00
|
|
|
const float target_turn_rate = (desired_steering / 4500.0f) * radians(g2.acro_turn_rate);
|
2017-11-28 22:55:11 -04:00
|
|
|
|
2017-11-28 02:59:13 -04:00
|
|
|
// set reverse flag backing up
|
2017-12-05 21:37:31 -04:00
|
|
|
const bool reversed = is_negative(target_speed);
|
2017-11-28 02:59:13 -04:00
|
|
|
rover.set_reverse(reversed);
|
|
|
|
|
2017-12-13 05:17:42 -04:00
|
|
|
// apply object avoidance to desired speed using half vehicle's maximum acceleration/deceleration
|
|
|
|
rover.g2.avoid.adjust_speed(0.0f, 0.5f * attitude_control.get_accel_max(), ahrs.yaw, target_speed, rover.G_Dt);
|
|
|
|
|
2017-11-28 22:55:11 -04:00
|
|
|
// run steering turn rate controller and throttle controller
|
2017-12-05 21:37:31 -04:00
|
|
|
const float steering_out = attitude_control.get_steering_out_rate(target_turn_rate, g2.motors.have_skid_steering(), g2.motors.limit.steer_left, g2.motors.limit.steer_right, reversed);
|
2017-11-28 22:55:11 -04:00
|
|
|
g2.motors.set_steering(steering_out * 4500.0f);
|
|
|
|
calc_throttle(target_speed, false);
|
2017-11-28 02:59:13 -04:00
|
|
|
}
|