libstp
Robotics library for Botball
Loading...
Searching...
No Matches
turn_motion.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "motion/motion.hpp"
5
6namespace libstp::motion
7{
9 struct TurnConfig
10 {
11 double target_angle_rad{0.0}; // Target turn angle (positive = CCW, negative = CW)
12 double speed_scale{1.0}; // 0-1 fraction of AxisConstraints.angular.max_velocity
13 double kS{0.0}; // Static friction compensation (rad/s)
14
20 bool has_angle_target{true};
21 };
22
30 class TurnMotion final : public Motion
31 {
32 public:
34
35 void start() override;
36 void update(double dt) override;
37 [[nodiscard]] bool isFinished() const override;
38
47 void startWarm(double heading_offset_rad, double initial_angular_velocity);
48
50 void setSuppressHardStopOnComplete(bool suppress) { suppress_hard_stop_ = suppress; }
51
53 [[nodiscard]] bool hasReachedAngle() const;
54
56 [[nodiscard]] double getFilteredVelocity() const { return filtered_velocity_; }
57
58 private:
59 void complete();
60
61 TurnConfig cfg_{};
62 double max_velocity_{0.0}; // computed from speed_scale * AxisConstraints
63 bool finished_{false};
64 bool suppress_hard_stop_{false};
65 double heading_offset_rad_{0.0}; // subtracted from accumulated heading in warm-start mode
66
67 // Profiled PID controller (replaces manual PID)
68 ProfiledPIDController profiled_pid_;
69
70 // Velocity tracking for settling detection
71 double prev_heading_{0.0}; // last wrapped heading from odometry (for delta computation)
72 double accumulated_heading_{0.0}; // unwrapped heading (handles wraparound at ±π)
73 double filtered_velocity_{0.0};
74 static constexpr double kVelocityFilterAlpha{0.3};
75
76 // Diagnostic counter
77 int cycle_{0};
78 };
79}
Motion(MotionContext ctx)
Definition motion.hpp:35
void setSuppressHardStopOnComplete(bool suppress)
TurnMotion(MotionContext ctx, TurnConfig config)
void update(double dt) override
double getFilteredVelocity() const
void startWarm(double heading_offset_rad, double initial_angular_velocity)
bool isFinished() const override