I am running an Lynxmotion Botboarduino (Arduino Duemilanove equivalent), connected to a Lynxmotion SSC-32 servo controller via serial cable, controlling my Lynxmotion AL5D arm. I am trying to program the arm to sense an object placed at a starting location via IR sensor, have the arm move to pick it up and drop it in a cup, a specified number of times (having the arm wait for the object is sensed by the sensor before it goes to pick it up) then stop, ignoring anything else placed in front of the IR sensor.
My progress: I have the arm sense the object, move to pick it up, drop it in the cup.
My problem: Anything I have tried as far as to limit how many times the arm reacts to the IR sensor has not worked. It senses the object, then "picks up and drops" whatever my specified number of times was, regardless of there having been only one object (it doesn't wait for the IR sensor). I will include the upper portion of the code, but not the last half, as its just movements:
// set pin numbers:
const int irsensorPin = 2; // the number of the irsensor pin
const int go_ledPin = 8; // the number of the Green LED pin
const int stop_ledPin = 7; // the number of the Red LED pin
// variables will change:
int irsensorState = 0; // variable for reading the irsensor status
void setup()
{
Serial.begin(9600); //sets the baud rate at 9600 to match the one set on the SSC-32 board
pinMode(irsensorPin, INPUT); // initialize the irsensor pin as an input
pinMode(go_ledPin, OUTPUT); // initialize the LED pins as an outputs
pinMode(stop_ledPin, OUTPUT); // initialize the LED pins as an outputs
digitalWrite(go_ledPin, HIGH);
digitalWrite(stop_ledPin, HIGH);
park(); // park ARM to starting position
}
void loop(){
irsensorState = digitalRead(irsensorPin); // read the state of the ir sensor value
checksensorLED();
getround();
}
void checksensorLED()
{
if (irsensorState == LOW) { // check if the ir sensor is triggered, if it is, the ir sensor is LOW
// turn Green LED on, turn Red LED off:
digitalWrite(go_ledPin, LOW); // the LED's on this board light during low state...
digitalWrite(stop_ledPin, HIGH);
}
else {
// turn Green LED off, turn Red LED on:
digitalWrite(go_ledPin, HIGH);
digitalWrite(stop_ledPin, LOW);
}
}
void getround()
{
if (irsensorState == LOW) { // check if the ir sensor is triggered, if it is, the ir sensor is LOW
//Move arm to pick up round:
delay(2000);
Serial.println("#5 P1500 T1000 <cr>");
Serial.println("#2 P1790 T1000 <cr>");
Serial.println("#3 P840 T1000 <cr>");
Serial.println("#0 P690 T1000 <cr>");
delay(1000);
Serial.println("#1 P1620 T1000 <cr>");
delay(1000);
Serial.println("#4 P1435 T1000 <cr>");
delay(1000);
(the remaining code is more "Serial.println("#5 P1500 T1000 ");" commands for the arms movement).
Any suggestions as to what mechanism would work in this instance would be greatly appreciated. I have tried if/else, then tried while with exactly the same results. I am having no luck adapting anything from the reference examples I can find.
Also: I have to base the count on how many times the arm is initiated, as opposed to counting the IR trips, as the sensor would count a number of times every cycle due to the gripper setting it off during the cycle.
I thank you for your assistance in advance.