Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Rover/mode_steering.cpp
Views: 1798
#include "Rover.h"12void ModeSteering::update()3{4// get speed forward5float speed;6if (!attitude_control.get_forward_speed(speed)) {7// no valid speed so stop8g2.motors.set_throttle(0.0f);9g2.motors.set_steering(0.0f);10_desired_lat_accel = 0.0f;11return;12}1314float desired_steering, desired_speed;15get_pilot_desired_steering_and_speed(desired_steering, desired_speed);1617bool reversed = is_negative(desired_speed);1819// determine if pilot is requesting pivot turn20if (g2.motors.have_skid_steering() && is_zero(desired_speed)) {21// pivot turning using turn rate controller22// convert pilot steering input to desired turn rate in radians/sec23const float target_turn_rate = (desired_steering / 4500.0f) * radians(g2.acro_turn_rate);24_desired_lat_accel = 0.0f;2526// run steering turn rate controller and throttle controller27const float steering_out = attitude_control.get_steering_out_rate(target_turn_rate,28g2.motors.limit.steer_left,29g2.motors.limit.steer_right,30rover.G_Dt);31set_steering(steering_out * 4500.0f);32} else {33// In steering mode we control lateral acceleration directly.34// For regular steering vehicles we use the maximum lateral acceleration35// at full steering lock for this speed: V^2/R where R is the radius of turn.36float max_g_force = speed * speed / MAX(g2.turn_radius, 0.1f);37max_g_force = constrain_float(max_g_force, 0.1f, attitude_control.get_turn_lat_accel_max());3839// convert pilot steering input to desired lateral acceleration40_desired_lat_accel = max_g_force * (desired_steering / 4500.0f);4142// reverse target lateral acceleration if backing up43if (reversed) {44_desired_lat_accel = -_desired_lat_accel;45}4647// run lateral acceleration to steering controller48calc_steering_from_lateral_acceleration(_desired_lat_accel, reversed);49}5051// run speed to throttle controller52calc_throttle(desired_speed, true);53}545556