RaidZeroLib
Coroutine robot framework for VEX V5
Loading...
Searching...
No Matches
RotationSensor.hpp
1#pragma once
2#include "RaidZeroLib/api/Hardware/Device.hpp"
3#include "RaidZeroLib/api/Hardware/Direction.hpp"
4#include "RaidZeroLib/api/Hardware/Sensor.hpp"
5#include "RaidZeroLib/api/Units/Units.hpp"
6
7namespace rz {
8
10class RotationSensor final : public Device, public Sensor<Angle> {
11 public:
16
17 explicit RotationSensor(std::uint8_t port) : RotationSensor(port, Config{}) {}
18 RotationSensor(std::uint8_t port, Config config);
19
20 [[nodiscard]] bool connected() const override { return deviceConnected(); }
21
22 protected:
23 [[nodiscard]] Angle raw() const override;
24 [[nodiscard]] std::uint32_t epoch() const override { return deviceEpoch(); }
25
26 private:
27 bool poll() override;
28
29 Config config;
30 Angle position{};
31};
32
33} // namespace rz
bool deviceConnected() const noexcept
Whether this tick's read succeeded.
Definition Device.hpp:23
std::uint8_t port() const noexcept
Definition Device.hpp:20
std::uint32_t deviceEpoch() const noexcept
Increments on every (re)connection.
Definition Device.hpp:26
Device(std::uint8_t port, std::string_view kind)
virtual bool poll()=0
Reads the hardware into cached members. Returns false if the read failed (keep old values).
bool connected() const override
Definition RotationSensor.hpp:20
RotationSensor(std::uint8_t port)
Definition RotationSensor.hpp:17
RotationSensor(std::uint8_t port, Config config)
std::uint32_t epoch() const override
Increments every time the source reconnects. Readings across a reconnect are not comparable.
Definition RotationSensor.hpp:24
Angle raw() const override
This tick's reading from the source; the last good value while disconnected. May restart after a reco...
Direction
A way a shaft can turn, seen looking at the face the shaft comes out of.
Definition Direction.hpp:6
@ Counterclockwise
Definition Direction.hpp:8
au::QuantityD< au::Radians > Angle
Definition Units.hpp:13
Definition DriverControl.hpp:11
Definition RotationSensor.hpp:12
Direction positive
The way the shaft turns, looking at the sensor's front face, for the angle to count up.
Definition RotationSensor.hpp:14