Help with programming NEO Motors

We just started using NEOs and while testing our practice bot, we noticed a strange control issue and were pretty sure it’s programming. despite using a simple tank drive program with plain set methods, when only one side of our robot is running the robot will always move that side forward at a constant speed, regardless of the joystick values, and we have no idea why. This also doesn’t happen when both sides are moving, which is the part that really confuses us.

Any ideas are appreciated. Thanks.

1 Like

Please post or point to your code.

2 Likes

CANSparkMax frontRight = new CANSparkMax(3, CANSparkMaxLowLevel.MotorType.kBrushless);
CANSparkMax frontLeft = new CANSparkMax(4, CANSparkMaxLowLevel.MotorType.kBrushless);
CANSparkMax backRight = new CANSparkMax(5, CANSparkMaxLowLevel.MotorType.kBrushless);
CANSparkMax backLeft = new CANSparkMax(6, CANSparkMaxLowLevel.MotorType.kBrushless);
CANEncoder leftEncoder = backLeft.getEncoder();
CANEncoder rightEncoder = backRight.getEncoder();

Joystick xbox = new Joystick(0);

@Override
public void robotInit() {
frontLeft.follow(backLeft);
frontRight.follow(backRight);
}

@Override
public void teleopPeriodic() {
if (xbox.getRawAxis(1) >= 0.15 || xbox.getRawAxis(1) <= -0.15) {
backRight.set(xbox.getRawAxis(5));
} else {
backRight.set(0);
}
if (xbox.getRawAxis(5) >= 0.15 || xbox.getRawAxis(5) <= -0.15) {
backLeft.set(-xbox.getRawAxis(1));
} else {
backLeft.set(0);
}
System.out.println("Left Speed: " + -xbox.getRawAxis(1) + " : " + leftEncoder.getVelocity() + " Right Speed: " + xbox.getRawAxis(5) + " : " + rightEncoder.getVelocity());
}

1 Like

Your if statements appear to be looking for a set deadband value (+/- 0.15) but they seem to check the opposite joystick value. i.e. if the left joystick is out of deadband, then set the right motors to the value of the right joystick axis (even if it’s 0), else if the left joystick is inside the deadband zone, then stop the right motors. And vice versa.

Is this what you intended?

3 Likes

We had a similar issue one time, our encoded broke in the controller and was returning a ”NaN” or not a number and trying to set the motor power to positive and negative infinity. This probably isn’t the problem if your motor controllers are brand new, but, make sure your encoder value is reading a real number.