Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
ramp.hpp
Go to the documentation of this file.
1#ifndef FANG_ROBOTICS_MCB_TRAP_ALGORITHMS_RAMP_HPP
2#define FANG_ROBOTICS_MCB_TRAP_ALGORITHMS_RAMP_HPP
4
6#include "tap/util_macros.hpp"
7namespace trap::algorithms
8{
12 template <typename ValueUnit, typename TimeUnit>
13 class Ramp
14 {
15 public:
19 Ramp(ValueUnit initialValue, double rampSpeed)
20 : m_ramp{static_cast<float>(initialValue)},
21 m_speed{rampSpeed}
22 {
23 }
24
25 mockable void setTarget(ValueUnit target)
26 {
27 m_ramp.setTarget(static_cast<float>(target));
28 }
29
30 mockable ValueUnit getTarget() const
31 {
32 return ValueUnit{m_ramp.getTarget()};
33 }
34
42 mockable void setSpeed(double speed)
43 {
44 m_speed = speed;
45 }
46
48 {
49 const TimeUnit deltaTime{static_cast<TimeUnit>(m_updateTimer.getDurationAndReset())};
50 const double rawDeltaTime{static_cast<double>(deltaTime)};
51 const double increment{m_speed * rawDeltaTime};
52
53 m_ramp.update(increment);
54 }
55
56 mockable ValueUnit getValue() const
57 {
58 return ValueUnit{m_ramp.getValue()};
59 }
60
62 {
63 return m_ramp.isTargetReached();
64 }
65
66 private:
68 double m_speed;
69 fang::chrono::SimpleTimer m_updateTimer{};
70
71 };
72}
73#endif
Definition simple_timer.hpp:12
Microseconds getDurationAndReset()
Definition simple_timer.cpp:20
Definition ramp.hpp:43
void setTarget(float target)
Sets a new target ramp value.
Definition ramp.cpp:43
float getValue() const
Returns the current value being generated by the ramp.
Definition ramp.cpp:62
float getTarget() const
Returns the target value (where the ramp generator will head torwards).
Definition ramp.cpp:66
bool isTargetReached() const
Returns true if the value == target.
Definition ramp.cpp:64
void update(float increment)
Definition ramp.cpp:54
Definition ramp.hpp:14
mockable ValueUnit getValue() const
Definition ramp.hpp:56
mockable bool isTargetReached() const
Definition ramp.hpp:61
mockable ValueUnit getTarget() const
Definition ramp.hpp:30
Ramp(ValueUnit initialValue, double rampSpeed)
Definition ramp.hpp:19
mockable void setTarget(ValueUnit target)
Definition ramp.hpp:25
mockable void update()
Definition ramp.hpp:47
mockable void setSpeed(double speed)
Definition ramp.hpp:42
Definition dimensional_smooth_pid.hpp:10
#define mockable
Wrap class functions that are not already virtual in this function if you wish to mock them.
Definition util_macros.hpp:38