Did a few things

This commit is contained in:
66945
2022-06-13 20:10:18 -06:00
parent 0b2f1871ef
commit f827314e09
32 changed files with 1471 additions and 285 deletions
+14 -5
View File
@@ -9,6 +9,8 @@ import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc4388.utility.DesmosServer;
import frc4388.utility.RobotTime;
import frc4388.utility.tuner.CANBusReader;
import frc4388.utility.tuner.TunerTablesHandler;
/**
* The VM is configured to automatically run this class, and to call the
@@ -19,7 +21,9 @@ import frc4388.utility.RobotTime;
*/
public class Robot extends TimedRobot {
Command m_autonomousCommand;
private TunerTablesHandler m_tunerTablesHandler = TunerTablesHandler.getInstance();
private RobotTime m_robotTime = RobotTime.getInstance();
private RobotContainer m_robotContainer;
@@ -34,11 +38,13 @@ public class Robot extends TimedRobot {
// Instantiate our RobotContainer. This will perform all our button bindings, and put our
// autonomous chooser on the dashboard.
m_robotContainer = new RobotContainer();
desmosServer = new DesmosServer(8000);
desmosServer.start();
DesmosServer.putTable("table", "x1", new double[] {1, 2, 3.1, 3.9}, "y1", new double[] {1, 2, 2.9, 4.1});
CANBusReader.readCANBus();
// desmosServer = new DesmosServer(8000);
// desmosServer.start();
// DesmosServer.putTable("table", "x1", new double[] {1, 2, 3.1, 3.9}, "y1", new double[] {1, 2, 2.9, 4.1});
}
/**
@@ -51,6 +57,9 @@ public class Robot extends TimedRobot {
*/
@Override
public void robotPeriodic() {
// * Necessary for communication with Tuner application
m_tunerTablesHandler.updateReaders();
m_robotTime.updateTimes();
// Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled
// commands, running already-scheduled commands, removing finished or interrupted commands,
@@ -29,18 +29,6 @@ public class RobotContainer {
/* RobotMap */
private final RobotMap m_robotMap = new RobotMap();
/* Subsystems */
// private final SwerveDrive m_robotSwerveDrive = new SwerveDrive(
// m_robotMap.leftFrontSteerMotor, m_robotMap.leftFrontWheelMotor,
// m_robotMap.rightFrontSteerMotor, m_robotMap.rightFrontWheelMotor,
// m_robotMap.leftBackSteerMotor, m_robotMap.leftBackWheelMotor,
// m_robotMap.rightBackSteerMotor, m_robotMap.rightBackWheelMotor,
// m_robotMap.leftFrontEncoder,
// m_robotMap.rightFrontEncoder,
// m_robotMap.leftBackEncoder,
// m_robotMap.rightBackEncoder
// );
private final TestMotor m_testMotor = new TestMotor(m_robotMap.testMotor);
private final LED m_robotLED = new LED(m_robotMap.LEDController);
@@ -55,11 +43,7 @@ public class RobotContainer {
configureButtonBindings();
/* Default Commands */
// // drives the swerve drive with a two-axis input from the driver controller
// m_robotSwerveDrive.setDefaultCommand(
// new RunCommand(() -> m_robotSwerveDrive.driveWithInput(-getDriverController().getLeftXAxis(),
// getDriverController().getLeftYAxis(), -getDriverController().getRightXAxis(), false), m_robotSwerveDrive));
m_testMotor.setDefaultCommand(new RunCommand(() -> m_testMotor.testDesmos(), m_testMotor));
// m_testMotor.setDefaultCommand(new RunCommand(() -> m_testMotor.testDesmos(), m_testMotor));
// continually sends updates to the Blinkin LED controller to keep the lights on
m_robotLED.setDefaultCommand(new RunCommand(m_robotLED::updateLED, m_robotLED));
+2 -1
View File
@@ -5,6 +5,7 @@
package frc4388.robot;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import com.ctre.phoenix.sensors.CANCoder;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
@@ -94,6 +95,6 @@ public class RobotMap {
//rightBackSteerMotor.configRemoteFeedbackFilter(rightBackEncoder.getDeviceID(), RemoteSensorSource.CANCoder, SwerveDriveConstants.REMOTE_0, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
}
public final CANSparkMax testMotor = new CANSparkMax(6, MotorType.kBrushless);
public final WPI_TalonSRX testMotor = new WPI_TalonSRX(6);
}
@@ -18,7 +18,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc4388.robot.Constants.SwerveDriveConstants;
import frc4388.utility.Gains;
import frc4388.utility.RobotGyro;
//import frc4388.utility.RobotGyro;
public class SwerveDrive extends SubsystemBase {
SwerveDriveKinematics m_kinematics;
@@ -59,7 +59,7 @@ public class SwerveDrive extends SubsystemBase {
private SwerveDriveKinematics kinematics = new SwerveDriveKinematics(m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, m_backRightLocation);
public SwerveModule[] modules;
public RobotGyro gyro; //TODO Add Gyro Lol
// public RobotGyro gyro; //TODO Add Gyro Lol
// public SwerveDrive(WPI_TalonFX leftFrontSteerMotor,WPI_TalonFX leftFrontWheelMotor,WPI_TalonFX rightFrontSteerMotor,WPI_TalonFX rightFrontWheelMotor,
@@ -107,7 +107,7 @@ public class SwerveDrive extends SubsystemBase {
SwerveModuleState[] states =
kinematics.toSwerveModuleStates(
fieldRelative
? ChassisSpeeds.fromFieldRelativeSpeeds(xSpeedMetersPerSecond, ySpeedMetersPerSecond, rot*3, gyro.getRotation2d())
? ChassisSpeeds.fromFieldRelativeSpeeds(xSpeedMetersPerSecond, ySpeedMetersPerSecond, rot*3, new Rotation2d())//, gyro.getRotation2d())
: new ChassisSpeeds(xSpeedMetersPerSecond, ySpeedMetersPerSecond, rot*3));
SwerveDriveKinematics.desaturateWheelSpeeds(states, Units.feetToMeters(SwerveDriveConstants.MAX_SPEED_FEET_PER_SEC));
for (int i = 0; i < states.length; i++) {
@@ -1,23 +1,58 @@
package frc4388.robot.subsystems;
import com.ctre.phoenix.sensors.CANCoder;
import com.revrobotics.CANSparkMax;
import com.revrobotics.RelativeEncoder;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc4388.utility.DesmosServer;
import frc4388.utility.Gains;
import frc4388.utility.tuner.TunerLogger;
import frc4388.utility.tuner.annotations.Controller;
import frc4388.utility.tuner.annotations.GainsField;
import frc4388.utility.tuner.annotations.Loggable;
import frc4388.utility.tuner.annotations.Reader;
import frc4388.utility.tuner.TunerController;
import frc4388.utility.tuner.TunerTablesHandler;
import java.util.Map;
public class TestMotor extends SubsystemBase {
private CANSparkMax m_testMotor;
private RelativeEncoder m_testEncoder;
private final WPI_TalonSRX m_testMotor;
public TestMotor(CANSparkMax testMotor) {
@GainsField(id="TestMotor")
public Gains gains = new Gains(1, 1, 1, 1, 1, 1);
@Loggable(id="test")
public double logable = 4;
@Loggable(id="test2")
public double second = 5;
// private final RelativeEncoder m_testEncoder;
public TestMotor(WPI_TalonSRX testMotor) {
m_testMotor = testMotor;
m_testEncoder = m_testMotor.getEncoder();
m_testMotor.configFactoryDefault();
// m_testEncoder = m_testMotor.getEncoder();
TunerTablesHandler.getInstance().addControllers(TunerController.createTunerControllers(this));
TunerTablesHandler.getInstance().addLoggers(TunerLogger.createTunerLoggers(this));
}
public void testDesmos() {
DesmosServer.putDouble("Position", m_testEncoder.getPosition());
m_testMotor.set(DesmosServer.readDouble("Speed"));
// public void testDesmos() {
// DesmosServer.putDouble("Position", m_testEncoder.getPosition());
// m_testMotor.set(DesmosServer.readDouble("Speed"));
// }
@Reader(id="TestMotor", value="velocity")
public double velocityReader() {
return m_testMotor.getSelectedSensorVelocity();
}
}
@Reader(id="TestMotor", value="position")
public double positionReader() {
return m_testMotor.getSelectedSensorPosition();
}
@Controller(id="TestMotor", value="velocity")
public void velocityController(double value) {
logable = Math.random() * 10;
m_testMotor.set(value);
}
}