designing an Automatic pop-up target using a geared DC motor

thatoneguy

Joined Feb 19, 2009
6,359
Just use the for loop to slowly change the servo position, with the delay inside the for loop, it will rotate slower.

Rich (BB code):
for b12 = 75 to 150 step 5 
          servopos 1,b12         
   pause servo_delay 
next b12
If you "unroll" the for loop block, the controller is sending these commands, the for loop simply saves you a ton of typing and code space. :)

Rich (BB code):
servopos 75
pause servo_delay
servopos 80
pause servo_delay
...
servopos 150
pause servo_delay
 

Thread Starter

MLD

Joined Dec 7, 2012
76
It seems this entire PICAXE code thing has scared everyone away from posting anymore here. Seems you are the only one around here that understands these codes. What book do you recommend to read to learn PICAXE basic code?
 

thatoneguy

Joined Feb 19, 2009
6,359
The picaxe forum has a lot of experts on it.

They are catching on more when people realize how low cost and easily implemented they are, so more code will be around in the next year or two.
 

John P

Joined Oct 14, 2008
2,026
It seems this entire PICAXE code thing has scared everyone away from posting anymore here. Seems you are the only one around here that understands these codes. What book do you recommend to read to learn PICAXE basic code?
Well, when this was a design project with a lot of possibilities, it was more interesting. Once it goes into a "black box" which involves programming one particular type of processor, it's just a question of how well you can write code for that unit and there isn't much else to say. Not "scared", just not much to contribute any more.
 

Bernard

Joined Aug 7, 2008
5,784
MLD is is about ready with electronics & machanical system is not far behind as shown in photo. All parts are finished, steel pickled & Cu plated ready for painting. System roughtly based on post 52. The round topped piece is the target, .196 in steel & has already been hit with 7 177 cal pellets which left visable indintations- wonder what a 22 is going to do.
 

Attachments

thatoneguy

Joined Feb 19, 2009
6,359
Finally after a bout with pnemonia, bad weather, bad disposition, bowling, & dancing, the parts are assembled into a working model of Pop-Up Target #1.
First: Does it work Well? Any modifications to the code from what was posted earlier prior to the servo code?

Second: Is it an optical illusion? I'm a bit confused. On the target plate itself, in the up position side view, I see a nut on the back and maybe screw on front. On the top view with the target plate down, I don't see a screw.

Was am I actually seeing?

It's the nut sticking out from the vertical plate, crossing the border between box and concrete on the horizontal, about 1/4 to 1/3 from the left edge: (Sorry for huge picture, I'm just pasting the attachment from above)

 

Thread Starter

MLD

Joined Dec 7, 2012
76
Bernard, Excellent work on that mechanism for the pneumatic model. When you are ready we will start working on the RC servo model.
 

Bernard

Joined Aug 7, 2008
5,784
Nice blowup, thatoneguy, that 1/4-20 nut is there, the head of bolt is hidden by angle of shot. There were 4, 1/4" bolts, but the center two were changed to 10-32 trus head screws to avoid interfearance with lifting arm & wheels. With 40 lb of air cycle time is about one sec, including target bounce supression. Stay tuned for rpt from MLD with live amo. Shipping Monday to east coast.
 

thatoneguy

Joined Feb 19, 2009
6,359
With 40 lb of air cycle time is about one sec, including target bounce supression. Stay tuned for rpt from MLD with live amo. Shipping Monday to east coast.
1 second between target falling, and actuator moving after random time, or 1 second between actuator starting to move and target ready? The latter should be close to instant.

Let me know if you need help modifying the code, if they will be built standalone like this, each could use an 08M2.
 

Bernard

Joined Aug 7, 2008
5,784
On time for air switch should be adjustable to obtain fastes reset time. Guestimate time on air SW activation: .2 s target uprite, .3 s debounce time, .1s lifting arm down.
 

thatoneguy

Joined Feb 19, 2009
6,359
Will this still be one controller per target, or will you be wiring the outputs from this box?

IIRC, the arm was deployed for 2 seconds then retracted, that should be reduced to about 0.75 seconds?

The settling time will change based on how well the hinge works, if it gets stiff, it will take longer, so I understand why the user would want it variable. Adding another thumbwheel type pot on an anlog input and doing similar math can take care of that if you are around to help with the wiring.

Please post the current working code on that unit, in case tweaks have been made to it. I'll update what you'd like for timing. The switch in the down position simply connects the air cylinder, correct?
 

Bernard

Joined Aug 7, 2008
5,784
The "switch", presume it referrs to reed SW which closes when target falls; it goes to MLD's control box. Air SW control also will come from control box.
 

Thread Starter

MLD

Joined Dec 7, 2012
76
thatoneguy, I need the code to use a 08M2 instead of using a 20M2 since Im only utilizing one channel on this model and this will minimize the circuit and keep it compact. I also need to wire up the down switch which tells the target is down to an input of the 08M2. Note: The output only needs to be active when the input is enabled. Keep in mind the Pot is still a good idea to have to vary the timing if necessary.

Please keep the code short and simple.
 

thatoneguy

Joined Feb 19, 2009
6,359
So it's an 08M2
Rich (BB code):
Read Value of potentiometer for user delay time
  Generate Random time from 0 to 7 seconds
  delay user selected delay + random time from 0-7 seconds
  if switch is closed
       toggle single output high
       wait 1.75 seconds
       toggle output low release cylinder
  else
go back to reading potentiometer for user delay
Please add any other features you'd like to that pseudo-code, such as another adjustment for time to have cylinder engaged (I think that is what you were referring to?)

