diff --git a/Definitions.h b/Definitions.h index 0ebf679..7eedf2d 100644 --- a/Definitions.h +++ b/Definitions.h @@ -66,4 +66,9 @@ #define COLLECTOR_EXTEND 9 #define COLLECTOR_RETRACT 10 +//Drive threshold definitions + +#define DRIVE_MAX_VALUE_CHANGE .05 +#define DRIVE_SPEED_FALLBACK 2 + #endif diff --git a/ZaphodBase.cpp b/ZaphodBase.cpp index 3393cf1..b4341dc 100644 --- a/ZaphodBase.cpp +++ b/ZaphodBase.cpp @@ -7,6 +7,12 @@ ZaphodBase::ZaphodBase(): } void ZaphodBase::RobotInit() { + //Checks the state of the drive joystick to make sure it was not moved + //while plugged in, giving inaccurate readings + if(!zBot->checkJoystickValues()) + { + printf("***UNPLUG AND REPLUG THE JOYSTICKS***\n"); + } } void ZaphodBase::DisabledInit() { diff --git a/ZaphodRobot.cpp b/ZaphodRobot.cpp index 4854595..cd5eb72 100644 --- a/ZaphodRobot.cpp +++ b/ZaphodRobot.cpp @@ -57,8 +57,35 @@ float ZaphodRobot::getRearSonar() return (rearSonarRightV+rearSonarLeftV)/2; } -void driveRobot(float x, float y) +bool ZaphodRobot::checkJoystickValues() { + float x = ControlSystem->rightJoystickAxisValues[1]; + float y = ControlSystem->rightJoystickAxisValues[2]; + if((-.1 < x && x < .1) && (-.1 < y && y < .1)) + { + return true; + } + else + { + return false; + } +} + +void ZaphodRobot::driveRobot(float x, float y) +{ + if(y>1.0f){ + y=1.0f; + }else if(y!=0.0f&&y<-1.0f){ + y=-1.0f; + } + float leftPower=((y+x)/2+1)*127+1; + float rightPower=((y-x)/2+1)*127+1; + right1->SetRaw(int(rightPower)); + right2->SetRaw(int(rightPower)); + right3->SetRaw(int(rightPower)); + left1->SetRaw(int(leftPower)); + left2->SetRaw(int(leftPower)); + left3->SetRaw(int(leftPower)); } //Main function used to handle periodic tasks on the robot @@ -71,11 +98,11 @@ void ZaphodRobot::handler() //TODO Need to implement a timing system to not break the spike (this function doesn't run the compressor at the moment) compressorSystem->compressorSystemPeriodic(); collector->updateCollector(shooter->isShooting, shooter->getAngle()); + driveRobot(ControlSystem->rightJoystickAxisValues[3]+ControlSystem->rightJoystickAxisValues[1], -ControlSystem->rightJoystickAxisValues[2]); //Button assignments to actions if(ControlSystem->leftJoystickValues[SHOOTER_FIRE]) { - //TODO Needs a power input shooter->startShootingSequence(ControlSystem->throttle); } if(ControlSystem->rightJoystickValues[COLLECTOR_INTAKE]) diff --git a/ZaphodRobot.h b/ZaphodRobot.h index a8d2b2b..e93d097 100644 --- a/ZaphodRobot.h +++ b/ZaphodRobot.h @@ -22,10 +22,10 @@ class ZaphodRobot ZaphodCompressor *compressorSystem; public: ZaphodRobot(); - float frontSonarLeftV, frontSonarRightV, rearSonarLeftV, rearSonarRightV; float getFrontSonar(); float getRearSonar(); + bool checkJoystickValues(); void driveRobot(float,float); void handler(); };