// Real Autonomous // * Code to be run autonomously for the first ten (10) seconds of the match. // * Launch catapult // * Drive robot forward ENCODER_DIST ticks. void Autonomous() { robotDrive.SetSafetyEnabled(false); // STEP 1: Set all of the states. // SAFETY AND SANITY - SET ALL TO ZERO loaded = winchSwitch.Get(); loading = false; intake.Set(0.0); rightWinch.Set(0.0); leftWinch.Set(0.0); // STEP 2: Move forward to optimum shooting position Drive(-AUTO_DRIVE_SPEED, SHOT_POSN_DIST); // STEP 3: Drop the arm for a clean shot arm.Set(DoubleSolenoid::kForward); Wait(1.0); // Ken // STEP 4: Launch the catapult LaunchCatapult(); Wait (1.0); // Ken // Get us fully into the zone for 5 points Drive(-AUTO_DRIVE_SPEED, INTO_ZONE_DIST - SHOT_POSN_DIST); // SAFETY AND SANITY - SET ALL TO ZERO intake.Set(0.0); rightWinch.Set(0.0); leftWinch.Set(0.0); }
// HandleArm // * Manage solenoids for arm up-down // ----> ASSUMES kForward on DoubleSolenoid is the down position. // * Handle intake motors void HandleArm() { if (gamepad.GetEvent(BUTTON_ARM) == kEventClosed && armDown) { arm.Set(DoubleSolenoid::kReverse); armDown = false; } else if (gamepad.GetEvent(BUTTON_ARM) == kEventClosed) { arm.Set(DoubleSolenoid::kForward); armDown = true; } if (gamepad.GetDPadEvent(BUTTON_INTAKE_COLLECT) == kEventClosed) { intake.Set(INTAKE_COLLECT); } else if (gamepad.GetDPadEvent(BUTTON_INTAKE_COLLECT) == kEventOpened) { intake.Set(0.0); } if(gamepad.GetDPadEvent(BUTTON_INTAKE_EJECT) == kEventClosed) { intake.Set(INTAKE_EJECT); } if (gamepad.GetDPadEvent(BUTTON_INTAKE_EJECT) == kEventOpened) { intake.Set(0.0); } }
// Test Autonomous void Autonomous() { robotDrive.SetSafetyEnabled(false); // STEP 1: Set all of the states. // SAFETY AND SANITY - SET ALL TO ZERO loaded = winchSwitch.Get(); loading = false; intake.Set(0.0); rightWinch.Set(0.0); leftWinch.Set(0.0); // STEP 2: Move forward to optimum shooting position Drive(-AUTO_DRIVE_SPEED, SHOT_POSN_DIST); // STEP 3: Drop the arm for a clean shot arm.Set(DoubleSolenoid::kForward); Wait(1.0); // Ken // STEP 4: Launch the catapult LaunchCatapult(); Wait (1.0); // Ken if (ds->GetDigitalIn(1)) { // STEP 5: Start the intake motor and backup to our origin position to pick up another ball InitiateLoad(); intake.Set(-INTAKE_COLLECT); while (CheckLoad()); Drive(AUTO_DRIVE_SPEED, SHOT_POSN_DIST); Wait(1.0); // For the ball to collect // STEP 6: Shut off the intake, bring up the arm and move to shooting position intake.Set(0.0); arm.Set(DoubleSolenoid::kReverse); Wait (1.0); // "Settle down" Drive(-AUTO_DRIVE_SPEED, SHOT_POSN_DIST); // Step 7: drop the arm for a clean shot and shoot arm.Set(DoubleSolenoid::kForward); Drive(AUTO_DRIVE_SPEED, SHOT_POSN_DIST); // UNTESTED KICKED OFF FIELD Wait(1.0); // For arm to go down LaunchCatapult(); } // Get us fully into the zone for 5 points Drive(-AUTO_DRIVE_SPEED, INTO_ZONE_DIST - SHOT_POSN_DIST); // SAFETY AND SANITY - SET ALL TO ZERO intake.Set(0.0); rightWinch.Set(0.0); leftWinch.Set(0.0); }
// Code to be run during the remaining 2:20 of the match (after Autonomous()) // // OperatorControl // * Calls all the above methods void OperatorControl() { // SAFETY AND SANITY - SET ALL TO ZERO intake.Set(0.0); rightWinch.Set(0.0); leftWinch.Set(0.0); arm.Set(DoubleSolenoid::kReverse); /* TODO: Investigate. At least year's (GTR East) competition, we reached the conclusion that disabling this was * the only way we could get out robot code to work (reliably). Should this be set to false? */ robotDrive.SetSafetyEnabled(false); Timer clock; int sanity = 0; int bigSanity = 0; loading = false; loaded = winchSwitch.Get(); RegisterButtons(); gamepad.Update(); leftStick.Update(); compressor.Start(); while (IsOperatorControl() && IsEnabled()) { clock.Start(); HandleDriverInputs(); HandleShooter(); HandleArm(); // HandleEject(); while (!clock.HasPeriodPassed(LOOP_PERIOD)); // add an IsEnabled??? clock.Reset(); sanity++; if (sanity >= 100) { bigSanity++; sanity = 0; dsLCD->PrintfLine(DriverStationLCD::kUser_Line4, "%d", bigSanity); } gamepad.Update(); leftStick.Update(); dsLCD->UpdateLCD(); } // SAFETY AND SANITY - SET ALL TO ZERO intake.Set(0.0); rightWinch.Set(0.0); leftWinch.Set(0.0); }