We are having problems with very basic run of SparkMax controller driving a NEO brushless. Buttons OFTEN don’t fire the motor. SparkMax has been restored to factory setting using SparkMax Client, firmware updated. Understand there could be other reasons, but we want to rule out any issue with the code. We stripped the code down to minimum as below (some lines omitted). Is there anything missing / wrong here?
Any advice is appreciated.
Robot.java:
public class Robot extends TimedRobot {
private static RobotContainer m_robotContainer;
@Override
public void robotInit() {
m_robotContainer = new RobotContainer();
}
@Override
public void robotPeriodic() {
CommandScheduler.getInstance().run();
}
}
RobotContainer.java:
public class RobotContainer {
private final Arm m_arm = new Arm();
final XboxController xbox = new XboxController(XBOX_CTRL_PORT);
public RobotContainer() {
configureButtonBindings();
m_arm.reset();
}
private void configureButtonBindings() {
final JoystickButton btnArmDown = new JoystickButton(xbox, Button.kY.value); // Y button
btnArmDown.whenPressed( new ArmDown(m_arm, () -> !btnArmDown.get()) );
final JoystickButton btnArmUp = new JoystickButton(xbox, Button.kB.value); // B button
btnArmUp.whenPressed( new ArmUp(m_arm, () -> !btnArmUp.get()) );
}
}
Subsystem - Arm.java:
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class Arm extends SubsystemBase {
private final CANSparkMax m_spark = new CANSparkMax(ARM_SPARK_ID, MotorType.kBrushless);
public void raise() {
m_spark.set(-ARM_MAX_SPEED);
}
public void lower() {
m_spark.set(ARM_MAX_SPEED);
}
public void stop() {
m_spark.set(0);
}
public void reset() {
m_spark.restoreFactoryDefaults(); // should we call burnFlash() after this line?
}
@Override
public void periodic() {
}
}
Command - ArmUp.java:
public class ArmUp extends WaitUntilCommand {
private Arm m_arm;
public ArmUp(Arm subsystem, BooleanSupplier btnState) {
super(btnState);
addRequirements(subsystem);
m_arm = subsystem;
}
@Override
public void initialize() { }
@Override
public void execute() {
m_arm.raise();
}
@Override
public void end(boolean interrupted) {
m_arm.stop();
}
}
ArmDown.java all the same except calling m_arm.lower().
Instead of extending WaitUntilCommand and using the joystick button as the supplier, just extend CommandBase. By default isFinished will return false which is fine for this use case. Then you will want to use whileHeld rather than whenPressed so that the command will be scheduled continuously while the button is held, and canceled when it is released.
WaitUntilCommand is meant to be used as an easy wrapper for a command that you want to run until an external condition (like a sensor reporting a value, not a joystick) returns true.
The command change worked as expected in terms of firing the motor, thanks!
Unfortunately for other reasons we don’t really understand yet, the motor was not able to raise our intake arm successfully. It could been mechanical or electrical reasons, basically we are not familiar with NEO/SparkMax combo yet to make a determination. We eventually walked away and picked a mini CIM with a higher reduction gearbox and the arm now works fine.
Yeah, we are following Everybot. The NEO has a 16:1 gearbox, driving a 12-T sprocket which is chained onto a 60-T sprocket (so to me that’s another 5:1 reduction). NEO is factory default setting, i.e. current limit is 80A (I heard some other team had issue raising arm because current limit was only at 10A). We did notice something not as smooth in the mechanics but I believe we resolved it (or at least significantly improved it). Code is also the most basic, sending full voltage in the command…not sure why it wouldn’t raise.
Yes, we double checked, button assignments were verified, was able to lower arm with one button, the other one is for going up but we can see/hear motor was stalling…
I would check once more that the arm is able to move freely. We are driving our arm through a 20:1 maxplanetary and a 15t to 54t sprocket (overall reduction 72:1) and our NEO is having no problem lifting the arm.
Interesting…what we did was taking down the connecting bar from the large sprocket, motor moves freely both way per button assignments and set values. Once it’s mounted back on, motor can’t raise it. So, even though our overall reduction (16:1 gear x 60t:12t = 80:1) is more than yours, gearbox is lower…could that be the reason (barring other mechanical issue)?
No, that shouldn’t be the issue. Try moving the arm up and down with the linkage connected. It should move pretty smoothly with only the slight resistance of the motor. If it takes any excessive force to get the arm to move, you have binding/friction somewhere in your linkage past the first link.
I was wondering what kind of arm your robot has, since it might be that yours is lighter? We are following the Everybot design, The Robonauts 118 Everybot 2022 - YouTube.