Product
S
Op
REVrobotics/SPARK-MAX-ExamplesPublic
master
Latest commit 1fd3ac8 on Feb 5, 2019 History
1 contributor
62 lines (53 sloc) 2.33 KB
/*----------------------------------------------------------------------------*/
/* Copyright (c) 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.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
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 Joystick m_leftStick;
private Joystick m_rightStick;
private static final int leftDeviceID = 1;
private static final int rightDeviceID = 2;
private CANSparkMax m_leftMotor;
private CANSparkMax m_rightMotor;
@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);
/**
* The RestoreFactoryDefaults method can be used to reset the configuration parameters
* in the SPARK MAX to their factory default state. If no argument is passed, these
* parameters will not persist between power cycles
*/
m_leftMotor.restoreFactoryDefaults();
m_rightMotor.restoreFactoryDefaults();
m_myRobot = new DifferentialDrive(m_leftMotor, m_rightMotor);
m_leftStick = new Joystick(0);
m_rightStick = new Joystick(1);
}
@Override
public void teleopPeriodic() {
m_myRobot.tankDrive(m_leftStick.getY(), m_rightStick.getY());
}
}
© 2023 GitHub, Inc.
SPARK-MAX-Examples/Robot.java at master · REVrobotics/SPARK-MAX-Examples · GitHub