mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user