Im getting a Can Timeout with this code, I’m only connecting the pcm to the can circuit
/*----------------------------------------------------------------------------*/
/* Copyright (c) 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.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.SpeedControllerGroup;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the TimedRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the build.gradle file in the
* project.
*/
public class Robot extends TimedRobot {
/**
* This function is run when the robot is first started up and should be used
* for any initialization code.
*/
//***Controllers***
public Joystick driver_Controller;
public Joystick operator_Controller1;
//#region Motores
//***Motors***
public Spark left_ChassisMaster;
public Spark left_ChassisSlave1;
public Spark left_ChassisSlave2;
public Spark right_ChassisMaster;
public Spark right_ChassisSlave1;
public Spark right_ChassisSlave2;
/*
public Spark arm_Motor1;
public Spark arm_Motor2;
*/
//***Compressor***
public Compressor airCompressor;
//***Solenoids***
//Gearbox
public DoubleSolenoid gearbox;
//***Chassis***
private DifferentialDrive driveTrain;
//***Reversa***
protected boolean reverse = false;
//Toggle
boolean toggle1 = true;
boolean toggle2 = true;
@Override
public void robotInit() {
//***Motors Id Assigned***
left_ChassisMaster = new Spark(0);
left_ChassisSlave1 = new Spark(1);
left_ChassisSlave2 = new Spark(2);
right_ChassisMaster = new Spark(3);
right_ChassisSlave1 = new Spark(4);
right_ChassisSlave2 = new Spark(5);
/*
arm_Motor1 = new Spark(1);
arm_Motor2 = new Spark(2);
*/
SpeedControllerGroup chassis_Left = new SpeedControllerGroup(left_ChassisMaster, left_ChassisSlave1, left_ChassisSlave2);
SpeedControllerGroup chassis_Right = new SpeedControllerGroup(right_ChassisMaster, right_ChassisSlave1, right_ChassisSlave2);
//***Chassis's Motors Assigned***
driveTrain = new DifferentialDrive(chassis_Left, chassis_Right);
//***Air Compressor Id Assigned***
airCompressor = new Compressor(0);
//***AirCompressor Security***
airCompressor.setClosedLoopControl(true);
//***AirCompressor Start***
airCompressor.start();
//***States Values Assigned***
airCompressor.enabled();
airCompressor.getPressureSwitchValue();
airCompressor.getCompressorCurrent();
//***Solenoid Id Assigned***
//Gearbox Assigned
gearbox = new DoubleSolenoid(0, 2, 3);
}
public void kart1()
{
//****************
double x = (driver_Controller.getRawAxis(4));
double y = -(driver_Controller.getRawAxis(1));
double r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
if (r > 1) {r = 1;}
double kLimiteX = 0.30;//75; //<<-- Sensibilidad de giro <<
double t = ((r - Math.abs(x)) * (1 - kLimiteX)) + (r * kLimiteX);
if (t > 1) { t = 1;}
reverse = false;
//***Foward & reverse***
if(y < 0)
{
double temp = -t;
t = -r;
r = temp;
reverse = true;
}
if (x < 0)
{
double temp = t;
t = r;
r = temp;
}
driveTrain.tankDrive(r,t);
}
public void kart2()
{
double x = (driver_Controller.getRawAxis(4));
double y = -(driver_Controller.getRawAxis(1));
double r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
if (r > 1) {r = 1;}
double kLimiteX = 0.30;//75; //<<-- Sensibilidad de giro <<
double t = ((r - Math.abs(x)) * (1 - kLimiteX)) + (r * kLimiteX);
if (t > 1) { t = 1;}
reverse = false;
//***Foward & reverse***
if(y < 0)
{
double temp = -t;
t = -r;
r = temp;
reverse = true;
}
if (x < 0)
{
double temp = t;
t = r;
r = temp;
}
driveTrain.tankDrive((r * 0.50) , (t * 0.50));
}
@Override
public void autonomousInit() {
}
@Override
public void autonomousPeriodic() {
}
@Override
public void teleopInit() {
}
@Override
public void teleopPeriodic() {
//#region Toggle
if(operator_Controller1.getRawButton(3)){
if(toggle2 == true){
toggle2 = false;
}
}
if(operator_Controller1.getRawButton(4)){
if(toggle2 == false){
toggle2 = true;
}
}
if(operator_Controller1.getRawButton(5)){
if(toggle1 == true){
toggle1 = false;
}
}
if(operator_Controller1.getRawButton(6)){
if(toggle1 == false){
toggle1 = true;
}
}
if(toggle2)
{
if(toggle1){
kart1();
}
else
{
kart2();
}
}
else
{
left_ChassisMaster.stopMotor();
right_ChassisMaster.stopMotor();
}
}
@Override
public void testInit() {
}
@Override
public void testPeriodic() {
}
}