Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
tilt_pid_modder.hpp
Go to the documentation of this file.
1#pragma once
4
5#include <memory>
6#include <cmath>
7
8namespace fang::turret
9{
24template <typename Output>
26{
27public:
31 struct Config
32 {
33 double correctionScaler
34 };
35
44 TiltPidModder(std::unique_ptr<telemetry::IAngularPosition> fieldPitchSensor, const Config& config):
45 fieldPitchSensor_{std::move(fieldPitchSensor)},
46 config_{config}
47 {}
48
53 Output getModdedOutput(const Output& output) override
54 {
55 // These calculations are not unit sensitive
56 const double kRawAngle{static_cast<double>(fieldPitchSensor_->getAngularPosition())};
57
58 // Solve for the equilibrium of an tall object hinged at the bottom
59 // which is under the influence of gravity
60 // The moment at the hinge should keep it in equilibrium in all positions
61
62 // If the head is tilted down, the angle is negative, a positive force must counteract it
63 // Therefore, a negative is required.
64 // This provides the archetype
65 const double kPhysicsCorrection{-std::sin(kRawAngle)};
66
67 // It must be scaled to various turret head sizes
68 const double kCorrection{config_.correctionScaler * kPhysicsCorrection};
69 const Output kOutputCorrection{static_cast<Output>(kCorrection)};
70
71 // The turret is targeting a specific position, but
72 // The correct should remove the influence of gravity
73 // So that its ability to achieve the desired position is unhindered
74 return Output{kOutputCorrection + output};
75 };
76private:
77 std::unique_ptr<telemetry::IAngularPosition> fieldPitchSensor_;
78 Config config_;
79};
80}
Definition tilt_pid_modder.hpp:26
TiltPidModder(std::unique_ptr< telemetry::IAngularPosition > fieldPitchSensor, const Config &config)
Definition tilt_pid_modder.hpp:44
Output getModdedOutput(const Output &output) override
Definition tilt_pid_modder.hpp:53
Definition ipid_modder.hpp:14
Config(double p, double i, double d, double maxIntegralAccumulation, double maxOutput, double errorDerivativeFloor, double errorDeadzone=0.0, double tQDerivativeKalman=1.0, double tRDerivativeKalman=0.0, tRProportionalKalman=1.0)
Definition dimensional_smooth_pid.hpp:16
Definition pwm_info.hpp:4
Definition activate_booster_command.cpp:5
Definition tilt_pid_modder.hpp:32