Day 3

Today I worked on writing the line follower’s code based on Dr. Bardoe’s simulator in processing. The code itself is very simple:

class DriveSystemD extends DriveSystem{
    DriveSystemD(Car c){
        super(c);
    }

    int sensorLeft(){
        return myCar.ledSensorLeft.sense((int) myCar.position.x,(int) myCar.position.y, myCar.angle);
    }

    int sensorRight(){
        return myCar.ledSensorRight.sense((int) myCar.position.x,(int) myCar.position.y, myCar.angle);
        }

    int c=0;
    void drive(){
        int l=myCar.sensorValueLeft;
        int r=myCar.sensorValueRight;

        if (c>0){ // the equivalent of the noSense. However it's losing data
            c--;
            myCar.setLeftSpeed(50);
            myCar.setRightSpeed(50);
            return;

            }

        println(l-r,l, r);
        if (r>128){
            myCar.setLeftSpeed(20);
            myCar.setRightSpeed(-20);
        } else if (l>128){
            myCar.setLeftSpeed(-20);
            myCar.setRightSpeed(20);
        } else {
            myCar.setLeftSpeed(50);
            myCar.setRightSpeed(50);
        }

        c=0;
    }
}

The only problem I found was that, based on the original template, the delay was implemented by dropping sensor (simulated) data, which causes the car not being able to turn across the corner. Convinced there’s something wrong with the template code, it took me a while to reverse engineer the code template and finally figured out the issue. In the process, I also found that the noises generated randomly is working as intended because the values are too small. Each element of the random noise vector takes value between \([-5,5]\) while the sensor data takes value between \([0,255]\). Therefore, all the noises are negligible.