Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked — Edited

Target Bot - Getservo() Question

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?

AI Support Bot
Related Content
Synthiam
PRO
Synthiam
#1  
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: http://www.ez-robot.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...

Code:



# Set the movement resolution. This is the range the POT can move to know if it's been shot
$resolution = 2

:MainLoop

# Move servo to position
servo(d0, 50)

# Sleep for a bit to make sure we're in position
sleep(500)

# Release the servo
Release(d9)

# sleep for a bit in case the servo moves after releasing
sleep(250)

# get the adc value of the pot before being shot
$pot = GetADC(adc0)

$rangeHigh = $pot + $resolution
$rangeLow = $pot - $resolution

print("Waiting to be shot")

:GameLoop

$newPot = GetADC(adc0)

if ($newPot > $rangeHigh)
Goto(BeenShot)

if ($newPot < $rangeLow)
Goto(BeenShot)

Goto(GameLoop)

:BeenShot

# We have been shot!
print("OUCH! You hit me")

# Move the servo down to pretend the nerf gun has a lot of juice
servo(d0, 20)

# Pause for a second
sleep(2000)

# Start the game over
Goto(MainLoop)
#2  
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.
PRO
Synthiam
#3  
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.
#4  
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!
#6  
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".
PRO
Synthiam
#7  
You mean Power (RED) and Signal (white) are connected, it will return yes:)

Check this page: http://www.ez-robot.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).
#8  
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()