Let me know if that is correct, such as switch open/closed state, what the value will be (+5V or???) when switch is closed, length of other delay if desired, etc.
 

thatoneguy

Joined Feb 19, 2009
6,359
Here is the new code for the single target reset using an 08M2.

I'm assuming the reed switch will apply +5V when target is down? If it is 5V when target is up, the if C.3 test just needs to be changed to zero instead of 1.

Please keep header if distributing source code, and add header to older versions (I'll edit the forum posts of mine with it).


Rich (BB code):
#picaxe08M2

; Automated Target random timer reset system on PICAXE 08M2 for MLD.
; Reads two potentiometers on IC Pins 6 and 5, switch on IC pin 4, and gives a 0V or 5V output on IC Pin 6
; Potentiometer on Pin 6 determines how frequently actuator will be reset (longest random time adjust)
; Potentiometer on Pin 5 determines how long the actuator is held high for (adjust for miminum required, plus a bit)
; Reed switch to input +5V When closed, indicating target is down, connected to IC Pin 4
; Actuator to reset target is connected to IC Pin 3
; 
; Created by thatoneguy for MLD, 2/21/2013 - http://www.allaboutcircuits.com
;
; More info at:http://forum.allaboutcircuits.com/showthread.php?t=77919
; 
; This code may be re-used, modified, and shared by anybody, as long as the information and credits above are not altered or removed.
; Please post improved code ideas and updates to a thread in the electronics chat area of allaboutcircuits.com
; Have fun, remember to wear eye and hearing protection when shooting!


;declarations
; i/o 1 (IC pin 6/C.1) is ADC Input for random delay time between target reset attempts
; i/o 2 (IC pin 5/C.2) is ADC Input for actuator cylinder up time adjustment
; i/o 3 (IC pin 4/C.3) is Digital Input for Reed Switch to get target state
; i/o 4 (IC pin 3/C.4) is OUTPUT to Target Solenoid

;variables
symbol duadjust = b10   ;duadjust variable is 8 bit ADC Read of user potentiometer A for actuator active time 
symbol radjust = w6    ;radjust variable is 8 bit ADC Read of user potentiometer B for target reset random delay time
symbol adjust = w7         ; expanded delay adjust time between target reset attempts
symbol delaytime = w8  ;delaytime variable  random requires word variables
symbol duptime = w9    ;duptime variable determines how long target return actuater is engaged

;initialization
low  C.4                ;Set C.4 as an output and low state on power up.
input C.1, C.2, C.3        ;C.1 is long delay adjust, C.2 is actuator up-time adjust, C.3 is input reed switch (0 or 5V)
readadc c.1,radjust    ; Pot connected between V+ and Gnd, wiper connected to C.1 (08M2 pin 6).  Used for adjusting random timing.
readadc c.2,duadjust  ;Pot connected between V+ and GND, wiper to C.2 (08M2 pin 5), Used for adjusting actuator active time
delaytime = radjust + duadjust  ;seed PRNG with ADC Read values, which will vary with temp
                              ;more unique seed should give different delays on each startup.

;main procedure block                      
main:

readadc c.1,radjust    ; Pot connected between V+ and Gnd, wiper connected to C.1 (08M2 pin 6).  Used for adjusting random timing.
radjust = radjust * 100   ; make 0-254 number 0-25400 

readadc c.2,duadjust  ;Pot connected between V+ and GND, wiper to C.2 (08M2 pin 5), Used for adjusting actuator active time
duptime = duadjust * 10 ; make 0-254 number between 0-2540
duptime = duptime + 460 ; actuator adjust time is now number between 460 and 3000

random delaytime      ; get pseudo-random number between 0 and 65535
delaytime = delaytime % 7000  ; Mod returned number from 0-65535 with 7000 to get number between 0 and 7000
delaytime = delaytime + radjust ; add user chosen delaytime to delay.   This number will be used for seed of next random delay

pause delaytime        ; wait for 0-25400 user set milliseconds + 0-7000 random milliseconds to proceed
       ; at this point, power has been on, and 0 to 32.4 seconds have passed since last test of switch on C.3/ IC pin 4
       ; The pause delaytime command can be put AFTER the pinC.3 test below (prior to high C.4) to only delay if switch is pressed, but
       ; runnning in this fashion will generate more diverse random numbers since the random function is called more frequently.
if pinC.3=1 then     ; if reed switch is at 5V, target is down and needs to be reset
    high C.4        ; engage actuator to reset taret
    pause duptime    ; wait for actuator to get target reset, 460-3000 milliseconds (0.46 to 3 seconds)
    low C.4            ; after delay, release actuator for spring to return to low position
endif
goto main
 
Last edited:

Thread Starter

MLD

Joined Dec 7, 2012
76
thatoneguy, I will test the code with the hardware to see how it functions. Either or on the switch being active low or active high should be fine. I can wire up the hardware as needed for the switch.

Yes, timing I wanted with both options to either be adjusted via the code / software or the pot / hardware.


Thanks
 

thatoneguy

Joined Feb 19, 2009
6,359
The way it is written currently, the reed switch should be pulled to ground with a 10k resistor when target is up, and when target is down, it should put 5V onto the pin.

If the delays are too long between resets, you can put the pause inside the if statement that checks for the resets, as it is, it should give a nice, random amount of time, as a little extra time delay will be present prior to checking the switch.

The more frequently a random number is generated, the greater the chance the pattern will not repeat, since it's a psuedo-random generator, each seed will result in the same pattern every time. If you add the reed switch in the loop, the timing isn't constant, so the pseudo-random comes closer to true random, if that makes sense.
 
Top