A Special Thanks to Colin. For helping me with the WebCam calibration concept way back when.
Visit my blog, for all other details not contained in this instructable.
Update: HACK-A-DAY Post checking out the turret. Very flattered from these guys words.
Remove these ads by
Signing UpStep 1Get an "Electronic" Airsoft BB Gun. And Slice it open.
If you are in the U.S. Say just as the title says, go to any Department Store and buy one.
Look for guns that look easy to cut or to take apart.
After you've got your gun, open it up (follow this guide).
As you can see, it is very simple. If you power the motor, you fire the pistol. Before you hack it open you do this by closing the circuit by pushing a switch with your finger as you pull the trigger. But there are many, many ways to close an electric circuit, and you can get very creative. In this project we are going to use Relays to do that.
If you are not in the U.S, this may take some doing.
I am obviously not in the U.S. but I got Lucky. A friend of mine gave me his.
'(Gracias Pinche Bronzon!! Ahi esta el Robot que te dije que iba a hacer con tu Pistola.)'
If you are in Mexico: 'jalense a los bazares o a los mercados y busquen a la gente que vende cuchillos y pistolas tipo militar. las tiendas de chucherias afuera de los super mercados (Soriana y la Comer y demas) a veces las tienen. De ultimas, preguntenle a algun amigo que le gusten las gotchas si tiene una o sabe donde comprarla. En Mexico es comun que vendan gotchas y Airsoft Guns en las mismas tiendas.'
| « Previous Step | Download PDFView All Steps | Next Step » |




























































I will post the results!
resistance is futile....
Sorry for the very late response. yes, you can use micro servos.
The servos I used were way over caculated. The bearings help a lot with the load!
Be sure to use ball bearings for the Y Axis servo and push bearings for the X Axis Servo.
I think the best choice you have is to use a "Pan and Tilt" mechanism and attach it directly to the Airsoft Gun's body.
It requires only two servos and the firing signal.
Lynxmotion has some sweet pre-made "Pan and Tilt" assemblies.
As for the weight, it depends on the servos, the mechanism's material and the gun.
Good luck!
Sub GetMotion()
Static Counter As Single 'counter
BoxesX = 50 'from 1 to 50 50 default on x and y
BoxesY = 50 'from 1 to 50
AveragePixelLoop = 30 'from 1 to 250 30 default
For Px = 0 To (MotionPic.Width) Step Int(MotionPic.Width / BoxesX)
For Py = 0 To (MotionPic.Height) Step Int(MotionPic.Height / BoxesY)
pixx = Fix(Px / (MotionPic.Width / BoxesX))
pixy = Fix(Py / (MotionPic.Height / BoxesY))
For Repeat = 0 To 5 ' default is 5
ColorSumStr = Right$("000000" + Hex(GetPixel(MotionPic.hdc, Px + Repeat, Py + Repeat)), 6)
ColorRedStr = Mid$(ColorSumStr, 5, 2)
ColorGreenStr = Mid$(ColorSumStr, 3, 2)
ColorBlueStr = Mid$(ColorSumStr, 1, 2)
ColorRedDec = Val("&H" + ColorRedStr)
ColorGreenDec = Val("&H" + ColorGreenStr)
ColorBlueDec = Val("&H" + ColorBlueStr)
AveragePixel(Repeat) = ColorRedDec + ColorGreenDec + ColorBlueDec
Next
Counter = Counter + 1
If Counter = AveragePixelLoop Then Counter = 1
mdSample(pixx, pixy, 0) = 0
mdSample(pixx, pixy, Counter) = 0
For Repeat = 0 To 5
mdSample(pixx, pixy, 0) = mdSample(pixx, pixy, 0) + AveragePixel(Repeat)
mdSample(pixx, pixy, Counter) = mdSample(pixx, pixy, 0) + AveragePixel(Repeat)
Next
AverageSum = 0
For Repeat = 1 To AveragePixelLoop
AverageSum = AverageSum + mdSample(pixx, pixy, Repeat)
Next
AverageSum = AverageSum / AveragePixelLoop
'preveri pro~enje motion-a
If Abs(mdSample(pixx, pixy, 0) - AverageSum) > mdTriger Then
MotionPic.Line (Px - 4, Py - 4)-Step((MotionPic.Width / BoxesX) - 4, (MotionPic.Height / BoxesY) - 4), , B
If pixx = 0 Then Label2.Caption = 84 Else Label2.Caption = (pixx * 5)
If pixy = 0 Then Label3.Caption = 84 Else Label3.Caption = (pixy * 3) '(MotionPic.Height / 2)
Label9.Caption = MotionPic.Height
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(8)
MSComm1.Output = Chr$(Label2.Caption)
MSComm1.Output = Chr$(85) 'Terminate and Update
MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(9)
MSComm1.Output = Chr$(Label3.Caption)
MSComm1.Output = Chr$(85) 'Terminate and Update
Here is what you are going to:
Find the x,y value for a single pixel you want in your image. (this will be what ever you are aiming for)
Manually move your servos so that the gun is aiming to that point in the real world (if you shoot, it's going to hit where your point is)
Wirte down the value for the servo moving your X and write down the value for the servo moving Y.
Do this for all XY points for the entire cross section of the image.
Once you have the data to what servo values correspond to what x/y value, make a mathematic regresion (you can use excell or a TI calculator to do this)
Your program should be something like:
getXPixel();
getYPixel();
servoX = regression in fuction of X pixel data;
servoY = regression in fuction of Y pixel data;
shootFace();
If you run into trouble let me know.
It would be awesome if you post some pics of your work in progress.
Good Luck.
I just found the perfect plataform:
http://www.trossenrobotics.com/roboard.aspx
The automated aiming mode is very simple. The OpenCV Library has an example on face recognition. In that Example, you will see that the program draws a circle around the face it is detecting.
If you look at the code as how the program draws that circle, you will see it uses a point of the image (pixel) as a center to trace the circle. This point is almost always smack in the middle of the face.
About the accuracy, it will depend on how well you calibrate your robot.
Use the FIXED WebCam to use this pixel (in x, y, coordinate system of the image) as your reference point. In order to get the position of your servos as a function of the center point of the circle, you will need to gather at least 20 points of data across the mid-section of your screen and use a spreadsheet to do a cuadratic o cubic regresion.
That means that you will have to experimentally (trial and error) find at least 20 points where the servos are in such position, that the gun is pointing to where the center of the drawn circle is. And you have to find this 20 points across the mid section of the image.
I hope that answered your question, if not, ask again what ever you are stuck in.
Good luck in that part of the world of yours! Just don't be mean to your neighbors.
Saludos,