Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions robotpyExamples/DifferentialDriveBot/drivetrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def __init__(self) -> None:
self.rightFollower = wpilib.PWMSparkMax(4)

# Make sure both motors for each side are in the same group
self.leftLeader.addFollower(self.leftFollower)
self.rightLeader.addFollower(self.rightFollower)
self.leftFollower.follow(self.leftLeader)
self.rightFollower.follow(self.rightLeader)

# We need to invert one side of the drivetrain so that positive voltages
# result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def __init__(self, cameraToObjectTopic: ntcore.DoubleArrayTopic) -> None:

self.imu.resetYaw()

self.leftLeader.addFollower(self.leftFollower)
self.rightLeader.addFollower(self.rightFollower)
self.leftFollower.follow(self.leftLeader)
self.rightFollower.follow(self.rightLeader)

# We need to invert one side of the drivetrain so that positive voltages
# result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def __init__(self) -> None:
self.right1 = wpilib.PWMVictorSPX(constants.kRightMotor1Port)
self.right2 = wpilib.PWMVictorSPX(constants.kRightMotor2Port)

self.left1.addFollower(self.left2)
self.right1.addFollower(self.right2)
self.left2.follow(self.left1)
self.right2.follow(self.right1)

# We need to invert one side of the drivetrain so that positive velocities
# result in both sides moving forward. Depending on how your robot's
Expand Down
4 changes: 2 additions & 2 deletions robotpyExamples/RapidReactCommandBot/subsystems/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def __init__(self) -> None:
DriveConstants.kS, DriveConstants.kV, DriveConstants.kA
)

self.leftLeader.addFollower(self.leftFollower)
self.rightLeader.addFollower(self.rightFollower)
self.leftFollower.follow(self.leftLeader)
self.rightLeader.follow(self.rightFollower)

# We need to invert one side of the drivetrain so that positive voltages
# result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def __init__(self) -> None:
)

# Subsystem constructor.
self.leftLeader.addFollower(self.leftFollower)
self.rightLeader.addFollower(self.rightFollower)
self.leftFollower.follow(self.leftLeader)
self.rightLeader.follow(self.rightFollower)

# We need to invert one side of the drivetrain so that positive voltages
# result in both sides moving forward. Depending on how your robot's
Expand Down
4 changes: 2 additions & 2 deletions robotpyExamples/SysId/subsystems/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def __init__(self) -> None:
)

# Add the second motors on each side of the drivetrain
self.left_motor.addFollower(PWMSparkMax(DriveConstants.kLeftMotor2Port))
self.right_motor.addFollower(PWMSparkMax(DriveConstants.kRightMotor2Port))
PWMSparkMax(DriveConstants.kLeftMotor2Port).follow(self.left_motor)
PWMSparkMax(DriveConstants.kRightMotor2Port).follow(self.right_motor)

# We need to invert one side of the drivetrain so that positive voltages
# result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ void PWMMotorController::EnableDeadbandElimination(bool eliminateDeadband) {
m_eliminateDeadband = eliminateDeadband;
}

void PWMMotorController::AddFollower(PWMMotorController& follower) {
m_nonowningFollowers.emplace_back(&follower);
}

