WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
ExpansionHubCRServo.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
7#include <memory>
8
12#include "wpi/units/time.hpp"
13
14namespace wpi {
15
16/** This class controls a specific servo in continuous rotation mode hooked up
17 * to an ExpansionHub. */
19 public:
20 /**
21 * Constructs a continuous rotation servo at the requested channel on a
22 * specific USB port.
23 *
24 * @sa ExpansionHubServo for a servo mode, or non-continuous rotation servo
25 * @param usbId The USB port ID the hub is connected to
26 * @param channel The servo channel
27 */
28 ExpansionHubCRServo(int usbId, int channel);
30
31 /**
32 * Set the servo throttle.
33 *
34 * Throttle values range from -1.0 to 1.0 corresponding to full reverse to
35 * full forward.
36 *
37 * @param value Throttle from -1.0 to 1.0.
38 */
39 void SetThrottle(double value);
40
41 /**
42 * Sets the raw pulse width output on the servo.
43 *
44 * @param pulseWidth Pulse width
45 */
46 void SetPulseWidth(wpi::units::microsecond_t pulseWidth);
47
48 /**
49 * Sets if the servo output is enabled or not. Defaults to false.
50 *
51 * @param enabled True to enable, false to disable
52 */
53 void SetEnabled(bool enabled);
54
55 /**
56 * Sets the frame period for the servo. Defaults to 20ms.
57 *
58 * @param framePeriod The frame period
59 */
60 void SetFramePeriod(wpi::units::microsecond_t framePeriod);
61
62 /**
63 * Gets if the underlying ExpansionHub is connected.
64 *
65 * @return True if hub is connected, otherwise false
66 */
67 bool IsHubConnected() const { return m_hub.IsHubConnected(); }
68
69 /**
70 * Sets the PWM range for the servo.
71 * By default, this is 600 to 2400 microseconds.
72 *
73 * Maximum must be greater than minimum.
74 *
75 * @param minPwm Minimum PWM
76 * @param maxPwm Maximum PWM
77 */
78 void SetPWMRange(wpi::units::microsecond_t minPwm,
79 wpi::units::microsecond_t maxPwm);
80
81 /**
82 * Sets whether the servo is reversed.
83 *
84 * This will reverse SetThrottle.
85 *
86 * @param reversed True to reverse, false for normal
87 */
88 void SetReversed(bool reversed);
89
90 private:
91 wpi::units::microsecond_t GetFullRangeScaleFactor() const;
92
93 ExpansionHub m_hub;
94 int m_channel;
95
96 wpi::units::microsecond_t m_minPwm = 600_us;
97 wpi::units::microsecond_t m_maxPwm = 2400_us;
98
99 bool m_reversed = false;
100
101 wpi::nt::IntegerPublisher m_pulseWidthPublisher;
102 wpi::nt::IntegerPublisher m_framePeriodPublisher;
103 wpi::nt::BooleanPublisher m_enabledPublisher;
104};
105} // namespace wpi
bool IsHubConnected() const
Gets if the underlying ExpansionHub is connected.
Definition ExpansionHubCRServo.hpp:67
ExpansionHubCRServo(int usbId, int channel)
Constructs a continuous rotation servo at the requested channel on a specific USB port.
void SetPulseWidth(wpi::units::microsecond_t pulseWidth)
Sets the raw pulse width output on the servo.
void SetThrottle(double value)
Set the servo throttle.
void SetEnabled(bool enabled)
Sets if the servo output is enabled or not.
void SetFramePeriod(wpi::units::microsecond_t framePeriod)
Sets the frame period for the servo.
~ExpansionHubCRServo() noexcept
void SetPWMRange(wpi::units::microsecond_t minPwm, wpi::units::microsecond_t maxPwm)
Sets the PWM range for the servo.
void SetReversed(bool reversed)
Sets whether the servo is reversed.
This class controls a REV ExpansionHub plugged in over USB to Systemcore.
Definition ExpansionHub.hpp:18
NetworkTables Boolean publisher.
Definition BooleanTopic.hpp:126
NetworkTables Integer publisher.
Definition IntegerTopic.hpp:126
Definition CvSource.hpp:15