View Single Post
  #6   Spotlight this post!  
Unread 10-02-2011, 13:47
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Re: On Java an Line Sensing.

Here's my line sensing code:

Code:
package com.robototes.abomasnow;

import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;

public class Main extends SimpleRobot {
    Driver robot = new Driver(1,2);
    LineSensorGroup lsg   = new LineSensorGroup(1,2,3);
    
    final int middle = 2;
    final int left = 1;
    final int right = 3;

    public void autonomous() {
        getWatchdog().feed();
        
        int last = middle;  //last line sensor value
        while(this.isEnabled() && this.isAutonomous()) {
            if(lsg.getMiddle()) {
                last = middle;
            } if (lsg.getLeft()) {
                last = left;
            } if (lsg.getRight()) {
                last = right;
            }

            if (lsg.allAreOff()) {
                if (last == left) {
                    robot.arcadeDrive(0.4, 0.1);  //Forward and right*/
                    System.out.println("Left");
                } else if (last == middle) {
                    robot.arcadeDrive(0.5, 0);    /* Straight forward */
                    System.out.println("Forward");
                } else if (last == right) {
                    robot.arcadeDrive(0.4, -0.1);  /* forward and left */
                    System.out.println("Right");
                }
            }

            if (lsg.allAreOn()) {
                if (last == middle) {
                    robot.stop();
                    System.out.println("Stopping");
                    break;
                }
            }
            Timer.delay(0.05);
            this.getWatchdog().feed();
        }
    }
}
Driver is my own motor group controller, RobotDrive was too heavy for me
Reply With Quote