New Spark Max NEO Motors Brushless Tank Drive Not working

I’ve been trying to program the tank drive for a couple days. All the motor’s firmware is updated and CAN IDs are matched…for some reason the motors won’t move at all.

/----------------------------------------------------------------------------/
/* Copyright © 2017-2018 FIRST. All Rights Reserved. /
/
Open Source Software - may be modified and shared by FRC teams. The code /
/
must be accompanied by the FIRST BSD license file in the root directory of /
/
the project. /
/
----------------------------------------------------------------------------*/

package frc.robot;

import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.SpeedControllerGroup;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.GenericHID.Hand;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;

import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;

public class Robot extends TimedRobot {
private DifferentialDrive m_myRobot;
//private SpeedControllerGroup m_leftDrive;
//private SpeedControllerGroup m_rightDrive;
private static final int leftDeviceID = 0;
private static final int rightDeviceID = 1;
private static final int leftDeviceID2 = 2;
private static final int rightDeviceID2 = 3;

private CANSparkMax m_leftMotor;
private CANSparkMax m_rightMotor;
private CANSparkMax m_leftMotor2;
private CANSparkMax m_rightMotor2;

private Spark intake;
private Spark intake2;
private XboxController gamePad;

private Spark lift;

private DoubleSolenoid Solenoid_break;
private DoubleSolenoid Claw;
@Override
public void robotInit() {
/**

  • SPARK MAX controllers are intialized over CAN by constructing a CANSparkMax object
  • The CAN ID, which can be configured using the SPARK MAX Client, is passed as the
  • first parameter
  • The motor type is passed as the second parameter. Motor type can either be:
  • com.revrobotics.CANSparkMaxLowLevel.MotorType.kBrushless
  • com.revrobotics.CANSparkMaxLowLevel.MotorType.kBrushed
  • The example below initializes four brushless motors with CAN IDs 1 and 2. Change
  • these parameters to match your setup
    */
    m_leftMotor = new CANSparkMax(leftDeviceID, MotorType.kBrushless);
    m_rightMotor = new CANSparkMax(rightDeviceID, MotorType.kBrushless);
m_leftMotor2 = new CANSparkMax(leftDeviceID2, MotorType.kBrushless);
m_rightMotor2 = new CANSparkMax(rightDeviceID2, MotorType.kBrushless);

SpeedControllerGroup m_left = new SpeedControllerGroup(m_leftMotor, m_leftMotor2);
SpeedControllerGroup m_right = new SpeedControllerGroup(m_rightMotor, m_rightMotor2);

m_myRobot = new DifferentialDrive(m_left, m_right);
m_myRobot.setExpiration(Robot.kDefaultPeriod); 
intake = new Spark(4);


intake2 = new Spark(5);
lift= new Spark(6);
Claw= new DoubleSolenoid(1,2); 
//Solenoid_break= new DoubleSolenoid(1,2); 

// Initialize a single gamepad controller
gamePad = new XboxController(0);
}

@Override
public void teleopPeriodic() {

 // Tank drive controlled with the left and right joysticks of the gamepad
 m_myRobot.tankDrive(gamePad.getRawAxis(1), gamePad.getRawAxis(3));

 // If the gamepad's right bumper is held, run the intake at 50% power
 if(gamePad.getRawButton(6)) {
     intake.set(0.5);
     intake2.set(0.5);
   } else if(gamePad.getRawButton(8)) {
       intake.set(-0.5);
       intake2.set(-0.5);
     } else {
       intake.set(0);
       intake2.set(0);
 }
 //Elevator Lift
 if(gamePad.getRawButton(5)) {
  lift.set(0.5);
 } else if(gamePad.getRawButton(7)) {
  lift.set(-0.5);
 }else {
  lift.set(0);
 }
 //Breaking System According to the Binder
 if(gamePad.getRawButton(2)) {
  Claw.set(DoubleSolenoid.Value.kForward);
 }else if (gamePad.getRawButton(3)) {
   Claw.set(DoubleSolenoid.Value.kReverse);
  }
 }

}

A warning has also popped up
Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:273): Loop time of 0.02s overrun

Personally, I don’t see any issues with the programming which makes me think the Spark Max’s are either connected wrong or are bugged. What colors do the Spark Max’s light up as?

Magenta

I think an issue may be that you have loops inside of teleopPeriodic() and its causing the drive train not to be updated often enough.

Ah how do I fix that?

Watchdog not fed within 0.020000s
Loop time of 0.02s overrun
Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:273): Loop time of 0.02s overrun
Starting live window mode.
Default testInit() method… Overload me!
Default testPeriodic() method… Overload me!

I would comment out all other lines in teleopPeriodic() than m_myRobot.tankDrive just to test if it works.

The warning disappeared…

Is there a way to make it work with the loops?

Yes, its a certain type of programming called command-based which will allow you to use different subsystems at the same time.

I recommend reading this:
https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599732-what-is-command-based-programming

Ah okay thanks. Is that the only way to be able to make the tank work?

No, but iterativerative-based programming shouldn’t really be used unless testing a specific subsystem.