Hi,
I have written a program, and expanded it abit to breakout some code into routines, and when I try to compile it I get 'java.lang.StackOverflowError'.
I have got ver 12 Alpha of the compiler, running on Vista. I have also re-installed java, but have no idea how to check the version.
Any ideas of how to fix would be very welcome 8-).
Thanks,
Martin
Here is the code:
/* Wheel encoder multi test 4
*
* This test is designed to test 6 motor driver
*
* Mapping so far (Default direction in bracketts):
* 1-Not Working
* 2-Base (CounterClockwise)
* 7-Shoulder (ClockWise)
* 4-Not Working
* 5-Gripper (Close)
*/
int MotorSpeed1 = 0;
int MotorSpeed2 = 0;
int MotorSpeed3 = 0;
int MotorSpeed4 = 0;
int MotorSpeed5 = 0;
int MotorSpeed6 = 0;
int PinPulse1 = 3;
int PinDirection1 = 2;
int PinPulse2 = 5;
int PinDirection2 = 4;
int PinPulse3 = 6;
int PinDirection3 = 7;
int PinPulse4 = 9;
int PinDirection4 = 8;
int PinPulse5 = 10;
int PinDirection5 = 12;
int PinPulse6 = 11;
int PinDirection6 = 13;
int SerialStreamByte = -1;
int StepSize = 128;
void setup()
{
Serial.begin(9600);
for (int x = 2; x < 14; x++)
{
pinMode(x, OUTPUT);
digitalWrite(x, LOW);
}
Serial.println("P4 Ready");
// ExecCommand('r');
}
void loop()
{
SerialStreamByte = ListenForCommand();
if (SerialStreamByte != -1)
{
ExecCommand(SerialStreamByte);
DebugMotorSpeeds()
LimitHardware();
InterfaceHardware();
}
}
int ListenForCommand()
{
if (Serial.available() > 0)
{
return Serial.read();
}
return -1;
}
void LimitHardware()
{
MotorSpeed1 = constrain(MotorSpeed1, -255, 255);
MotorSpeed2 = constrain(MotorSpeed2, -255, 255);
MotorSpeed3 = constrain(MotorSpeed3, -255, 255);
MotorSpeed4 = constrain(MotorSpeed4, -255, 255);
MotorSpeed5 = constrain(MotorSpeed5, -255, 255);
MotorSpeed6 = constrain(MotorSpeed6, -255, 255);
}
void InterfaceHardware()
{
analogWrite(PinPulse1, abs(MotorSpeed1));
digitalWrite(PinDirection1, MotorSpeed1 > 0 ? HIGH : LOW);
analogWrite(PinPulse2, abs(MotorSpeed2));
digitalWrite(PinDirection2, MotorSpeed2 > 0 ? HIGH : LOW);
analogWrite(PinPulse3, abs(MotorSpeed3));
digitalWrite(PinDirection3, MotorSpeed3 > 0 ? HIGH : LOW);
analogWrite(PinPulse4, abs(MotorSpeed4));
digitalWrite(PinDirection4, MotorSpeed4 > 0 ? HIGH : LOW);
analogWrite(PinPulse5, abs(MotorSpeed5));
digitalWrite(PinDirection5, MotorSpeed5 > 0 ? HIGH : LOW);
analogWrite(PinPulse6, abs(MotorSpeed6));
digitalWrite(PinDirection6, MotorSpeed6 > 0 ? HIGH : LOW);
}
void DebugMotorSpeeds()
{
Serial.print("MotorSpeed 1=");
Serial.print(MotorSpeed1, DEC);
Serial.print(" MotorSpeed 2=");
Serial.print(MotorSpeed2, DEC);
Serial.print(" MotorSpeed 3=");
Serial.print(MotorSpeed3, DEC);
Serial.print(" MotorSpeed 4=");
Serial.print(MotorSpeed4, DEC);
Serial.print(" MotorSpeed 5=");
Serial.print(MotorSpeed5, DEC);
Serial.print(" MotorSpeed 6=");
Serial.print(MotorSpeed6, DEC);
Serial.println();
}
void ExecCommand(int Command)
{
switch (Command)
{
case 'r':
Serial.println("Reset");
MotorSpeed1 = 0;
MotorSpeed2 = 0;
MotorSpeed3 = 0;
MotorSpeed4 = 0;
MotorSpeed5 = 0;
MotorSpeed6 = 0;
break;
case '1':
MotorSpeed1 += StepSize;
break;
case '!':
MotorSpeed1 -= StepSize;
break;
case '2':
MotorSpeed2 += StepSize;
break;
case '\"':
MotorSpeed2 -= StepSize;
break;
case '7':
MotorSpeed3 += StepSize;
break;
case '&':
MotorSpeed3 -= StepSize;
break;
case '4':
MotorSpeed4 += StepSize;
break;
case '
:
MotorSpeed4 -= StepSize;
break;
case '5':
MotorSpeed5 += StepSize;
break;
case '%':
MotorSpeed5 -= StepSize;
break;
case '6':
MotorSpeed6 += StepSize;
break;
case '^':
MotorSpeed6 -= StepSize;
break;
}
}