No, the robot wasn't on anymore because I forgot about the screnshot. Luckily the error hanged around after that still.
The motors shut down randomly (to me). Sometimes the robot is moving, sometimes it's just standing there enabled, sometimes the error keeps coming back after I reboot the thing, sometimes it goes away. I couldn't really find a pattern. I did notice that it never shut down while moving at "high" speeds, though that could be just luck. Below is the code (I hope I did the formatting correctly). Thanks for the attention!
Code:
#include <cstdint>
#include "WPILib.h"
class Robot: public IterativeRobot
{
RobotDrive myRobot; // robot drive system
Joystick joystickMain;
Joystick joystickRotate;
CANTalon FL;
CANTalon FR;
CANTalon RL;
CANTalon RR;
CANTalon talonSwerve;
AnalogInput potSwerve;
float mov, mainMagRAW, mainMag, potSwerveAngle, WrapMinusPiToPlusPi;
bool movingForward;
public:
Robot() :
myRobot(FL,RL,FR,RR),
joystickMain(0),
joystickRotate(1),
FL(11),
FR(12),
RL(14),
RR(13),
talonSwerve(15),
potSwerve(0)
{
//Drive system setup
myRobot.SetExpiration(0.1);
myRobot.SetInvertedMotor(myRobot.kFrontLeftMotor,false);
myRobot.SetInvertedMotor(myRobot.kFrontRightMotor,true);
myRobot.SetInvertedMotor(myRobot.kRearLeftMotor,false);
myRobot.SetInvertedMotor(myRobot.kRearRightMotor,true);
//Pot setup
potSwerve.SetOversampleBits(5);
potSwerve.SetAverageBits(5);
//Camera Setup
CameraServer::GetInstance()->SetQuality(50);
CameraServer::GetInstance()->StartAutomaticCapture("cam0");
}
private:
void RobotInit()
{
}
void AutonomousInit()
{
}
void AutonomousPeriodic()
{
}
void TeleopInit()
{
}
void TeleopPeriodic()
{
//1.430 - 2.624 - 3.828
potSwerveAngle = (potSwerve.GetAverageVoltage()-2.624) * 71.485;
//------------JOYSTICK DEADBAND------------//
mainMagRAW = joystickMain.GetMagnitude();
if(mainMagRAW >= 0.3)
{
mainMag = (mainMagRAW-0.3)/0.7;
}
if(mainMagRAW <= -0.3)
{
mainMag = (mainMagRAW+0.3)/0.7;
}
if(mainMagRAW < 0.3 && mainMagRAW > -0.3)
{
mainMag = 0;
}
//------------MOVEMENT DIRECTION------------//
if(joystickMain.GetDirectionDegrees() <= 90.0 && joystickMain.GetDirectionDegrees() >= -90.0){
WrapMinusPiToPlusPi = joystickMain.GetDirectionDegrees();
movingForward = true;
}
else if(joystickMain.GetDirectionDegrees() > 90.0 && joystickMain.GetDirectionDegrees() <= 180.0){
WrapMinusPiToPlusPi = joystickMain.GetDirectionDegrees() - 180.0;
movingForward = false;
}
else if(joystickMain.GetDirectionDegrees() < -90.0 && joystickMain.GetDirectionDegrees() > -180.0){
WrapMinusPiToPlusPi = joystickMain.GetDirectionDegrees() + 180.0;
movingForward = false;
}
if(WrapMinusPiToPlusPi < 70.0 && WrapMinusPiToPlusPi > -70.0 ){
if(mainMag > 0.08 && potSwerve.GetAverageVoltage() >= 1.430 && potSwerve.GetAverageVoltage() <= 3.828){
talonSwerve.Set(-1.0 * (potSwerveAngle - WrapMinusPiToPlusPi)/90.0);
}
else{
if(potSwerve.GetAverageVoltage() < 1.430){
talonSwerve.Set(0.5);
}
else if(potSwerve.GetAverageVoltage() > 3.828){
talonSwerve.Set(-0.5);
}
else{
talonSwerve.Set(0);
}
}
if(movingForward)
{
mov = mainMag;
}
else
{
mov = mainMag*-1.0;
}
}
else if(joystickMain.GetDirectionDegrees() > -110.0 && joystickMain.GetDirectionDegrees() < -70.0){
talonSwerve.Set(-1.0 * (potSwerveAngle + 95.0)/95.0);
mov = mainMag;
}
else if(joystickMain.GetDirectionDegrees() > 70.0 && joystickMain.GetDirectionDegrees() < 110.0){
talonSwerve.Set(-1.0 * (potSwerveAngle - 95.0)/95.0);
mov = mainMag;
}
myRobot.MecanumDrive_Cartesian(0,mov,(joystickRotate.GetX()*-1.0));
}
void TestPeriodic()
{
}
};
START_ROBOT_CLASS(Robot);