Pages: [1]   Go Down
Author Topic: Coil Rifle!  (Read 550 times)
0 Members and 1 Guest are viewing this topic.
NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 20
I am the eggman
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm trying to make an arduino controlled coil rifle.  the biggest problem i'm having right now is that it currently won't fire the first stage because the projectile is already moving too fast from the injector.  i have a phototransistor / ir LED setup which is supposed to fire an SCR when its interrupted.  
Code:
int trigger = 2;                 // Trigger, will fire injector when safety is off
int triggerpin = 0;              // value where trigger value is stored
int index1 = 0;                  // LDR value, stage 1
int index2 = 0;                  // LDR value, stage 2
int inputPin1 = 0;               // LDR in, stage 1
int inputPin2 = 1;               // LDR in, stage 2
int scrj = 4;                   // SCR in the first main stage  
int scr1 = 3;                   // SCR in the injector
int scr2 = 5;                   // SCR in stage 2

void setup()
{
  pinMode (scr1, OUTPUT);
  pinMode (scrj, OUTPUT);
  pinMode (scr2, OUTPUT);
  pinMode (trigger, INPUT);
  Serial.begin(9600);            // initialize serial communication with computer    
  backlightOn();
}

void loop()
{
  //looplcd();
  index1 = analogRead (inputPin1);            // sets index to LDR value
  index2 = analogRead (inputPin2);            // sets index2 to LDR2 value
  triggerpin = digitalRead(trigger);          // read input value
  //Serial.println(index1 , index2);          // prints LDR value, comment for final  
  // delay(10);

  {
    if (index1 < 550){
      digitalWrite (scr1, HIGH);
      delay(10);
    }
    else{
      digitalWrite (scr1, LOW);
    }
  }
  {
    if (triggerpin == HIGH){          
      digitalWrite(scrj, HIGH);          // turn SCRj ON
      delay(10);
    }
    else{
      digitalWrite(scrj, LOW);          // turn SCRj OFF
    }
  }
}

void looplcd()
{  
  selectLineOne();
  delay(100);
  Serial.print("BAT:");
  Serial.print(index1);
  Serial.print("% V:99m/s");
  selectLineTwo();
  delay(100);
  Serial.print("CAP:100% MAG:3 S");
  delay(100);
}
void selectLineOne(){  //puts the cursor at line 0 char 0.
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(128, BYTE);    //position
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(192, BYTE);    //position
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
  if (position<16){
    Serial.print(0xFE, BYTE);   //command flag
    Serial.print((position+128), BYTE);    //position
  }
  else if (position<32){
    Serial.print(0xFE, BYTE);   //command flag
    Serial.print((position+48+128), BYTE);    //position
  }
  else {
    goTo(0);
  }
}

void clearLCD(){
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(0x01, BYTE);   //clear command.
}
void backlightOn(){  //turns on the backlight
  Serial.print(0x7C, BYTE);   //command flag for backlight stuff
  Serial.print(157, BYTE);    //light level.
}
void backlightOff(){  //turns off the backlight
  Serial.print(0x7C, BYTE);   //command flag for backlight stuff
  Serial.print(128, BYTE);     //light level for off.
}
void serCommand(){   //a general function to call the command flag for issuing all other commands  
  Serial.print(0xFE, BYTE);
}



is there any hope for this, or am i going to have to skip the arduino and just fire it straight from the phototransistor?  
also, http://coilturret.blogspot.com/   (i really need to update this x])
Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is there any hope for this, or am i going to have to skip the arduino and just fire it straight from the phototransistor?
 
You may just have to do that; but have you considered using an interrupt routine for detection rather than polling the input?
« Last Edit: April 05, 2010, 11:58:02 pm by keeper63@cox.net » Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 20
I am the eggman
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no i have not.  how might i go about doing that?
Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have a look at these links:

http://www.arduino.cc/playground/Code/Interrupts
http://www.arduino.cc/en/Reference/AttachInterrupt
http://www.uchobby.com/index.php/2007/11/24/arduino-interrupts/

The catch, though, is that if you have more than one coil firing, while you will know that the interrupt occurred, you won't know (at least, in the interrupt handler itself) which photo-transistor triggered it; in the interrupt handler you would have to check the pins assigned to generate the interrupt and poll (read) each of them (and hope that the poll happens fast enough!) to see which one generated the interrupt, then use that info to fire the correct coil.

If your projectile is moving too fast, from either the injector, or subsequent acceleration by the coils - then you might get a trigger on the interrupt, but by the time you poll the pin, the projectile might have moved past the sensor that generated the interrupt. At that point, your choices would be to either use "direct connections" as you noted, or use a faster processor.
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Pages: [1]   Go Up
Jump to: