[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

@@ -158,11 +158,28 @@ ExpansionHubPositionConstants& ExpansionHubMotor::GetPositionConstants() {
return m_positionConstants;
}
void ExpansionHubMotor::Follow(const ExpansionHubMotor& leader) {
void ExpansionHubMotor::Follow(const ExpansionHubMotor& leader,
FollowDirection direction) {
if (m_hub.GetUsbId() != leader.m_hub.GetUsbId()) {
throw WPILIB_MakeError(err::InvalidParameter,
"Cannot follow motor on different hub");
}
if (m_channel == leader.m_channel) {
throw WPILIB_MakeError(err::InvalidParameter, "Cannot follow self");
}
m_hub.AddFollower(leader.m_channel, m_channel);
SetEnabled(true);
m_modePublisher.Set(kFollowerMode);
m_setpointPublisher.Set(leader.m_channel);
if (direction == FollowDirection::Opposed) {
m_setpointPublisher.Set(leader.m_channel + 4);
} else {
m_setpointPublisher.Set(leader.m_channel);
}
}
void ExpansionHubMotor::Unfollow() {
m_hub.RemoveFollower(m_channel);
SetEnabled(false);
m_modePublisher.Set(kPercentageMode);
m_setpointPublisher.Set(0);
}