I'm currently using my arduino to control four actuators to move in different directions for pre-configured motions. Individually, my functions work, but when i try to demo the complete range of motions, it will only ever do my 'nuetral' function and one other function. This is puzzeling to me, because the code in these functions is nearly identical besides variable name changes and pot values. Is there a limit to the amount of functions that can be called? Am i missing something incredibly obvious (so tired). I'm attaching my code below, and how i'm trying to call it. Each function works correctly by itself, but when i try to do one after another (unless it is immediately following my nuetral function) it just stops doing anything.
void loop ( )
{
//64 will stop the motor 1
//192 is stop for motor 2
//All MC's active to set a nuetral position
digitalWrite(MC1, LOW);
digitalWrite(MC2, LOW);
// there appears to be a bug where it will only do two functions in a row. All functions work individualy
Nuetral();
LeanLeft();
LeanRight();
}
Breaking it up into snippets:
Nuetral code (only showing the first actuator's test/adjustment to save space, and the final global position check):
void Nuetral( void )
{
boolean nuetral = false; //all actuators are in nuetral position
boolean nuetral1 = false; // checking actuator 1 in position
boolean nuetral2 = false; // checking actuator 2 in position
boolean nuetral3 = false; // checking actuator 3 in position
boolean nuetral4 = false; // checking actuator 4 in position
//64 will stop the motor 1
//192 is stop for motor 2
//All MC's active to set a nuetral position do i need to worry about this?
// I'm setting the MC's with ever loop check
while (!nuetral)
{
// Reading in values for actuator position, lower is more extended
Actuator1Value = analogRead(Actuator1);
Actuator2Value = analogRead(Actuator2);
Actuator3Value = analogRead(Actuator3);
Actuator4Value = analogRead(Actuator4);
// checking and adjusting actuator 1
if (Actuator1Value >= 615)
{
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
SaberSerial.write(byte(SABER_MOTOR2_FULL_FORWARD));
}
if (Actuator1Value <= 585)
{
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
SaberSerial.write(byte(SABER_MOTOR2_FULL_REVERSE));
}
if ((Actuator1Value > 585) && (Actuator1Value < 615))
nuetral1 = true;
// checking to make sure all actuators are in right position before leaving loop.
if (nuetral1 && nuetral2 && nuetral3 && nuetral4)
{
nuetral= true;
}
}
}
Leaning left:
void LeanLeft( void )
{
boolean leaningLeft = false; //all actuators are in position
boolean leaningLeft1 = false; // checking actuator 1 in position
boolean leaningLeft2 = false; // checking actuator 2 in position
boolean leaningLeft3 = false; // checking actuator 3 in position
boolean leaningLeft4 = false; // checking actuator 4 in position
//64 will stop the motor 1
//192 is stop for motor 2
//All MC's active to set a nuetral position do i need to worry about this?
// I'm setting the MC's with every loop check
while (!leaningLeft)
{
// Reading in values for actuator position, lower is more extended
Actuator1Value = analogRead(Actuator1);
Actuator2Value = analogRead(Actuator2);
Actuator3Value = analogRead(Actuator3);
Actuator4Value = analogRead(Actuator4);
// checking and adjusting actuator 1
if (Actuator1Value >= 1115)
{
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
SaberSerial.write(byte(SABER_MOTOR2_FULL_FORWARD));
}
if (Actuator1Value <= 1095)
{
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
SaberSerial.write(byte(SABER_MOTOR2_FULL_REVERSE));
}
if ((Actuator1Value > 1095) && (Actuator1Value < 1115))
leaningLeft1 = true;
// checking and adjusting actuator 2
if (Actuator2Value >= 55)
{
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
SaberSerial.write(byte(SABER_MOTOR1_FULL_FORWARD));
}
if (Actuator2Value <= 35)
{
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
SaberSerial.write(byte(SABER_MOTOR1_FULL_REVERSE));
}
if ((Actuator2Value > 35) && (Actuator2Value < 55))
leaningLeft2 = true;
// checking and adjusting actuator 3
if (Actuator3Value >= 55)
{
digitalWrite(MC1, LOW);
digitalWrite(MC2, HIGH);
SaberSerial.write(byte(SABER_MOTOR1_FULL_FORWARD));
}
if (Actuator3Value <= 35)
{
digitalWrite(MC1, LOW);
digitalWrite(MC2, HIGH);
SaberSerial.write(byte(SABER_MOTOR1_FULL_REVERSE));
}
if ((Actuator3Value > 35) && (Actuator3Value < 55))
leaningLeft3= true;
// checking and adjusting actuator 4
if (Actuator4Value >= 1115)
{
digitalWrite(MC1, LOW);
digitalWrite(MC2, HIGH);
SaberSerial.write(byte(SABER_MOTOR2_FULL_FORWARD));
}
if (Actuator4Value <= 1095)
{
digitalWrite(MC1, LOW);
digitalWrite(MC2, HIGH);
SaberSerial.write(byte(SABER_MOTOR2_FULL_REVERSE));
}
if ((Actuator4Value > 1095) && (Actuator4Value < 1115))
leaningLeft4 = true;
// checking to make sure all actuators are in right position before leaving loop.
if (leaningLeft1 && leaningLeft2 && leaningLeft3 && leaningLeft4)
{
leaningLeft= true;
}
}
}
Leaning right:
void LeanRight(void)
{
boolean leaningRight = false; //all actuators are in position
boolean leaningRight1 = false; // checking actuator 1 in position
boolean leaningRight2 = false; // checking actuator 2 in position
boolean leaningRight3 = false; // checking actuator 3 in position
boolean leaningRight4 = false; // checking actuator 4 in position
//64 will stop the motor 1
//192 is stop for motor 2
// I'm setting the MC's with every loop check
while (!leaningRight)
{
// Reading in values for actuator position, lower is more extended
Actuator1Value = analogRead(Actuator1);
Actuator2Value = analogRead(Actuator2);
Actuator3Value = analogRead(Actuator3);
Actuator4Value = analogRead(Actuator4);
// checking and adjusting actuator 1
if (Actuator1Value >= 55)
{
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
SaberSerial.write(byte(SABER_MOTOR2_FULL_FORWARD));
}
if (Actuator1Value <= 35)
{
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
SaberSerial.write(byte(SABER_MOTOR2_FULL_REVERSE));
}
if ((Actuator1Value > 35) && (Actuator1Value < 55))
leaningRight1 = true;
// checking and adjusting actuator 2
if (Actuator2Value >= 1115)
{
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
SaberSerial.write(byte(SABER_MOTOR1_FULL_FORWARD));
}
if (Actuator2Value <= 1095)
{
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
SaberSerial.write(byte(SABER_MOTOR1_FULL_REVERSE));
}
if ((Actuator2Value > 1095) && (Actuator2Value < 1115))
leaningRight2 = true;
// checking and adjusting actuator 3
if (Actuator3Value >= 1115)
{
digitalWrite(MC1, LOW);
digitalWrite(MC2, HIGH);
SaberSerial.write(byte(SABER_MOTOR1_FULL_FORWARD));
}
if (Actuator3Value <= 1095)
{
digitalWrite(MC1, LOW);
digitalWrite(MC2, HIGH);
SaberSerial.write(byte(SABER_MOTOR1_FULL_REVERSE));
}
if ((Actuator3Value > 1095) && (Actuator3Value < 1115))
leaningRight3= true;
// checking and adjusting actuator 4
if (Actuator4Value >= 55)
{
digitalWrite(MC1, LOW);
digitalWrite(MC2, HIGH);
SaberSerial.write(byte(SABER_MOTOR2_FULL_FORWARD));
}
if (Actuator4Value <= 35)
{
digitalWrite(MC1, LOW);
digitalWrite(MC2, HIGH);
SaberSerial.write(byte(SABER_MOTOR2_FULL_REVERSE));
}
if ((Actuator4Value > 35) && (Actuator4Value < 55))
leaningRight4 = true;
// checking to make sure all actuators are in right position before leaving loop.
if (leaningRight1 && leaningRight2 && leaningRight3 && leaningRight4)
{
leaningRight= true;
}
}
}
i
If i were to call the nuetral, the leanleft, then leanright, it would only perform the first two items. If i were to just call leanleft and leanright, it would only do leanleft.
Sorry for the massive post. Any insights would be appreciated.