/*
 * Braitenberg Vehicles
 */

#include "Myro.h"

double Ambient;
// This function normalizes light sensor values to 0.0..1.0
double normalize (int v) {
    if (v > Ambient) {
        v = Ambient;
    }
    // we know now that 0 <= v <= Ambient
    return 1.0 - v/Ambient;
}


int main() {
    connect();

    // record average ambient light values
    Ambient = (robot.getLight("left") +
        robot.getLight("center") +
        robot.getLight("right")) / 3.0;

    // Run the robot for 60 seconds
    while (timeRemaining(60)) {
        int L = robot.getLight("left");
        int R = robot.getLight("right");
        // motors run proportional to light
        robot.motors(normalize(L), normalize(R));
    }
    robot.stop();
    disconnect();
    return 0;
}

/*
int main() {
    Ambient = 200;
    cout << normalize(0) << endl;
    cout << normalize(50) << endl;
    cout << normalize(150) << endl;
    cout << normalize(220) << endl;
    return 0;
}
*/

