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/cruise_learn.cpp
Views: 1798
#include "Rover.h"12// start cruise throttle and speed learning3void Rover::cruise_learn_start()4{5// if disarmed or no speed available do nothing6float speed;7if (!arming.is_armed() || !g2.attitude_control.get_forward_speed(speed)) {8cruise_learn.learn_start_ms = 0;9gcs().send_text(MAV_SEVERITY_CRITICAL, "Cruise Learning NOT started");10return;11}12// start learning13cruise_learn.speed_filt.reset(speed);14cruise_learn.throttle_filt.reset(g2.motors.get_throttle());15cruise_learn.learn_start_ms = AP_HAL::millis();16cruise_learn.log_count = 0;17#if HAL_LOGGING_ENABLED18log_write_cruise_learn();19#endif20gcs().send_text(MAV_SEVERITY_CRITICAL, "Cruise Learning started");21}2223// update cruise learning with latest speed and throttle24// should be called at 50hz25void Rover::cruise_learn_update()26{27float speed;28if (cruise_learn.learn_start_ms > 0 && g2.attitude_control.get_forward_speed(speed)) {29// update filters with latest speed and throttle30cruise_learn.speed_filt.apply(speed, 0.02f);31cruise_learn.throttle_filt.apply(g2.motors.get_throttle(), 0.02f);32// 10Hz logging33#if HAL_LOGGING_ENABLED34if (cruise_learn.log_count % 5 == 0) {35log_write_cruise_learn();36}37cruise_learn.log_count += 1;38#endif39// check how long it took to learn40if (AP_HAL::millis() - cruise_learn.learn_start_ms >= 2000) {41cruise_learn_complete();42}43return;44}45}4647// complete cruise learning and save results48void Rover::cruise_learn_complete()49{50// when switch is moved low, save learned cruise value51if (cruise_learn.learn_start_ms > 0) {52const float thr = cruise_learn.throttle_filt.get();53const float speed = cruise_learn.speed_filt.get();54if (thr >= 10.0f && thr <= 100.0f && is_positive(speed)) {55g.throttle_cruise.set_and_save(thr);56g.speed_cruise.set_and_save(speed);57gcs().send_text(MAV_SEVERITY_CRITICAL, "Cruise Learned: Thr:%d Speed:%3.1f", (int)g.throttle_cruise, (double)g.speed_cruise);58} else {59gcs().send_text(MAV_SEVERITY_CRITICAL, "Cruise Learning failed");60}61cruise_learn.learn_start_ms = 0;62#if HAL_LOGGING_ENABLED63log_write_cruise_learn();64#endif65}66}6768#if HAL_LOGGING_ENABLED69// logging for cruise learn70void Rover::log_write_cruise_learn() const71{72// @LoggerMessage: CRSE73// @Description: Cruise Learn messages74// @URL: https://ardupilot.org/rover/docs/rover-tuning-throttle-and-speed.html75// @Field: TimeUS: Time since system startup76// @Field: State: True if Cruise Learn has started77// @Field: Speed: Determined target Cruise speed in auto missions78// @Field: Throttle: Determined base throttle percentage to be used in auto missions7980AP::logger().WriteStreaming("CRSE", "TimeUS,State,Speed,Throttle", "Qbff",81AP_HAL::micros64(),82cruise_learn.learn_start_ms > 0,83cruise_learn.speed_filt.get(),84cruise_learn.throttle_filt.get());85}86#endif878889