WPILibC++ 2025.3.1
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
17namespace frc {
18class DigitalSource;
19
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 source The source.
36 */
38
39 /**
40 * Constructs a new tachometer.
41 *
42 * @param source The source.
43 */
44 explicit Tachometer(std::shared_ptr<DigitalSource> source);
45
46 Tachometer(Tachometer&&) = default;
48
49 ~Tachometer() override = default;
50
51 /**
52 * Gets the tachometer frequency.
53 *
54 * @return Current frequency.
55 */
56 units::hertz_t GetFrequency() const;
57
58 /**
59 * Gets the tachometer period.
60 *
61 * @return Current period.
62 */
63 units::second_t GetPeriod() const;
64
65 /**
66 * Gets the number of edges per revolution.
67 *
68 * @return Edges per revolution.
69 */
71
72 /**
73 * Sets the number of edges per revolution.
74 *
75 * @param edges Edges per revolution.
76 */
77 void SetEdgesPerRevolution(int edges);
78
79 /**
80 * Gets the current tachometer revolutions per second.
81 *
82 * SetEdgesPerRevolution must be set with a non 0 value for this to work.
83 *
84 * @return Current RPS.
85 */
86 units::turns_per_second_t GetRevolutionsPerSecond() const;
87
88 /**
89 * Gets the current tachometer revolutions per minute.
90 *
91 * SetEdgesPerRevolution must be set with a non 0 value for this to work.
92 *
93 * @return Current RPM.
94 */
95 units::revolutions_per_minute_t GetRevolutionsPerMinute() const;
96
97 /**
98 * Gets if the tachometer is stopped.
99 *
100 * @return True if the tachometer is stopped.
101 */
102 bool GetStopped() const;
103
104 /**
105 * Gets the number of sample to average.
106 *
107 * @return Samples to average.
108 */
110
111 /**
112 * Sets the number of samples to average.
113 *
114 * @param samples Samples to average.
115 */
116 void SetSamplesToAverage(int samples);
117
118 /**
119 * Sets the maximum period before the tachometer is considered stopped.
120 *
121 * @param maxPeriod The max period.
122 */
123 void SetMaxPeriod(units::second_t maxPeriod);
124
125 /**
126 * Sets if to update when empty.
127 *
128 * @param updateWhenEmpty True to update when empty.
129 */
130 void SetUpdateWhenEmpty(bool updateWhenEmpty);
131
132 protected:
133 void InitSendable(wpi::SendableBuilder& builder) override;
134
135 private:
136 std::shared_ptr<DigitalSource> m_source;
138 int m_edgesPerRevolution;
139 int32_t m_index;
140};
141} // namespace frc
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or and nanopb were all modified for use in Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation source
Definition ThirdPartyNotices.txt:124
DigitalSource Interface.
Definition DigitalSource.h:22
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 SetSamplesToAverage(int samples)
Sets the number of samples to average.
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.
units::second_t GetPeriod() const
Gets the tachometer period.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
int GetSamplesToAverage() const
Gets the number of sample to average.
Tachometer(Tachometer &&)=default
Tachometer(std::shared_ptr< DigitalSource > source)
Constructs a new tachometer.
int GetEdgesPerRevolution() const
Gets the number of edges per revolution.
Tachometer(DigitalSource &source)
Constructs a new tachometer.
bool GetStopped() const
Gets if the tachometer is stopped.
~Tachometer() override=default
void SetUpdateWhenEmpty(bool updateWhenEmpty)
Sets if to update when empty.
A move-only C++ wrapper around a HAL handle.
Definition Types.h:96
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 CAN.h:11