WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
Tachometer.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
8#include "wpi/hal/Counter.h"
9#include "wpi/hal/Types.hpp"
10#include "wpi/units/angular_velocity.hpp"
11#include "wpi/units/frequency.hpp"
12#include "wpi/units/time.hpp"
15
16namespace wpi {
17/**
18 * Tachometer for getting rotational velocity from a device.
19 *
20 * <p>The Tachometer class measures the time between digital pulses to
21 * determine the rotation velocity of a mechanism. Examples of devices that
22 * could be used with the tachometer class are a hall effect sensor, break beam
23 * sensor, or optical sensor detecting tape on a shooter wheel. Unlike
24 * encoders, this class only needs a single digital input.
25 */
27 public wpi::util::SendableHelper<Tachometer> {
28 public:
29 /**
30 * Constructs a new tachometer.
31 *
32 * @param channel The DIO Channel.
33 * @param configuration Edge configuration
34 */
35 Tachometer(int channel, EdgeConfiguration configuration);
36
37 Tachometer(Tachometer&&) = default;
39
40 ~Tachometer() override = default;
41
42 /**
43 * Sets the configuration for the channel.
44 *
45 * @param configuration The channel configuration.
46 */
48
49 /**
50 * Gets the tachometer frequency.
51 *
52 * @return Current frequency.
53 */
54 wpi::units::hertz_t GetFrequency() const;
55
56 /**
57 * Gets the tachometer period.
58 *
59 * @return Current period.
60 */
61 wpi::units::second_t GetPeriod() const;
62
63 /**
64 * Gets the number of edges per revolution.
65 *
66 * @return Edges per revolution.
67 */
69
70 /**
71 * Sets the number of edges per revolution.
72 *
73 * @param edges Edges per revolution.
74 */
75 void SetEdgesPerRevolution(int edges);
76
77 /**
78 * Gets the current tachometer revolutions per second.
79 *
80 * SetEdgesPerRevolution must be set with a non 0 value for this to work.
81 *
82 * @return Current RPS.
83 */
84 wpi::units::turns_per_second_t GetRevolutionsPerSecond() const;
85
86 /**
87 * Gets the current tachometer revolutions per minute.
88 *
89 * SetEdgesPerRevolution must be set with a non 0 value for this to work.
90 *
91 * @return Current RPM.
92 */
93 wpi::units::revolutions_per_minute_t GetRevolutionsPerMinute() const;
94
95 /**
96 * Gets if the tachometer is stopped.
97 *
98 * @return True if the tachometer is stopped.
99 */
100 bool GetStopped() const;
101
102 /**
103 * Sets the maximum period before the tachometer is considered stopped.
104 *
105 * @param maxPeriod The max period.
106 */
107 void SetMaxPeriod(wpi::units::second_t maxPeriod);
108
109 protected:
111
112 private:
114 int m_edgesPerRevolution;
115 int32_t m_channel;
116};
117} // namespace wpi
bool GetStopped() const
Gets if the tachometer is stopped.
wpi::units::second_t GetPeriod() const
Gets the tachometer period.
Tachometer & operator=(Tachometer &&)=default
~Tachometer() override=default
void InitSendable(wpi::util::SendableBuilder &builder) override
Initializes this Sendable object.
wpi::units::revolutions_per_minute_t GetRevolutionsPerMinute() const
Gets the current tachometer revolutions per minute.
wpi::units::hertz_t GetFrequency() const
Gets the tachometer frequency.
void SetEdgeConfiguration(EdgeConfiguration configuration)
Sets the configuration for the channel.
void SetEdgesPerRevolution(int edges)
Sets the number of edges per revolution.
Tachometer(Tachometer &&)=default
void SetMaxPeriod(wpi::units::second_t maxPeriod)
Sets the maximum period before the tachometer is considered stopped.
wpi::units::turns_per_second_t GetRevolutionsPerSecond() const
Gets the current tachometer revolutions per second.
Tachometer(int channel, EdgeConfiguration configuration)
Constructs a new tachometer.
int GetEdgesPerRevolution() const
Gets the number of edges per revolution.
A move-only C++ wrapper around a HAL handle.
Definition Types.hpp:16
Helper class for building Sendable dashboard representations.
Definition SendableBuilder.hpp:21
A helper class for use with objects that add themselves to SendableRegistry.
Definition SendableHelper.hpp:21
Interface for Sendable objects.
Definition Sendable.hpp:16
Definition CvSource.hpp:15
EdgeConfiguration
Edge configuration.
Definition EdgeConfiguration.hpp:11