Brick
Loading...
Searching...
No Matches
rotation.h
Go to the documentation of this file.
1/**
2 * @file rotation.h
3 * @brief V5 rotation sensor using Core's geometry and physical units.
4 */
5
6#pragma once
7
8#include "core/math/geometry/rotation2d.h"
9#include "core/math/units.h"
11
12namespace crust {
13
14/**
15 * @brief Class implementing the V5 Rotation Sensor.
16 *
17 * Provides functions for getting angle (wrapped), position (continuous), and angular velocity.
18 * The sensor is able to be reversed, and its position can be set.
19 */
20class Rotation : public Device {
21 public:
22 /**
23 * @brief Constructs a Rotation Sensor.
24 * @param port Physical Smart Port number [1, 21].
25 * @param reversed True to reverse the reported direction.
26 */
27 explicit Rotation(int port, bool reversed = false);
28
29 /**
30 * @brief Gets the shaft's absolute orientation within one revolution.
31 * @return Wrapped orientation represented by a Rotation2d.
32 * @note set_position() does not affect this value! The offset for this function can be set
33 * manually in the brain's devices tab.
34 */
36
37 /**
38 * @brief Gets the shaft's accumulated rotation relative to the current zero point.
39 * @return Continuous units::Angle that can span multiple revolutions.
40 */
41 units::Angle position() const;
42
43 /**
44 * @brief Gets the shaft's angular velocity.
45 * @return units::AngularVelocity.
46 */
47 units::AngularVelocity velocity() const;
48
49 /**
50 * @brief Sets the accumulated position to a continuous units::Angle.
51 * @param position value to set.
52 * @note Rounds to the nearest 0.01 degree for the C SDK. Does not change the result of angle().
53 */
54 void set_position(units::Angle position);
55
56 /**
57 * @brief Sets the accumulated position to a wrapped Rotation2d.
58 * @param position value to set.
59 * @note Rounds to the nearest 0.01 degree, wraps a rounded full revolution to zero.
60 * Does not change the result of angle().
61 */
63
64 /**
65 * @brief Sets the accumulated position to zero.
66 * @note Does not change the result of angle().
67 */
69
70 /**
71 * @brief Configures the direction reported.
72 * @param reversed True to reverse the sensor.
73 */
75
76 /**
77 * @brief Gets the sensor's reversal flag.
78 * @return True if sensor is reversed.
79 */
80 bool reversed() const;
81};
82
83} // namespace crust
Definition rotation2d.h:16
int port() const
Gets the physical Smart Port number.
Definition device.h:24
Device(int port, int expected_type)
Resolves and caches the C SDK handle for a physical Smart Port.
bool reversed() const
Gets the sensor's reversal flag.
Rotation(int port, bool reversed=false)
Constructs a Rotation Sensor.
void reset_position()
Sets the accumulated position to zero.
void set_position(Rotation2d position)
Sets the accumulated position to a wrapped Rotation2d.
units::AngularVelocity velocity() const
Gets the shaft's angular velocity.
Rotation2d angle() const
Gets the shaft's absolute orientation within one revolution.
void set_position(units::Angle position)
Sets the accumulated position to a continuous units::Angle.
void set_reversed(bool reversed)
Configures the direction reported.
units::Angle position() const
Gets the shaft's accumulated rotation relative to the current zero point.
Implements device port and connection logic used by VEX device subclasses.
The namespace of the entire Crust package, which contains direct abstractions for VEX hardware.