Asked — Edited
Resolved Resolved by Dunning-Kruger!

Best Way To Script And Build A Limit To Cont Servo

Ok I am sure someone has it listed in the threads ( cant find a specific one however) I have hacked printer parts to make a periscope lifter for my R2,and I am using an EZB 360 servo to power it.. however I need to be able to limit the up and down pretty precisely when I have the ezb execute the lift and lower script... I am guessing the only way to do this would be limit switches at the top and bottom of the physical lifer mechanism.. If so can anyone guide me on how that would look like scripted ? And no I cant do a simple "timing" script as the timing varies and a half second off either way will break the lifter. Thanks in advance :)


ARC Pro

Upgrade to ARC Pro

Stay on the cutting edge of robotics with ARC Pro, guaranteeing that your robot is always ahead of the game.

#1  

As you mentioned you could use limit switches (you will need a pull up or pull down resistor depending on how you wired them) and something like ADC_Wait to monitor the switches Maybe something like this?

#180 value may need to be 1 if the servo moves in the wrong direction and vice versa


if($periscope = 0) #periscope is down so move it up
Servo(D0,180) #may need to be 1

ADC_Wait(ADC0, LOWER, 50) #might need to use HIGHER instead of LOWER here
$periscope = 1 #periscope is up
Servo(D0,107) #servo 360 stop command

else #periscope is up so move it down
servo(D0,1) #may need to be 180

ADC_Wait(ADC1, LOWER, 50) #bottom switch on adc port 1
$periscope = 0 #periscope is down
Servo(D0,107) #servo 360 stop command

endif

Also I would advise you update to the new ezb4 x/2 board (if you haven't done so already) as it way faster at monitoring analog and digital reads. Not to mention other superior features as well...

#3  

Another way you can do this is to wire microwitchs into the motor circuit. One one each of the power lines. Then when the motor hits one of the switches the power will be cut and the motor stops. The trick to get the motor moving again after power is cut by the open switch is to place a diode on each switch in the proper way to get the motor to accept reversed power from a hbridge. Then all you need is script a digital on, sleep() for however long it takes the move to complete and then digital port off.

PRO
Synthiam
#4  

Also, have you thought about using the electrical PCB and potentiometer of a standard servo and hack to your application?

I'm with Richard on recommending the /2 upgrade as well. I see you have a /1 comm board still. The /2 will provide increased communication speed (about 100 times faster): EZ-B v4/2 Comm Upgrade

#5  

How many turns of the 360 servo does it take to fully deploy or retract the periscope? Could you use a sail winch servo? https://hobbyking.com/en_us/turnigytm-tgy-6114md-digital-sail-winch-servo-drum-type.html for instance can be programmed to turn 1 to 6 full rotations.

You'll need to calibrate with the EZ-B since position 0 to position 180 won't indicate degrees anymore, just min and max.

Alan

#6  

Thanks for help guys:) I got lazy (still recovering from holidays ) and just put a limit switch at top and one at bottom. Now I have a peri up button and peri down with each respective button having a termination of script once digital port reads "true" and its working good for my lazy man fix:) ( Cant say my bootleg limit switches are pretty ...but they work lol )

#7  

Quote:

I got lazy (still recovering from holidays ) and just put a limit switch at top and one at bottom. Now I have a peri up button and peri down with each respective button having a termination of script once digital port reads "true" and its working good for my lazy man fix Smile ( Cant say my bootleg limit switches are pretty ...but they work lol )

Perfectly legitimate solution. A lot of times a bunch of us will throw out a bunch of answers to a question just to show those coming later that there are multiple ways to do things. Some will work better in a situation than others. Limit switches are perfectly fine as long as you absolutely have the script that listens for them running any time the periscope is moving.

Alan