RaidZeroLib
Coroutine robot framework for VEX V5
Loading...
Searching...
No Matches
Odometry.hpp
1#pragma once
2#include <string_view>
3
4#include "RaidZeroLib/api/Geometry/Pose.hpp"
5#include "RaidZeroLib/api/Geometry/Rotation.hpp"
6#include "RaidZeroLib/api/Geometry/Twist.hpp"
7#include "RaidZeroLib/api/Hardware/Sensor.hpp"
8#include "RaidZeroLib/api/Runtime/Component.hpp"
9
10namespace rz {
11
25class Odometry : public Component {
26 public:
27 [[nodiscard]] const Pose& pose() const noexcept { return pose_; }
28
31 void setPose(const Pose& pose) noexcept { pose_ = pose; }
32
34 [[nodiscard]] Sensor<Rotation>& heading() noexcept { return headingSensor; }
35
37 [[nodiscard]] Sensor<Length>& distance() noexcept { return distanceSensor; }
38
39 protected:
40 explicit Odometry(std::string_view name) : Component(name) {}
41
43 [[nodiscard]] virtual Twist displacement() = 0;
44
45 private:
46 class HeadingEstimate final : public Sensor<Rotation> {
47 public:
48 explicit HeadingEstimate(const Odometry& odometry) : odometry(odometry) {}
49 [[nodiscard]] bool connected() const override { return true; }
50
51 protected:
52 [[nodiscard]] Rotation raw() const override { return odometry.pose_.getRotation(); }
53
54 private:
55 const Odometry& odometry;
56 };
57
58 class DistanceEstimate final : public Sensor<Length> {
59 public:
60 explicit DistanceEstimate(const Odometry& odometry) : odometry(odometry) {}
61 [[nodiscard]] bool connected() const override { return true; }
62
63 protected:
64 [[nodiscard]] Length raw() const override { return odometry.distance_; }
65
66 private:
67 const Odometry& odometry;
68 };
69
70 Task<> loop() final;
71
72 Pose pose_;
73 Length distance_{};
74 HeadingEstimate headingSensor{*this};
75 DistanceEstimate distanceSensor{*this};
76};
77
78} // namespace rz
std::string_view name() const noexcept
Used in log and error messages.
Definition Component.hpp:30
Component(const Component &)=delete
Tracks the robot's pose on the field from its sensors.
Definition Odometry.hpp:25
void setPose(const Pose &pose) noexcept
Sets where the robot is now, e.g. its starting position at the start of autonomous....
Definition Odometry.hpp:31
Sensor< Length > & distance() noexcept
How far the robot has driven along its own forward axis in total; driving backward counts down.
Definition Odometry.hpp:37
virtual Twist displacement()=0
How the robot moved in its own frame since the previous tick.
Sensor< Rotation > & heading() noexcept
The heading on the field (the pose's rotation), counterclockwise positive.
Definition Odometry.hpp:34
Odometry(std::string_view name)
Definition Odometry.hpp:40
const Pose & pose() const noexcept
Definition Odometry.hpp:27
Rigid-body pose in SE(2) with unit-safe position and rotation.
Definition Pose.hpp:20
const Rotation & getRotation() const noexcept
Access the heading.
Immutable planar rotation about the Z axis.
Definition Rotation.hpp:16
A reading from hardware, or computed from other sensors.
Definition Sensor.hpp:25
virtual Rotation raw() const=0
virtual bool connected() const=0
Differential motion (twist) in SE(2) space.
Definition Twist.hpp:16
corral::Task< T > Task
Lazy: nothing runs until it is co_awaited.
Definition Task.hpp:17
au::QuantityD< au::Meters > Length
Definition Units.hpp:9
Definition DriverControl.hpp:11