2#include "RaidZeroLib/api/Hardware/Device.hpp"
3#include "RaidZeroLib/api/Hardware/Direction.hpp"
4#include "RaidZeroLib/api/Hardware/Motor.hpp"
5#include "RaidZeroLib/api/Hardware/Sensor.hpp"
6#include "RaidZeroLib/api/Units/Units.hpp"
38 class Encoder final :
public Sensor<Angle> {
40 explicit Encoder(
const MotorDevice& motor) : motor(motor) {}
44 [[nodiscard]]
Angle raw()
const override {
return motor.position; }
45 [[nodiscard]] std::uint32_t epoch()
const override {
return motor.deviceEpoch(); }
51 class Velocity final :
public Sensor<AngularVelocity> {
53 explicit Velocity(
const MotorDevice& motor) : motor(motor) {}
54 [[nodiscard]]
bool connected()
const override {
return motor.deviceConnected(); }
57 [[nodiscard]]
AngularVelocity raw()
const override {
return motor.speed; }
58 [[nodiscard]] std::uint32_t epoch()
const override {
return motor.deviceEpoch(); }
65 void onConnect()
override;
70 Encoder encoderSensor{*
this};
71 Velocity velocitySensor{*
this};
bool deviceConnected() const noexcept
Whether this tick's read succeeded.
Definition Device.hpp:23
std::uint8_t port() const noexcept
Definition Device.hpp:20
Device(std::uint8_t port, std::string_view kind)
V5 Smart Motor. Its built-in encoder is exposed as sensors on the same snapshot.
Definition MotorDevice.hpp:11
void setVoltage(Voltage voltage) override
Commands a voltage, clamped to the motor's range. Positive drives the mechanism forward.
Sensor< AngularVelocity > & velocity() noexcept
Output shaft velocity as estimated by the motor.
Definition MotorDevice.hpp:35
bool connected() const override
Definition MotorDevice.hpp:29
Sensor< Angle > & encoder() noexcept
Output shaft angle (after the cartridge).
Definition MotorDevice.hpp:32
Cartridge
Definition MotorDevice.hpp:13
@ Green
200 rpm
Definition MotorDevice.hpp:15
MotorDevice(std::uint8_t port)
Definition MotorDevice.hpp:25
MotorDevice(std::uint8_t port, Config config)
A reading from hardware, or computed from other sensors.
Definition Sensor.hpp:25
virtual bool connected() const=0
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::UnitQuotientT< au::Radians, au::Seconds > > AngularVelocity
Definition Units.hpp:14
au::QuantityD< au::Volts > Voltage
Definition Units.hpp:15
au::QuantityD< au::Radians > Angle
Definition Units.hpp:13
Definition DriverControl.hpp:11
Definition MotorDevice.hpp:19
Cartridge cartridge
Definition MotorDevice.hpp:20
Direction positive
The way the output shaft turns for a positive voltage, and the way the encoder counts up.
Definition MotorDevice.hpp:22