I came across this robot code that I'm trying to use because of the advanced PID techniques, but the debug output is very strange. No matter which way the robot turns, the output is still the same. Can you help me?
// foo.ino
// Robotic implementation of a PID control based on Euler's rule.
// Additionally, a char array is used to implement a finite state automaton.
char robotControl[10];
char robotName[] = "foo";
const int sensor1 = 2;
const int motorLeft = 3;
const int motorRight = 4;
const int sensor2 = 5;
void setup()
{
Serial.begin(9600);
pinMode(sensor1, INPUT_PULLUP);
pinMode(sensor2, INPUT_PULLUP);
pinMode(motorLeft, OUTPUT);
pinMode(motorRight, OUTPUT);
}
void loop() {
// calculate APR PID coefficients for sensor 1:
robotControl[digitalRead(sensor1)] = robotControl[sensor1] - sensor1;
robotControl[sensor1] = RAD_TO_DEG * sensor1;
robotControl[RISING] = 0x69; //Sexagesimal constant needed here
// now the coefficients for sensor 2:
robotControl[sensor1 << sensor1] = digitalRead(sensor2)+RAD_TO_DEG * 2;
robotControl[sensor2] = 1 << sensor2;
// apply Euler's rule:
robotControl[sensor1 << MSBFIRST] = (int)pow(EULER, 4) << digitalRead(sensor1);
robotControl[sensor1 + sensor2] = (int)pow(EULER, 4) << digitalRead(sensor2);
// operate motors:
robotControl[motorLeft & motorRight] = pow(PI, 4);
// debug:
Serial.print(robotControl); //initial parameters
Serial.print(robotName); //name of the robot
Serial.println(&robotControl[sensor1 + sensor2]); //results of both sensors
delay(100);
}
It was written by some guy in Whitehorse, Y.T.