[wpilib] ExHub Follower Fixes (#8892)

A chunk of updates to followers on Expansion Hub

Fixes followers not implicitly enabling.
Allows followers to follow other followers
Throws exceptions on construction if a follower cycle is detected.
Allows reversing followers.

The enable thing will fix
https://github.com/wpilibsuite/SystemcoreTesting/discussions/259#discussioncomment-16886195

Closes #8843

Depends on https://github.com/wpilibsuite/scservices/pull/30
This commit is contained in:
Thad House
2026-05-14 21:50:38 -07:00
committed by GitHub
parent b91001f504
commit 3f1cf3cabe
9 changed files with 260 additions and 5 deletions

View File

@@ -79,6 +79,9 @@ class ExpansionHub {
bool CheckAndReserveMotor(int channel);
void UnreserveMotor(int channel);
void AddFollower(int leaderChannel, int followerChannel);
void RemoveFollower(int followerChannel);
void ReportUsage(std::string_view device, std::string_view data);
class DataStore;

View File

@@ -19,6 +19,14 @@ namespace wpi {
* ExpansionHub. */
class ExpansionHubMotor {
public:
/** The direction to follow a leader motor in when using the follow method. */
enum class FollowDirection {
/** Follow the leader motor in the same direction. */
Aligned,
/** Follow the leader motor in the opposite direction. */
Opposed
};
/**
* Constructs a servo at the requested channel on a specific USB port.
*
@@ -144,8 +152,14 @@ class ExpansionHubMotor {
* Additionally, the direction of both motors will be the same.
*
* @param leader The motor to follow
* @param direction The direction to follow the leader
*/
void Follow(const ExpansionHubMotor& leader);
void Follow(const ExpansionHubMotor& leader, FollowDirection direction);
/**
* Stops following the currently set leader motor.
*/
void Unfollow();
private:
ExpansionHub m_hub;