WPILibC++ 2023.4.3
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/Types.h>
11#include <units/frequency.h>
12#include <units/time.h>
15
16namespace frc {
17class DigitalSource;
18
19/**
20 * Tachometer for getting rotational speed from a device.
21 *
22 * <p>The Tachometer class measures the time between digital pulses to
23 * determine the rotation speed of a mechanism. Examples of devices that could
24 * be used with the tachometer class are a hall effect sensor, break beam
25 * sensor, or optical sensor detecting tape on a shooter wheel. Unlike
26 * encoders, this class only needs a single digital input.
27 */
29 public wpi::SendableHelper<Tachometer> {
30 public:
31 /**
32 * Constructs a new tachometer.
33 *
34 * @param source The source.
35 */
37
38 /**
39 * Constructs a new tachometer.
40 *
41 * @param source The source.
42 */
43 explicit Tachometer(std::shared_ptr<DigitalSource> source);
44
45 ~Tachometer() override;
46
47 Tachometer(Tachometer&&) = default;
49
50 /**
51 * Gets the tachometer frequency.
52 *
53 * @return Current frequency.
54 */
55 units::hertz_t GetFrequency() const;
56
57 /**
58 * Gets the tachometer period.
59 *
60 * @return Current period.
61 */
62 units::second_t GetPeriod() const;
63
64 /**
65 * Gets the number of edges per revolution.
66 *
67 * @return Edges per revolution.
68 */
70
71 /**
72 * Sets the number of edges per revolution.
73 *
74 * @param edges Edges per revolution.
75 */
76 void SetEdgesPerRevolution(int edges);
77
78 /**
79 * Gets the current tachometer revolutions per second.
80 *
81 * SetEdgesPerRevolution must be set with a non 0 value for this to work.
82 *
83 * @return Current RPS.
84 */
85 units::turns_per_second_t GetRevolutionsPerSecond() const;
86
87 /**
88 * Gets the current tachometer revolutions per minute.
89 *
90 * SetEdgesPerRevolution must be set with a non 0 value for this to work.
91 *
92 * @return Current RPM.
93 */
94 units::revolutions_per_minute_t GetRevolutionsPerMinute() const;
95
96 /**
97 * Gets if the tachometer is stopped.
98 *
99 * @return True if the tachometer is stopped.
100 */
101 bool GetStopped() const;
102
103 /**
104 * Gets the number of sample to average.
105 *
106 * @return Samples to average.
107 */
109
110 /**
111 * Sets the number of samples to average.
112 *
113 * @param samples Samples to average.
114 */
115 void SetSamplesToAverage(int samples);
116
117 /**
118 * Sets the maximum period before the tachometer is considered stopped.
119 *
120 * @param maxPeriod The max period.
121 */
122 void SetMaxPeriod(units::second_t maxPeriod);
123
124 /**
125 * Sets if to update when empty.
126 *
127 * @param updateWhenEmpty True to update when empty.
128 */
129 void SetUpdateWhenEmpty(bool updateWhenEmpty);
130
131 protected:
132 void InitSendable(wpi::SendableBuilder& builder) override;
133
134 private:
135 std::shared_ptr<DigitalSource> m_source;
136 hal::Handle<HAL_CounterHandle> m_handle;
137 int m_edgesPerRevolution;
138 int32_t m_index;
139};
140} // 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 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:114
DigitalSource Interface.
Definition: DigitalSource.h:22
Tachometer for getting rotational speed from a device.
Definition: Tachometer.h:29
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.
~Tachometer() override
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.
void SetUpdateWhenEmpty(bool updateWhenEmpty)
Sets if to update when empty.
Definition: SendableBuilder.h:18
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:19
Interface for Sendable objects.
Definition: Sendable.h:16
::int32_t int32_t
Definition: Meta.h:57
Definition: AprilTagFieldLayout.h:22