RaidZeroLib
Coroutine robot framework for VEX V5
Loading...
Searching...
No Matches
TrackingWheel.hpp
1#pragma once
2#include <stdexcept>
3
4#include "RaidZeroLib/api/Hardware/GearRatio.hpp"
5#include "RaidZeroLib/api/Hardware/Sensor.hpp"
6#include "RaidZeroLib/api/Units/Units.hpp"
7
8namespace rz {
9
15class TrackingWheel final : public Sensor<Length> {
16 public:
20 TrackingWheel(Sensor<Angle>& encoder, Length diameter, GearRatio gears = {})
21 : encoder(encoder), diameter(diameter), gears(gears) {
22 if (gears.driving <= 0 || gears.driven <= 0 || diameter <= Length{}) {
23 throw std::invalid_argument("a tracking wheel needs positive tooth counts and diameter");
24 }
25 }
26
27 [[nodiscard]] bool connected() const override { return encoder.connected(); }
28
29 protected:
30 [[nodiscard]] Length raw() const override {
31 return encoder.get().in(au::radians) * gears.drivenTurnsPerDrivingTurn() * diameter / 2.0;
32 }
33
34 private:
35 Sensor<Angle>& encoder;
36 Length diameter;
37 GearRatio gears;
38};
39
40} // namespace rz
A reading from hardware, or computed from other sensors.
Definition Sensor.hpp:25
bool connected() const override
Definition TrackingWheel.hpp:27
TrackingWheel(Sensor< Angle > &encoder, Length diameter, GearRatio gears={})
Definition TrackingWheel.hpp:20
Length raw() const override
This tick's reading from the source; the last good value while disconnected. May restart after a reco...
Definition TrackingWheel.hpp:30
au::QuantityD< au::Meters > Length
Definition Units.hpp:9
Definition DriverControl.hpp:11
A gear reduction, from the tooth counts as you would read them off the robot.
Definition GearRatio.hpp:13
double driving
Definition GearRatio.hpp:14
double driven
Definition GearRatio.hpp:15