The original Java CansparkMax command has been depreciated
that I used last year with no problem. Does anyone know the
new syntax for 2024? Is there a code example for 4 motor drive
that you could reference? Thank You.
Have you imported RevLib for 2024? That is probably your issue?
Anyway, here is your example:
package frc.robot;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkLowLevel.MotorType;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
/**
* This is a demo program showing the use of the DifferentialDrive class, specifically it contains
* the code necessary to operate a robot with tank drive.
*/
public class Robot extends TimedRobot {
private DifferentialDrive m_robotDrive;
private Joystick m_leftStick;
private Joystick m_rightStick;
private final CANSparkMax m_leftMotor = new CANSparkMax(0, MotorType.kBrushless);
private final CANSparkMax m_rightMotor = new CANSparkMax(1, MotorType.kBrushless);
private final CANSparkMax m_leftMotor2 = new CANSparkMax(2, MotorType.kBrushless);
private final CANSparkMax m_rightMotor2 = new CANSparkMax(3, MotorType.kBrushless);
@Override
public void robotInit() {
SendableRegistry.addChild(m_robotDrive, m_leftMotor);
SendableRegistry.addChild(m_robotDrive, m_rightMotor);
// 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
// gearbox is constructed, you might have to invert the left side instead.
m_rightMotor.setInverted(true);
m_rightMotor2.setInverted(true);
m_leftMotor2.follow(m_leftMotor);
m_rightMotor2.follow(m_rightMotor);
m_robotDrive = new DifferentialDrive(m_leftMotor::set, m_rightMotor::set);
m_leftStick = new Joystick(0);
m_rightStick = new Joystick(1);
}
@Override
public void teleopPeriodic() {
m_robotDrive.tankDrive(-m_leftStick.getY(), -m_rightStick.getY());
}
}
Thank you very much.
I installed new rev library 2024. I thought I had completed that.
Thanks
1 Like
To complete making those instances, the second argument in the constructor should be ControlType.kBrushless
or ControlType.kBrushed
.
To set the power on a motor, you will call set()
.
1 Like
MB bro I was not connected to the Robo RIO I am a noob
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.