libstp
Robotics library for Botball
Loading...
Searching...
No Matches
directional_line_follow_motion.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <limits>
4#include <vector>
5
6#include <Eigen/Core>
7
9#include "motion/motion.hpp"
10
11namespace libstp::motion
12{
19
21 {
22 double heading_speed{0.0}; // -1..1 fraction of max forward velocity
23 double strafe_speed{0.0}; // -1..1 fraction of max lateral velocity
24 double distance_m{0.0};
26 double kp{0.4};
27 double ki{0.0};
28 double kd{0.1};
29 // Anti-windup band for the correction PID's integrator (output units,
30 // i.e. the same normalised correction space the PID emits). NaN
31 // integral_min mirrors -integral_max (symmetric clamp).
32 double integral_max{1.0};
33 double integral_min{std::numeric_limits<double>::quiet_NaN()};
35 bool heading_hold{true};
36 double correction_sign{1.0};
37 // When true, the heading-hold PID regulates onto ``target_heading_rad``
38 // (an absolute world heading) instead of the heading captured at start.
39 // Only consulted when heading_hold is true and correction_mode is
40 // Lateral or Forward.
41 bool has_target_heading{false};
42 double target_heading_rad{0.0};
43 };
44
46 {
47 double time_s{0.0};
48 double dt{0.0};
49 double error{0.0};
50 double correction{0.0};
51 double heading_error_rad{0.0};
52 double heading_speed_mps{0.0};
53 double strafe_speed_mps{0.0};
54 double cmd_vx_mps{0.0};
55 double cmd_vy_mps{0.0};
56 double cmd_wz_radps{0.0};
58 bool finished{false};
59 };
60
62 {
63 public:
65
66 void start() override;
67 void update(double dt) override;
68 [[nodiscard]] bool isFinished() const override;
69
70 void setSensorError(double error);
71 [[nodiscard]] const std::vector<DirectionalLineFollowMotionTelemetry>& getTelemetry() const
72 {
73 return telemetry_;
74 }
75
76 private:
77 void captureInitialPose();
78 [[nodiscard]] double straightDistanceFromStart() const;
79 void complete();
80
82 std::unique_ptr<foundation::PidController> correction_pid_;
83 std::unique_ptr<foundation::PidController> heading_pid_;
84 Eigen::Vector2d initial_position_m_{Eigen::Vector2d::Zero()};
85 double initial_heading_rad_{0.0};
86 double vx_mps_{0.0};
87 double vy_mps_{0.0};
88 double max_linear_mps_{0.0};
89 double max_lateral_mps_{0.0};
90 double sensor_error_{0.0};
91 double elapsed_time_{0.0};
92 bool finished_{false};
93 static constexpr size_t kMaxTelemetrySamples{3000};
94 std::vector<DirectionalLineFollowMotionTelemetry> telemetry_;
95 };
96}
DirectionalLineFollowMotion(MotionContext ctx, DirectionalLineFollowMotionConfig config)
const std::vector< DirectionalLineFollowMotionTelemetry > & getTelemetry() const
Motion(MotionContext ctx)
Definition motion.hpp:35