urbanh
USA
Asked
— Edited
I'm trying to build a robotic Target Practice Bot with one Servo. The servo raises the target up, and then releases the servo. At this point I can shoot the target with a nerf dart pushing the target back just a little.
Then I want it to run a script based on the if(GetServo()) function. However, it always returns the last servo Position programmed, NOT the actual position of the Servo. I'm using only components from the EZ-Robot kit.
Is there any way to get the actual value of the servo, as opposed to the last value sent to it?
It is impossible obtain the position of a servo by the servo itself. The servo position is specified by your controller (EZ-B, R/C, Etc). The controller broadcasts a special signal that the servo understands and moves into the respective position.
Learn how a servo works here: https://synthiam.com/Tutorials/Hardware.aspx?id=4
I think you're idea is neat, but you will not be able to determine the servo position that way. You can attach a Potentiometer (Also referred in short as POT) to the servo shaft. If you use a Peripheral Extension Cable (from our store) and connect to one of the ADC ports, you can determine the position of the POT.
To wire a POT, simply connect the +5 from the peripheral cable to the left pin of the pot. Connect the GND to the right pin of the pot. And connect the white/signal to the center pin of the pot.
Add the ADC control and voila... you can see the pot move. Use the GetADC() function in EZ-Script to obtain the value.
So do something like this...
That's awesome DJ sures! Thank you. One other thought, before I start hunting down a potentiometer. Can I make a trigger?
I'm thinking two cables running into a digitial port(or other port) and when they are a connected a script returns True, and when they are not connected they'll return False?
Thanks again.
You can use a trigger for sure. You can get creative and put a few triggers on the paddle so you know where it's been hit.
How do I wire the trigger? I've been playing around with the Read ADC control. It reads 5 volts when the red and black wire aren't connected, and the whole device shorts when they do connect eek. I tried inserting various resistors and LED's in between the cables, but haven't had any luck. I've no practical experience in circuitry.
Basically, how would I wire something as simple as this whisker trigger into the EZB? http://www.hobbyengineering.com/H1221.html
I'm guessing the coding is pretty easy too, but I'd appreciate any advice.
Thanks again DJ Sures!
The RED wire is +5, which is power. The GND wire is Ground. If you short (connect) the Red and Black, you will be shorting the power of the EZ-B. This will blow the fuse, or potentially damage the EZ-B voltage regulator.
Start at the tutorial section: https://synthiam.com/Tutorials/
And read about port types: https://synthiam.com/Tutorials/Hardware.aspx
Good luck
Got it! Thanks.
Here's the test code for anyone trying to figure out a switch.
:x If(GetDigital(d8) = 1) print("yes") sleep(1000) Goto(x)
When the power(red) and GND(white) wires are connected it'll return "yes".
You mean Power (RED) and Signal (white) are connected, it will return yes
Check this page: https://synthiam.com/Tutorials/Hardware.aspx?id=1
There is a diagram that I just added explaining the ports.
Also keep in mind that on a digital port, YES (true) is any voltage above 0 (gnd). If you connect a switch between +5 and Signal, it will occasionally respond with YES (true) when you move your hand near the switch. This is because your hand has static electricity and it will be conducted.
The way to get around this is to use a 75k (or any value really) resistor between Signal and GND. That way the Signal sees GND all the time. When the +5 is connected to Signal via the switch, it will now see +5 on the Signal and return True.
The resistor acts as a little cushion between the GND and Voltage. Resistors are like the water taps in your home. They can let more or less power pass through them (resistance).
So here's the Target Bot. D7 is the main servo. D8 is the switch, which uses the GND and Signal cables (no resistors required).
Servo(d7,38) Sleep(1000) Release(d7)
:main If(GetDigital(d8) = 0) Goto(hit) Goto(main)
:hit Servo(d7,80) Sleep(1500) say("Nice Shot") Servo(d7,38) Sleep(500) Release(d7) return()