libstp
Robotics library for Botball
Loading...
Searching...
No Matches
bemf_velocity_tune.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <string>
5#include <vector>
6
7#include "autotune/types.hpp"
8#include "drive/drive.hpp"
9#include "hal/odometry.hpp"
10
11namespace libstp::autotune
12{
28 {
32 std::vector<int> pwm_levels{};
35 int pwm_steps{6};
39 int sweeps{1};
40
43 double pre_roll_distance_m{0.10};
45 double measure_distance_m{0.15};
47 double segment_timeout_s{5.0};
51 double return_tolerance_m{0.04};
52 double return_timeout_s{6.0};
53
54 int sample_hz{100};
56 double settle_s{0.5};
57
62 double min_window_ticks{20.0};
63
72 bool apply{true};
73 };
74
77 {
80 double window_time_s{0.0};
81 double body_speed_mps{0.0};
82 double wheel_omega_rad_s{0.0};
83 std::array<double, 4> delta_ticks{};
84 std::array<double, 4> median_bemf{};
85 std::array<double, 4> ticks_to_rad{};
86 bool valid{false};
87 };
88
91 {
92 int port{-1};
93 int n_points{0};
94 double ticks_to_rad_median{0.0};
95 double ticks_to_rad_mean{0.0};
96 double ticks_to_rad_cv{0.0};
98 // ω = slope·bemf + intercept (ω from ground truth, bemf from ADC).
99 double bemf_omega_slope{0.0};
101 double bemf_omega_r2{0.0};
105 double bemf_offset{0.0};
106 bool linear{false};
107 };
108
111 {
112 std::vector<BemfVelocityPoint> points{};
113 std::array<BemfMotorFit, 4> motors{};
114 std::array<double, 4> ticks_to_rad{};
115 std::array<double, 4> bemf_offset{};
116 bool linear_overall{false};
117 bool applied{false};
118 bool success{false};
119 std::string failure_reason{};
120 };
121
132 {
133 public:
135
136 [[nodiscard]] BemfVelocityResult tune(const BemfVelocityConfig& cfg) const;
137
138 private:
139 drive::Drive& drive_;
140 odometry::IOdometry& odometry_;
141 };
142
143} // namespace libstp::autotune
BemfVelocityResult tune(const BemfVelocityConfig &cfg) const
BemfVelocityTuner(drive::Drive &drive, odometry::IOdometry &odometry)
Per-motor fit + linearity diagnostics across the speed sweep.
bool linear
cv low AND r² high AND |intercept| small
double ticks_to_rad_median
value chosen for persistence
Configuration for BemfVelocityTuner.
double segment_timeout_s
Safety cap on a single forward segment (pre-roll + window). Seconds.
double min_window_ticks
Reject a per-motor result whose accumulated |ticks| is below this.
int return_pwm_percent
PWM used to drive back toward the origin between segments (percent).
double settle_s
Settle/brake dwell between segments. Seconds.
double return_tolerance_m
How close to the origin the return move tries to get. Meters.
double measure_distance_m
Ground-truth distance of the measurement window itself. Meters.
One measurement window at a single PWM level.
std::array< double, 4 > delta_ticks
accumulated BEMF ticks per motor
std::array< double, 4 > ticks_to_rad
(D/r)/|Δticks| per motor
std::array< double, 4 > median_bemf
median |instantaneous BEMF| per motor
double ground_truth_distance_m
calibration-board displacement
double body_speed_mps
distance / time (≈ steady state)
double wheel_omega_rad_s
body_speed / wheel_radius
Full result of a BEMF→velocity calibration run.
std::array< BemfMotorFit, 4 > motors
std::array< double, 4 > bemf_offset
per-motor BEMF offset (counts)
std::vector< BemfVelocityPoint > points
std::array< double, 4 > ticks_to_rad
chosen per-motor value