Step 7Using the Software
When you run the code, two windows should pop up. One is the Webcam View and the other is the Control Panel.
In Manual Mode, you can aim and fire by pointing and clicking on the webcam view. In Autonomous Mode, the software takes over, and your gun gains a life of it's own! Give it a little time to adjust to the background, and then it will shoot at anything that enters its view.
Play around with the other functions as well - Auto/Semi-auto, hide camera view, etc.
Calibrating - your servo and camera arrangement is probably unique, so you will need to calibrate it the first time.
You can do this by adjusting the values of xMin, xMax, yMin, and yMax, at the beginning of the code. Play around with them untill you have the gun aiming where you point the mouse on the webcam view. A useful tool to do this is to watch the numbers scrolling by at the bottom of the Processing IDE while you run the code.
You may also need to calibrate the servo positions set in the Arduino code:
To set the reloading position, change these lines :
if(digitalRead(7) == HIGH) {
xPosition = 110 ;
yPosition = 135 ;
fire = 0;
}
To set the home position (no USB communication), change these lines :
if(idle) {
idleCounter++;
if(idleCounter > 10000) {
analogWrite(5, 50);
delay(250);
digitalWrite(5, LOW);
idleCounter = 0;
}
else{
digitalWrite(5, LOW);
}
xPosition = 110 ;
yPosition = 100 ;
fire = 0;
}
To set the 'squeezed' and 'not squeezed' positions for the trigger servo, change these lines :
void Fire(int selector) {
if(selector == 1) {
fireTimer++;
if(fireTimer >=0 && fireTimer <= triggerTravelMillis) {
trigger.write( 90 );
digitalWrite(2, HIGH);
}
if(fireTimer > triggerTravelMillis && fireTimer < 1.5*triggerTravelMillis) {
trigger.write( 140 );
digitalWrite(2, LOW);
}
if(fireTimer >= 1.5*triggerTravelMillis) {
fireTimer = 0;
}
}
if(selector == 3) {
trigger.write( 90 );
digitalWrite(2, HIGH);
}
}
void ceaseFire(int selector) {
if(selector == 1) {
fireTimer = 0;
trigger.write( 140 );
digitalWrite(2, LOW);
}
if(selector == 3) {
trigger.write( 140 );
digitalWrite(2, LOW);
}
}
| « Previous Step | Download PDFView All Steps | Next Step » |












































Thaks and sorry for the grammar
Yes, you can control the turret using a joystick (plugged into the computer). It will require a few small code changes, put it has been done before.
good luck,
-Bob
They seem to repeat and they are laggy. I can hear parts of one sound playing while others play at the same time. Some play fine but others get stuck. Any ideas? Is there a way to stop previous sounds playing before telling a new one to play?
Can you tell me what operating system and software version you are using, thanks.
processing 1.2.1
turret_05_03
Thanks you. If you can fix this it would be great! I'l also look into it when I have time.
In either case. I successfully tested my turret today and aside from frequent jamming and glitchy sounds, it worked well and was very impressive. Thank you for this instructable!
I will continue to improve the design and code and will submit my turret to your "featured successful projects" page.
Mine just keep repeat the last word of the second sound track.
However, the tracking works perfectly even the sound if screwed up.