WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
ExpansionHub.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#include <string_view>
9
10#include "wpi/util/mutex.hpp"
11
12namespace wpi {
16
17/** This class controls a REV ExpansionHub plugged in over USB to Systemcore. */
19 public:
20 /**
21 * Constructs a new ExpansionHub for a given USB ID
22 *
23 * Multiple instances can be constructed, but will point to the same backing
24 * object with a ref count.
25 *
26 * @param usbId The USB Port ID the hub is plugged into.
27 */
28 explicit ExpansionHub(int usbId);
29 ~ExpansionHub() noexcept = default;
30
31 friend class ExpansionHubServo;
32 friend class ExpansionHubMotor;
33 friend class ExpansionHubCRServo;
34
35 /**
36 * Constructs a servo at the requested channel on this hub.
37 *
38 * Only a single instance of each servo per hub can be constructed at a time.
39 *
40 * @param channel The servo channel
41 * @return Servo object
42 */
44
46
47 /**
48 * Constructs a motor at the requested channel on this hub.
49 *
50 * Only a single instance of each motor per hub can be constructed at a time.
51 *
52 * @param channel The motor channel
53 * @return Motor object
54 */
56
57 /**
58 * Gets if the hub is currently connected over USB.
59 *
60 * @return True if hub connection, otherwise false
61 */
62 bool IsHubConnected() const;
63
64 /**
65 * Gets the USB ID of this hub.
66 *
67 * @return The USB ID
68 */
69 int GetUsbId() const;
70
71 static constexpr int NumUsbPorts = 4;
72 static constexpr int NumServoPorts = 6;
73 static constexpr int NumMotorPorts = 4;
74
75 private:
76 bool CheckAndReserveServo(int channel);
77 void UnreserveServo(int channel);
78
79 bool CheckAndReserveMotor(int channel);
80 void UnreserveMotor(int channel);
81
82 void ReportUsage(std::string_view device, std::string_view data);
83
84 class DataStore;
85 friend class DataStore;
86
87 std::shared_ptr<DataStore> m_dataStore;
88
89 static wpi::util::mutex m_handleLock;
90 static std::weak_ptr<DataStore> m_storeMap[4];
91
92 static std::shared_ptr<DataStore> GetForUsbId(int usbId);
93};
94
95} // namespace wpi
basic_string_view< char > string_view
Definition base.h:620
This class controls a specific servo in continuous rotation mode hooked up to an ExpansionHub.
Definition ExpansionHubCRServo.hpp:18
friend class DataStore
Definition ExpansionHub.hpp:85
friend class ExpansionHubCRServo
Definition ExpansionHub.hpp:33
int GetUsbId() const
Gets the USB ID of this hub.
ExpansionHubCRServo MakeCRServo(int channel)
static constexpr int NumMotorPorts
Definition ExpansionHub.hpp:73
ExpansionHubServo MakeServo(int channel)
Constructs a servo at the requested channel on this hub.
static constexpr int NumUsbPorts
Definition ExpansionHub.hpp:71
bool IsHubConnected() const
Gets if the hub is currently connected over USB.
static constexpr int NumServoPorts
Definition ExpansionHub.hpp:72
ExpansionHubMotor MakeMotor(int channel)
Constructs a motor at the requested channel on this hub.
~ExpansionHub() noexcept=default
friend class ExpansionHubServo
Definition ExpansionHub.hpp:31
ExpansionHub(int usbId)
Constructs a new ExpansionHub for a given USB ID.
friend class ExpansionHubMotor
Definition ExpansionHub.hpp:32
This class controls a specific motor and encoder hooked up to an ExpansionHub.
Definition ExpansionHubMotor.hpp:20
This class controls a specific servo in positional/servo mode hooked up to an ExpansionHub.
Definition ExpansionHubServo.hpp:19
Definition StringMap.hpp:773
Definition raw_os_ostream.hpp:19
Definition CvSource.hpp:15