REVLib - C++
ServoHub.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 REV Robotics
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of REV Robotics nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#pragma once
30
31#include <stdint.h>
32
33#include <vector>
34
35#include "rev/REVLibError.h"
36#include "rev/ServoChannel.h"
40
41namespace rev::servohub {
42
43class ServoHub : public ServoHubLowLevel {
44 friend class ServoHubSim;
45
46public:
56
57public:
63 explicit ServoHub(int deviceID);
64
68 ~ServoHub() override;
69
71
85 ServoHubConfig& config,
87
106 ServoHubConfig& config,
108
115 bool HasActiveFault() const;
116
123 bool HasStickyFault() const;
124
131 bool HasActiveWarning() const;
132
139 bool HasStickyWarning() const;
140
141 struct Faults {
146 uint16_t rawBits;
147
148 explicit Faults(uint16_t faults);
149 };
150
157 Faults GetFaults() const;
158
168 Faults GetStickyFaults() const;
169
170 struct Warnings {
181 uint16_t rawBits;
182
183 explicit Warnings(uint16_t warnings);
184 };
185
192 Warnings GetWarnings() const;
193
204
211
215 double GetDeviceVoltage() const;
216
220 double GetDeviceCurrent() const;
221
225 double GetServoVoltage() const;
226
234
235 enum class Bank { kBank0_2 = 0, kBank3_5 = 1 };
236
244 REVLibError SetBankPulsePeriod(Bank bank, int pulsePeriod_us);
245
246private:
247 std::vector<ServoChannel> m_servoChannels;
248};
249
250} // namespace rev::servohub
Definition: ServoChannel.h:39
ChannelId
Definition: ServoChannel.h:48
Definition: ServoHubConfigAccessor.h:35
Definition: ServoHubConfig.h:39
Definition: ServoHub.h:43
REVLibError ClearFaults()
Definition: ServoHub.cpp:165
Warnings GetWarnings() const
Definition: ServoHub.cpp:149
bool HasActiveWarning() const
Definition: ServoHub.cpp:90
double GetDeviceCurrent() const
Definition: ServoHub.cpp:179
Warnings GetStickyWarnings() const
Definition: ServoHub.cpp:157
bool HasStickyFault() const
Definition: ServoHub.cpp:83
REVLibError Configure(ServoHubConfig &config, ResetMode resetMode=ResetMode::kNoResetSafeParameters)
Definition: ServoHub.cpp:54
REVLibError ConfigureAsync(ServoHubConfig &config, ResetMode resetMode=ResetMode::kNoResetSafeParameters)
Definition: ServoHub.cpp:67
REVLibError SetBankPulsePeriod(Bank bank, int pulsePeriod_us)
Definition: ServoHub.cpp:203
Bank
Definition: ServoHub.h:235
bool HasStickyWarning() const
Definition: ServoHub.cpp:97
ServoHub(int deviceID)
Definition: ServoHub.cpp:40
~ServoHub() override
Definition: ServoHub.cpp:52
ServoChannel & GetServoChannel(ServoChannel::ChannelId channelId)
Definition: ServoHub.cpp:196
Faults GetFaults() const
Definition: ServoHub.cpp:113
ResetMode
Definition: ServoHub.h:70
double GetServoVoltage() const
Definition: ServoHub.cpp:186
bool HasActiveFault() const
Definition: ServoHub.cpp:76
Faults GetStickyFaults() const
Definition: ServoHub.cpp:121
ServoHubConfigAccessor configAccessor
Definition: ServoHub.h:55
double GetDeviceVoltage() const
Definition: ServoHub.cpp:172
Definition: ServoHubLowLevel.h:39
Definition: ServoHubSim.h:41
Definition: ServoChannelConfig.h:34
REVLibError
Definition: REVLibError.h:33
Definition: ServoHub.h:141
bool lowBattery
Definition: ServoHub.h:145
bool hardware
Definition: ServoHub.h:143
bool regulatorPowerGood
Definition: ServoHub.h:142
bool firmware
Definition: ServoHub.h:144
uint16_t rawBits
Definition: ServoHub.h:146
Faults(uint16_t faults)
Definition: ServoHub.cpp:104
Definition: ServoHub.h:170
bool hasReset
Definition: ServoHub.h:174
bool channel0Overcurrent
Definition: ServoHub.h:175
bool channel2Overcurrent
Definition: ServoHub.h:177
Warnings(uint16_t warnings)
Definition: ServoHub.cpp:129
bool channel4Overcurrent
Definition: ServoHub.h:179
bool channel3Overcurrent
Definition: ServoHub.h:178
bool canBusOff
Definition: ServoHub.h:173
bool canWarning
Definition: ServoHub.h:172
bool brownout
Definition: ServoHub.h:171
bool channel1Overcurrent
Definition: ServoHub.h:176
bool channel5Overcurrent
Definition: ServoHub.h:180
uint16_t rawBits
Definition: ServoHub.h:181