PWMMotorController::PWMMotorController(std::string_view name, int channel)
: m_pwm(channel, false) {
wpi::util::SendableRegistry::Add(this, name, channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MotorController;
* These drive bases typically have drop-center / skid-steer with two or more
* wheels per side (e.g., 6WD or 8WD). This class takes a setter per side. For
* four and six motor drivetrains, use CAN motor controller followers or
* PWMMotorController::AddFollower().
* PWMMotorController::Follow().
*
* A differential drive robot has left and right wheels separated by an
* arbitrary width.
Expand Down Expand Up @@ -73,7 +73,7 @@ class DifferentialDrive : public RobotDriveBase,
* Construct a DifferentialDrive.
*
* To pass multiple motors per side, use CAN motor controller followers or
* PWMMotorController::AddFollower(). If a motor needs to be inverted, do so
* PWMMotorController::Follow(). If a motor needs to be inverted, do so
* before passing it in.
*
* @param leftMotor Left motor.
Expand All @@ -85,7 +85,7 @@ class DifferentialDrive : public RobotDriveBase,
* Construct a DifferentialDrive.
*
* To pass multiple motors per side, use CAN motor controller followers or
* PWMMotorController::AddFollower(). If a motor needs to be inverted, do so
* PWMMotorController::Follow(). If a motor needs to be inverted, do so
* before passing it in.
*
* @param leftMotor Left motor setter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

#pragma once

#include <concepts>
#include <memory>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>

#include "wpi/hal/SimDevice.hpp"
Expand Down Expand Up @@ -70,21 +67,12 @@ class PWMMotorController
void EnableDeadbandElimination(bool eliminateDeadband);

/**
* Make the given PWM motor controller follow the output of this one.
* Make the this PWM motor controller follow the output of the given one.
*
* @param follower The motor controller follower.
* @param leader The motor controller to follow.
*/
void AddFollower(PWMMotorController& follower);

/**
* Make the given PWM motor controller follow the output of this one.
*
* @param follower The motor controller follower.
*/
template <std::derived_from<PWMMotorController> T>
void AddFollower(T&& follower) {
m_owningFollowers.emplace_back(
std::make_unique<std::decay_t<T>>(std::forward<T>(follower)));
void Follow(PWMMotorController& leader) & {
leader.m_nonowningFollowers.push_back(this);
}

protected:
Expand Down
2 changes: 1 addition & 1 deletion wpilibc/src/main/python/semiwrap/PWMMotorController.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ classes:
GetDescription:
GetChannel:
EnableDeadbandElimination:
AddFollower:
Follow:
overloads:
PWMMotorController&:
keepalive:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
class Drivetrain {
public:
Drivetrain() {
leftLeader.AddFollower(leftFollower);
rightLeader.AddFollower(rightFollower);
leftFollower.Follow(leftLeader);
rightFollower.Follow(rightLeader);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include "wpi/system/RobotController.hpp"

Drivetrain::Drivetrain() {
leftLeader.AddFollower(leftFollower);
rightLeader.AddFollower(rightFollower);
leftFollower.Follow(leftLeader);
rightFollower.Follow(rightLeader);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ DriveSubsystem::DriveSubsystem()
wpi::util::SendableRegistry::AddChild(&drive, &left1);
wpi::util::SendableRegistry::AddChild(&drive, &right1);

left1.AddFollower(left2);
right1.AddFollower(right2);
left2.Follow(left1);
right2.Follow(right1);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ DriveSubsystem::DriveSubsystem()
wpi::util::SendableRegistry::AddChild(&drive, &left1);
wpi::util::SendableRegistry::AddChild(&drive, &right1);

left1.AddFollower(left2);
right1.AddFollower(right2);
left2.Follow(left1);
right2.Follow(right1);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Drive::Drive() {
wpi::util::SendableRegistry::AddChild(&drive, &leftLeader);
wpi::util::SendableRegistry::AddChild(&drive, &rightLeader);

leftLeader.AddFollower(leftFollower);
rightLeader.AddFollower(rightFollower);
leftFollower.Follow(leftLeader);
rightFollower.Follow(rightLeader);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Drivetrain {
Drivetrain() {
imu.ResetYaw();

leftLeader.AddFollower(leftFollower);
rightLeader.AddFollower(rightFollower);
leftFollower.Follow(leftLeader);
rightFollower.Follow(rightLeader);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include "wpi/commands2/Commands.hpp"

Drive::Drive() {
leftMotor.AddFollower(wpi::PWMSparkMax{constants::drive::kLeftMotor2Port});
rightMotor.AddFollower(wpi::PWMSparkMax{constants::drive::kRightMotor2Port});
leftFollower.Follow(leftLeader);
rightFollower.Follow(rightLeader);

rightMotor.SetInverted(true);
rightLeader.SetInverted(true);

leftEncoder.SetDistancePerPulse(
constants::drive::kEncoderDistancePerPulse.value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ class Drive : public wpi::cmd::SubsystemBase {
wpi::cmd::CommandPtr SysIdDynamic(wpi::cmd::sysid::Direction direction);

private:
wpi::PWMSparkMax leftMotor{constants::drive::kLeftMotor1Port};
wpi::PWMSparkMax rightMotor{constants::drive::kRightMotor1Port};
wpi::PWMSparkMax leftLeader{constants::drive::kLeftMotor1Port};
wpi::PWMSparkMax rightLeader{constants::drive::kRightMotor1Port};
wpi::PWMSparkMax leftFollower{constants::drive::kLeftMotor2Port};
wpi::PWMSparkMax rightFollower{constants::drive::kRightMotor2Port};
wpi::DifferentialDrive drive{
[this](auto val) { leftMotor.SetThrottle(val); },
[this](auto val) { rightMotor.SetThrottle(val); }};

[this](auto val) { leftLeader.SetThrottle(val); },
[this](auto val) { rightLeader.SetThrottle(val); }};
wpi::Encoder leftEncoder{constants::drive::kLeftEncoderPorts[0],
constants::drive::kLeftEncoderPorts[1],
constants::drive::kLeftEncoderReversed};
Expand All @@ -43,18 +44,18 @@ class Drive : public wpi::cmd::SubsystemBase {
nullptr},
wpi::cmd::sysid::Mechanism{
[this](wpi::units::volt_t driveVoltage) {
leftMotor.SetVoltage(driveVoltage);
rightMotor.SetVoltage(driveVoltage);
leftLeader.SetVoltage(driveVoltage);
rightLeader.SetVoltage(driveVoltage);
},
[this](wpi::sysid::SysIdRoutineLog* log) {
log->Motor("drive-left")
.voltage(leftMotor.GetThrottle() *
.voltage(leftLeader.GetThrottle() *
wpi::RobotController::GetBatteryVoltage())
.position(wpi::units::meter_t{leftEncoder.GetDistance()})
.velocity(
wpi::units::meters_per_second_t{leftEncoder.GetRate()});
log->Motor("drive-right")
.voltage(rightMotor.GetThrottle() *
.voltage(rightLeader.GetThrottle() *
wpi::RobotController::GetBatteryVoltage())
.position(wpi::units::meter_t{rightEncoder.GetDistance()})
.velocity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Robot : public wpi::TimedRobot {
// other side
rightLeader.SetInverted(true);
// Configure the followers to follow the leaders
leftLeader.AddFollower(leftFollower);
rightLeader.AddFollower(rightFollower);
leftFollower.Follow(leftLeader);
rightFollower.Follow(rightLeader);
}
void AutonomousPeriodic() override {
// Drives forward at half velocity until the robot has moved 5 feet, then
Expand Down
10 changes: 5 additions & 5 deletions wpilibj/src/main/java/org/wpilib/drive/DifferentialDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* <p>These drive bases typically have drop-center / skid-steer with two or more wheels per side
* (e.g., 6WD or 8WD). This class takes a setter per side. For four and six motor drivetrains, use
* CAN motor controller followers or {@link
* org.wpilib.hardware.motor.PWMMotorController#addFollower(PWMMotorController)}.
* org.wpilib.hardware.motor.PWMMotorController#follow(PWMMotorController)}.
*
* <p>A differential drive robot has left and right wheels separated by an arbitrary width.
*
Expand Down Expand Up @@ -94,8 +94,8 @@ public WheelVelocities(double left, double right) {
* Construct a DifferentialDrive.
*
* <p>To pass multiple motors per side, use CAN motor controller followers or {@link
* org.wpilib.hardware.motor.PWMMotorController#addFollower(PWMMotorController)}. If a motor needs
* to be inverted, do so before passing it in.
* org.wpilib.hardware.motor.PWMMotorController#follow(PWMMotorController)}. If a motor needs to
* be inverted, do so before passing it in.
*
* @param leftMotor Left motor.
* @param rightMotor Right motor.
Expand All @@ -113,8 +113,8 @@ public DifferentialDrive(MotorController leftMotor, MotorController rightMotor)
* Construct a DifferentialDrive.
*
* <p>To pass multiple motors per side, use CAN motor controller followers or {@link
* org.wpilib.hardware.motor.PWMMotorController#addFollower(PWMMotorController)}. If a motor needs
* to be inverted, do so before passing it in.
* org.wpilib.hardware.motor.PWMMotorController#follow(PWMMotorController)}. If a motor needs to
* be inverted, do so before passing it in.
*
* @param leftMotor Left motor setter.
* @param rightMotor Right motor setter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ public void enableDeadbandElimination(boolean eliminateDeadband) {
}

/**
* Make the given PWM motor controller follow the output of this one.
* Makes this motor controller follow another.
*
* @param follower The motor controller follower.
* @param leader The motor controller to follow.
*/
public void addFollower(PWMMotorController follower) {
m_followers.add(follower);
public void follow(PWMMotorController leader) {
leader.m_followers.add(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class Drivetrain {
public Drivetrain() {
imu.resetYaw();

leftLeader.addFollower(leftFollower);
rightLeader.addFollower(rightFollower);
leftFollower.follow(leftLeader);
rightFollower.follow(rightLeader);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public class Drivetrain {
public Drivetrain(DoubleArrayTopic cameraToObjectTopic) {
imu.resetYaw();

leftLeader.addFollower(leftFollower);
rightLeader.addFollower(rightFollower);
leftFollower.follow(leftLeader);
rightFollower.follow(rightLeader);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public DriveSubsystem() {
SendableRegistry.addChild(drive, leftLeader);
SendableRegistry.addChild(drive, rightLeader);

leftLeader.addFollower(leftFollower);
rightLeader.addFollower(rightFollower);
leftFollower.follow(leftLeader);
rightFollower.follow(rightLeader);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public DriveSubsystem() {
SendableRegistry.addChild(drive, leftLeader);
SendableRegistry.addChild(drive, rightLeader);

leftLeader.addFollower(leftFollower);
rightLeader.addFollower(rightFollower);
leftFollower.follow(leftLeader);
rightFollower.follow(rightLeader);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public DriveSubsystem() {
SendableRegistry.addChild(drive, leftLeader);
SendableRegistry.addChild(drive, rightLeader);

leftLeader.addFollower(leftFollower);
rightLeader.addFollower(rightFollower);
leftFollower.follow(leftLeader);
rightFollower.follow(rightLeader);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public Drive() {
SendableRegistry.addChild(drive, leftLeader);
SendableRegistry.addChild(drive, rightLeader);

leftLeader.addFollower(leftFollower);
rightLeader.addFollower(rightFollower);
leftFollower.follow(leftLeader);
rightFollower.follow(rightLeader);

// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
Expand Down
Loading
Loading