Professional Documents
Culture Documents
“TORRETA DE CONTROL”
Barrientos Romero Juan Gabriel
Realizar un prototipo de una torreta de control. Para desarrollar este robot se usó el prototipo rubber
band Centry Gum. El diseño de la torreta de control se
1.2 Objetivos Específicos muestra en la siguiente figura
2. Fundamento Teórico
Las guerras desde su antigüedad han involucionado FIGURA 1. Diseño de las piezas en el software
de manera exponencial desde su inicio, con la SolidWorks
finalidad de velar los intereses geopolíticos que se
suscitan. 4.1. Materiales
// servo positions:
#define panServo_scanningMin 0 // how int panServoPin; // Arduino pin for pan
far side to side you want the servo
#define panServo_scanningMax 180 // gun int tiltServoPin; // Arduino pin for tilt
to turn while 'scanning' servo
#define scanningSpeed 2000 // total time int triggerServoPin; // Arduino pin for
for 1 sweep (in milliseconds) trigger servo, or output to trigger MOSFET
int firingIndicatorLEDPin; // Arduino pin for
#define panServo_HomePosition 97 // firing indicator LED
'centered' gun position int USBIndicatorLEDPin; // Arduino pin for
#define tiltServo_HomePosition 65 // USB indicator LED
int modeIndicatorLEDPin; // Arduino pin for
#define panServo_ReloadPosition 97 // Mode indicator LED
convenient position for reloading gun int reloadSwitchPin; // Arduino pin for input
#define tiltServo_ReloadPosition 150 // from RELOAD switch
int disablePlatePin; // Arduino pin for input
#define triggerServo_HomePosition 120 // from disable plate
trigger servo not-firing position int electricTriggerPin; // Arduino pin for
#define triggerServo_SqueezedPosition 90 // output to trigger MOSFET
trigger servo firing position boolean invertInputs; // TRUE turns on
internal pull-ups, use if closed switch connects arduino
// more trigger settings: pin to ground
#define triggerTravelMillis 1500 // how // pin assignments for each hardware setup are set in the
often should trigger be squeezed (in semi-auto function assignPins() at bottom of code
firing)
// higher value = slower firing, lower value = faster typedef struct config_t
firing {
// Booleans but int
// disable plate settings: int controlMode;
#define disablePlateDelay 5000 // how int safety;
long to disable sentry when plate is pressed (in int firingMode;
milliseconds) int scanWhenIdle;
int trackingMotion;
// ammunition magazine/clip settings: int trackingColor;
boolean useAmmoCounter = false; // if int leadTarget;
you want to use the shot counter / clip size feature, int safeColor;
set this to true int showRestrictedZones;
int clipSize = 5; // how many shots int showDifferentPixels;
before the gun will be empty and the gun will be int showTargetBox;
disabled (reload switch resets the ammo counter) int showCameraView;
int mirrorCam;
// int soundEffects;
<==================================
=================================== // Integers
====> int camWidth;
// End custom values int camHeight;
int nbDot; boolean idle = true;
int antSens; boolean scanning = false;
int minBlobArea; boolean scanDirection = true;
int tolerance; boolean disabled = false;
int effect; unsigned long int disableEndTime;
int trackColorTolerance; int scanXPosition = panServo_scanningMin;
int trackColorRed;
int trackColorGreen; int shotCounter = 0; // number of shots fires
int trackColorBlue; since last reload
int safeColorMinSize; boolean clipEmpty = false; // is the ammo
int safeColorTolerance; magazine empty?
int safeColorRed;
int safeColorGreen;
int safeColorBlue; byte indicator; // if 'a', continue, if 'z', idle
int idleTime; byte x100byte; // some bytes used during
serial communication
// Floats byte x010byte;
double propX; byte x001byte;
double propY; byte y100byte;
double xRatio; byte y010byte;
double yRatio; byte y001byte;
double xMin; byte fireByte;
double xMax; byte fireSelectorByte;
double yMin; byte scanningByte;
double yMax;
void setup(){
} assignPins();
configuration;
configuration configuration1; pan.attach(panServoPin); // set up the x axis
servo
#include <Servo.h> pan.write(panServo_HomePosition);
tilt.attach(tiltServoPin); // set up the y axis servo
Servo pan; // x axis servo tilt.write(tiltServo_HomePosition);
Servo tilt; // y axis servo pinMode(electricTriggerPin, OUTPUT); // electric
Servo trigger; // trigger servo trigger, set as output
digitalWrite(electricTriggerPin, LOW);
int xPosition; // pan position trigger.attach(triggerServoPin); // servo for trigger,
int yPosition; // tilt position set that servo up
int fire = 0; // if 1, fire; else, don't trigger.write(triggerServo_HomePosition);
fire
pinMode(USBIndicatorLEDPin, OUTPUT); // set
int fireTimer = 0; up USB indicator LED
int fireSelector = 1; // 1 - semi-automatic pinMode(modeIndicatorLEDPin, OUTPUT); // set
firing, auto/semi-auto gun up Mode indicator LED
pinMode(firingIndicatorLEDPin, OUTPUT); // set
// 3 - full automatic firing, full-auto gun up firing indicator LED
pinMode(reloadSwitchPin, INPUT); // set up
int idleCounter = 0; reload switch input
int watchdog = 0; pinMode(disablePlatePin, INPUT); // set up
int watchdogTimeout = 2000; disable plate input
if(invertInputs) {
digitalWrite(reloadSwitchPin, HIGH); // }
turn on internal pull-up else if(indicator == 'r'){ // start restore
digitalWrite(disablePlatePin, HIGH); //
turn on internal pull-up restore();
}
Serial.begin(4800); // start }
communication with computer }
else{
} watchdog++;
if(watchdog > watchdogTimeout) {
void loop() { idle = true;
if (Serial.available() >= 10) { // check to see }
if a new set of commands is available }
watchdog = 0; if(idle) { // when Arduino is not getting
indicator = Serial.read(); // read first byte in commands from computer...
buffer Serial.write('T'); // tell the computer that
if(indicator == 'a') { // check for 'a' Arduino is here
(indicates start of message) idleCounter++; // periodically
idle = false; blink the USB indicator LED
idleCounter = 0; if(idleCounter > 1000) { //
digitalWrite(USBIndicatorLEDPin, HIGH); // sequenceLEDs(1, 100);
light up the USB indicator LED delay(10);
x100byte = Serial.read(); // read the
message, byte by byte // digitalWrite(USBIndicatorLEDPin, HIGH);
x010byte = Serial.read(); // //
x001byte = Serial.read(); // // delay(250); //
y100byte = Serial.read(); // // digitalWrite(USBIndicatorLEDPin, LOW); //
y010byte = Serial.read(); // idleCounter = 0; //
y001byte = Serial.read(); // } //
fireByte = Serial.read(); // else{ //
fireSelectorByte = Serial.read(); // digitalWrite(USBIndicatorLEDPin, LOW); //
fireSelector = int(fireSelectorByte) - 48; // } //
convert byte to integer xPosition = panServo_HomePosition; // keep x axis
scanningByte = Serial.read(); servo in its home position
if((int(scanningByte) - 48) == 1) { yPosition = tiltServo_HomePosition; // keep y axis
scanning = true; servo in its home position
} fire = 0; // don't fire
else{ }
scanning = false; else{ // when Arduino is getting commands
} from the computer...
} xPosition = (100*(int(x100byte)-48)) +
else if(indicator == 'z'){ // check for command (10*(int(x010byte)-48)) + (int(x001byte)-48); //
to go idle (sent by computer when program is decode those message bytes into two 3-digit numbers
ended) yPosition = (100*(int(y100byte)-48)) +
idle = true; (10*(int(y010byte)-48)) + (int(y001byte)-48); //
} fire = int(fireByte) - 48; // convert byte to
else if(indicator == 'b'){ // start backup integer
}
backup();
if(scanning) { digitalWrite(modeIndicatorLEDPin, LOW);
digitalWrite(modeIndicatorLEDPin, HIGH); delay(100);
if(scanDirection) { }
scanXPosition += 1;
if(scanXPosition > panServo_scanningMax) { if(disabled) {
scanDirection = false; xPosition = panServo_ReloadPosition; // if it is
scanXPosition = panServo_scanningMax; flipped, override computer commands,
} yPosition = tiltServo_ReloadPosition; // and send
} the servos to their reload positions
else{ fire = 0; // don't fire while reloading
scanXPosition -= 1; digitalWrite(modeIndicatorLEDPin, HIGH);
if(scanXPosition < panServo_scanningMin) { delay(50);
scanDirection = true; digitalWrite(modeIndicatorLEDPin, LOW);
scanXPosition = panServo_scanningMin; delay(50);
} }
}
xPosition = scanXPosition; pan.write(xPosition); // send the servos to
yPosition = tiltServo_HomePosition; whatever position has been commanded
fire = 0; tilt.write(yPosition); //
// float xRatio;
float yRatio;
int possibleX = camWidth/2; public boolean useInputDevice = false; // use a joystick or game
int possibleY = camHeight/2; controller as input (in manual mode)
public boolean inputDeviceIsSetup = false;
int displayX = camWidth/2;
int displayY = camHeight/2; public ControllIO controlIO; // more stuff for using a joystick
or game controller for input
int oldX = camWidth/2; // smoothing (contributed by Adam public ControllDevice inputDevice;
S.)
int oldY = camHeight/2; // smoothing public ControllButton[] buttons = new ControllButton[30];
int xdiff; // smoothing public ControllSlider[] sliders = new ControllSlider[10];
int ydiff; // smoothing
public float smoothingFactor = 0.8; // smoothing public ControllButton[] fire_buttons = new ControllButton[0];
public boolean activeSmoothing = true; public ControllButton[] preciseAim_buttons = new
ControllButton[0];
String strTargetx; public ControllButton[] centerGun_buttons = new
String strTargety; ControllButton[0];
String fireSelector; public ControllButton[] autoOn_buttons = new
String scanSelector; ControllButton[0];
public ControllButton[] autoOff_buttons = new
public boolean showDifferentPixels = false; ControllButton[0];
public boolean showTargetBox = true; public ControllButton[] inputToggle_buttons = new
public boolean showCameraView = true; ControllButton[0];
public boolean firingMode = true; // true = semi, public ControllButton[] randomSound_buttons = new
false = auto ControllButton[0];
public boolean safety = true;
public boolean controlMode = false; // true = public ControllSlider[] pan_sliders = new ControllSlider[0];
autonomous, false = manual public ControllSlider[] tilt_sliders = new ControllSlider[0];
public boolean soundEffects = false; // set to true to public ControllSlider[] panInvert_sliders = new ControllSlider[0];
enable sound effects by default public ControllSlider[] tiltInvert_sliders = new ControllSlider[0];
public boolean scanWhenIdle = true;
public boolean trackingMotion = true;
public float xPosition = camWidth/2;
int idleTime = 10000; // how many milliseconds to wait public float yPosition = camHeight/2;
until scanning (when in scan mode)
int idleBeginTime = 0;
boolean scan = false; String[] inStringSplit; // buffer for backup
int controlMode_i, safety_i, firingMode_i, scanWhenIdle_i,
public String serPortUsed; trackingMotion_i, trackingColor_i, leadTarget_i, safeColor_i,
showRestrictedZones_i, showDifferentPixels_i,
int[][] fireRestrictedZones = new int[30][4]; showTargetBox_i, showCameraView_i, mirrorCam_i,
int restrictedZone = 1; soundEffects_i;
boolean showRestrictedZones = false;
if (fire == 1) { if (selectingSafeColor) {
idleBeginTime = millis(); stroke(0, 255, 0);
scan = false; strokeWeight(2);
} fill(red(currFrame[(mouseY*width)+mouseX]),
else { green(currFrame[(mouseY*width)+mouseX]),
if (millis() > idleBeginTime + idleTime && controlMode blue(currFrame[(mouseY*width)+mouseX]));
&& scanWhenIdle) { rect(mouseX+2, mouseY+2, 30, 30);
scan = true; }
}
else { soundTimer++;
scan = false; if (soundTimer == soundInterval) {
} randomIdleSound();
} soundTimer = 0;
}
if (!safety) {
fire = 0; for (int i = 9; i >= 1; i--) {
} prevFire[i] = prevFire[i-1];
}
strTargetx = "000" + str(targetX); // make into 3- prevFire[0] = fire;
digit numbers int sumNewFire = prevFire[0] + prevFire[1] + prevFire[2] +
strTargetx = strTargetx.substring(strTargetx.length()-3); prevFire[3] + prevFire[4];
strTargety = "000" + str(targetY); int sumPrevFire = prevFire[5] + prevFire[6] + prevFire[7] +
strTargety = strTargety.substring(strTargety.length()-3); prevFire[8] + prevFire[9];
fireSelector = str(0);
if (firingMode) { if (sumNewFire == 0 && sumPrevFire == 5) { // target
fireSelector = str(1); departed screen
} int s = int(random(0, 6));
else { if (s == 0)
fireSelector = str(3); playSound(1);
} if (s == 1)
if (scan) { playSound(5);
if (s == 2) }
playSound(9); else {
if (s == 3) pixels[i] = color(0, 0, 0);
playSound(12); }
if (s == 4)
playSound(13); boolean motion = (((abs(red(currFrame[i])-
if (s == 5) red(Background[i])) + abs(green(currFrame[i])-
playSound(20); green(Background[i])) + abs(blue(currFrame[i])-
} blue(Background[i]))) > (200-tolerance)) && trackingMotion);
boolean isTrackedColor = (((abs(red(currFrame[i])-
if (fire == 1) trackColorRed) + abs(green(currFrame[i])-trackColorGreen) +
strokeWeight(3); abs(blue(currFrame[i])-trackColorBlue)) < trackColorTolerance)
if (fire == 0) && trackingColor);
strokeWeight(1);
stroke(255, 0, 0); //draw crosshairs boolean isSafeColor = (((abs(red(currFrame[i])-safeColorRed)
noFill(); // + abs(green(currFrame[i])-safeColorGreen) +
line(displayX, 0, displayX, camHeight); // abs(blue(currFrame[i])-safeColorBlue)) < safeColorTolerance)
line(0, displayY, camWidth, displayY); // && safeColor);
ellipse(displayX, displayY, 20, 20); //
ellipse(displayX, displayY, 28, 22); // if (motion || isTrackedColor) {
ellipse(displayX, displayY, 36, 24); // screenPixels[i] = color(255, 255, 255);
if (showDifferentPixels) {
updateControlPanels(); if (effect == 0) {
prevTargetX = targetX; pixels[i] = color(diffPixelsColor[0], diffPixelsColor[1],
prevTargetY = targetY; diffPixelsColor[2]);
} }
else if (effect == 1) {
void autonomousMode() { pixels[i] = color((diffPixelsColor[0] + red(currFrame[i]))/2,
if(inputDeviceIsSetup) { (diffPixelsColor[1] + green(currFrame[i]))/2, (diffPixelsColor[2]
checkInputDevice(); + blue(currFrame[i]))/2);
} }
else if (effect == 2) {
if (selectingColor || selectingSafeColor) { pixels[i] = color(255-red(currFrame[i]), 255-
cursor(1); green(currFrame[i]), 255-blue(currFrame[i]));
} }
else { else if (effect == 3) {
cursor(0); pixels[i] = color((diffPixelsColor[0] + (255-
} red(currFrame[i])))/2, (diffPixelsColor[1] + (255-
camInput.update(); green(currFrame[i])))/2, (diffPixelsColor[2] + (255-
rawBackground = camInput.retinaImage(); blue(currFrame[i])))/2);
rawImage = camInput.image(); }
if (mirrorCam) { }
for (int i = 0; i < camWidth*camHeight; i++) { }
int y = floor(i/camWidth); else {
int x = i - (y*camWidth); screenPixels[i] = color(0, 0, 0);
x = camWidth-x; }
currFrame[i] = rawImage[(y*camWidth) + x-1];
Background[i] = rawBackground[(y*camWidth) + x-1]; if (isSafeColor) {
} safeColorPixelsCounter++;
} pixels[i] = color(0, 255, 0);
else { screenPixels[i] = color(0, 0, 0);
currFrame = rawImage; }
Background = rawBackground; }
}
loadPixels();
int safeColorPixelsCounter = 0; updatePixels();
(1)
http://projectsentrygun.rudolphlabs.com/successful-
projects