We finalized the gamepad button mapping today:

Our robot can be controlled with one joystick (in case the other one fails), though the 2nd joystick can be used for sweeper/shooter control to increase efficiency in match.

We also wrote a controller using the Range Sensor (Ultrasonic) to automatically feed balls into our shooter from the ball intake.
The code uses a state machine: Once it detects a ball waiting to be fed, it activates a servo to push it into our shooter. Then, it keeps track of the servo position to automatically reset it for the next ball.
Code below:

   
private void ballFeedControl() {
        robot.rangeCache = robot.ultraSensorReader.read(robot.ULTRA_REG_START, robot.ULTRA_READ_LENGTH); //read US sensor value
        ultrasonicDistance = (robot.rangeCache[0] & 0xFF);
        if (ultrasonicState == 1) {//move forward
            if (robot.valveServo.getPosition() == 0.5) {
                ultrasonicState = 2;
            } else {
                robot.valveServo.setPosition(robot.valveServo.getPosition() - .125);
            }
        } else if (ultrasonicState == 2) {//reset
            if (robot.valveServo.getPosition() == 1) {
                ultrasonicState = 0;
            } else {
                robot.valveServo.setPosition(robot.valveServo.getPosition() + .125);
            }
        } else if (ultrasonicDistance < 10 || ultrasonicDistance > 14) {
            robot.valveServo.setPosition(robot.valveOpen);
            ultrasonicState = 0;
        } else if (ultrasonicDistance > 9 && ultrasonicDistance <= 14) {
            robot.valveServo.setPosition(robot.valveClose);
            ultrasonicState = 1;
        }
    }

3/18/17 Software
Tagged on:

Leave a Reply