libstp
Robotics library for Botball
Loading...
Searching...
No Matches
motion_tune.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <mutex>
5#include <string>
6#include <tuple>
7#include <vector>
8#include <condition_variable>
9#include <atomic>
10
11#include "autotune/types.hpp"
12#include "drive/drive.hpp"
13#include "hal/odometry.hpp"
16
17namespace libstp::autotune
18{
38 {
39 public:
48
59 [[nodiscard]] std::map<std::string, MotionTuneResult> tune(
60 const std::vector<std::string>& params,
61 const MotionTuneConfig& cfg) const;
62
71 const std::string& param_name,
72 const MotionTuneConfig& cfg) const;
73
75 void requestPauseAfterTrial() const noexcept;
76
78 void resume() const noexcept;
79
81 [[nodiscard]] std::string pauseState() const;
82
83 private:
90 [[nodiscard]] std::tuple<double, double, double> runLinearTrial(
91 motion::LinearAxis axis,
92 double distance_m,
93 double speed_scale,
94 const MotionTuneConfig& cfg) const;
95
102 [[nodiscard]] std::tuple<double, double, double> runTurnTrial(
103 double angle_rad,
104 double speed_scale,
105 const MotionTuneConfig& cfg) const;
106
117 void returnLinear(motion::LinearAxis axis, double home_heading_rad,
118 const MotionTuneConfig& cfg) const;
119
126 void returnTurn(double home_heading_rad, const MotionTuneConfig& cfg) const;
127
132 [[nodiscard]] double evaluateGains(
133 const std::string& param_name,
134 double kp,
135 double kd,
136 int trial_idx,
137 const MotionTuneConfig& cfg) const;
138
145 [[nodiscard]] double scoreMotionTrial(
146 const std::string& param_name,
147 double settle_time,
148 double overshoot,
149 double final_error,
150 const MotionTuneConfig& cfg) const;
151
156 [[nodiscard]] double linearTargetDistance(
157 motion::LinearAxis axis,
158 const MotionTuneConfig& cfg) const;
159
163 [[nodiscard]] double trialTimeoutS(
164 double distance_m,
165 double max_velocity,
166 double speed_scale,
167 const MotionTuneConfig& cfg) const;
168
170 void pauseIfRequested() const;
171
172 drive::Drive& drive_;
173 odometry::IOdometry& odometry_;
174 motion::UnifiedMotionPidConfig& pid_config_;
175 mutable std::atomic<bool> pause_requested_{false};
176 mutable std::atomic<bool> paused_{false};
177 mutable std::mutex pause_mutex_;
178 mutable std::condition_variable pause_cv_;
179 };
180
181} // namespace libstp::autotune
void requestPauseAfterTrial() const noexcept
Queue a pause that takes effect after the current trial completes.
MotionTuner(drive::Drive &drive, odometry::IOdometry &odometry, motion::UnifiedMotionPidConfig &pid_config)
void resume() const noexcept
Cancel a queued pause or resume from an active pause.
std::map< std::string, MotionTuneResult > tune(const std::vector< std::string > &params, const MotionTuneConfig &cfg) const
Tune multiple parameters in sequence.
std::string pauseState() const
Current operator-control state: "running", "stop_queued", or "stopped".
MotionTuneResult tuneParam(const std::string &param_name, const MotionTuneConfig &cfg) const
Tune a single motion PID parameter.
Configuration for the MotionTuner (Hooke-Jeeves coordinate descent).
Definition types.hpp:160
Result of tuning a single motion PID parameter (distance, lateral, or heading).
Definition types.hpp:145