Skip to content

Instantly share code, notes, and snippets.

@bsimmons99
Created February 19, 2020 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsimmons99/d437c877360244b995892fdcaaaae41e to your computer and use it in GitHub Desktop.
Save bsimmons99/d437c877360244b995892fdcaaaae41e to your computer and use it in GitHub Desktop.
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-2019 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.myclasses;
import com.revrobotics.CANEncoder;
import com.revrobotics.CANError;
import com.revrobotics.CANPIDController;
import com.revrobotics.CANSparkMax;
import com.revrobotics.ControlType;
import frc.robot.Robot;
/**
* Add your docs here.
*/
public class CANSparkMaxSim extends CANSparkMax {
public class CANEncoderSim extends CANEncoder {
public CANEncoderSim(CANSparkMax device) {
super(device);
}
@Override
public double getVelocity() {
if (simulated) {
return 0.0;
} else {
return super.getVelocity();
}
}
@Override
public double getPosition() {
if (simulated) {
return 0.0;
} else {
return super.getPosition();
}
}
}
public class CANPIDControllerSim extends CANPIDController {
public CANPIDControllerSim(CANSparkMax device) {
super(device);
}
@Override
public CANError setReference(double value, ControlType ctrl) {
if (simulated) {
return CANError.kOk;
} else {
return super.setReference(value, ctrl);
}
}
}
private boolean inverted = false;
private boolean simulated = false;
public CANSparkMaxSim(int deviceID, MotorType type) {
super(deviceID, type);
simulated = Robot.isSimulation();
}
@Override
public void setInverted(boolean isInverted) {
if (simulated) {
inverted = isInverted;
} else {
super.setInverted(isInverted);
}
}
@Override
public boolean getInverted() {
if (simulated) {
return inverted;
} else {
return super.getInverted();
}
}
@Override
public void set(double speed) {
if (simulated) {
} else {
super.set(speed);
}
}
@Override
public double get() {
if (simulated) {
return 0.0;
} else {
return super.get();
}
}
@Override
public void stopMotor() {
if (simulated) {
} else {
super.stopMotor();
}
}
@Override
public double getAppliedOutput() {
if (simulated) {
return 0.0;
} else {
return super.getAppliedOutput();
}
}
@Override
public CANEncoderSim getEncoder() {
return new CANEncoderSim(this);
}
@Override
public CANPIDControllerSim getPIDController() {
return new CANPIDControllerSim(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment