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