Welcome to Synthiam!

The easiest way to program the most powerful robots. Use technologies by leading industry experts. ARC is a free-to-use robot programming software that makes servo automation, computer vision, autonomous navigation, and artificial intelligence easy.

Get Started
Guernsey
Asked — Edited

Progress And Scripting

Hello.
Just a quick update and some issues I have.
The hex that is still nameless is awesome. EZ Builder is super awesome.
Ive got the hex walking ( not quite in a straight line) and rotating left.
Ive also managed to set up a sharp IR sensor to initiate attacks.
EZ builder crashes if I use the radar but I found an IR script and adapted it for my use which kind of works.

Now you guys need to understand I have written a few basic websites in html back in the 90s and dabbled a little with arduino and have recently started looking at C++ so I am relatively new to this.
The script is supposed to initiate an attack and bite from the IR reading.
if messed with it for about a day now and it has worked on a couple of occasions but I think there are some conflicting instructions that im yet to understand with my limited knowledge of EZ Builder hierarchy and scripting.

I have added some pics to show the Standing position, the attack position and the fangs which I have yet to attach to a mini servo I have wired to the EZ-B.


User-inserted image


User-inserted image


User-inserted image


So on to the Script
I have had it running and detecting the IR distance and going into attack and making sounds, it even did it once when I didnt expect it and it made me jump.
but sometimes and now every time it just disconnects the EZ-B when the IR is detected and the script keeps running.

Im kinda stabbing in the dark changing stuff around and its not working now.

here is the script:

# Bite using IR sensor on ADC port

# Adjust values below for configuration
$iradcport = ADC0 # Change for ADC Port with sensor attached
$maxirdistance = 100 # Change for maximum distance from object before biting in units



Goto(detect)

:detect
$currirdistance = GetADC($iradcport)
if ($currirdistance >= $maxirdistance)
Goto(bite)
endif
Sleep (50)
Goto (detect)

:bite
ControlCommand ( "Auto Position", AutoPositionAction, "Attack")
Servo (D11,100)
ControlCommand( "Soundboard V4", Track_4 )
Sleep (100)
Servo (D11,50)
Return()

Ok Script dogs, tear it apart !
:D:D:D

Andre


ARC Pro

Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

PRO
Synthiam
#1  
1) You aren't waiting for the Auto Position Action to finish before checking the ADC and looping again. So you're locking up the system by over and over and over and over and over and over and over and over and over and over and over and over and over again running the Auto Position Action.

Check and wait until the Auto Position action is completed.

2) Also, there was a GOTO at the beginning which just went to the next line...

3) The GOTO when finding the action is kind of irrelevant because the code can be placed wthin the IF/ENDIF

4) PS, when pasting code, place it within the [ code ] and [/ code ] blocks so it will be easier for others to read:)

Code:



# Bite using IR sensor on ADC port

# Adjust values below for configuration
$iradcport = ADC0 # Change for ADC Port with sensor attached
$maxirdistance = 100 # Change for maximum distance from object before biting in units

:detect
$currirdistance = GetADC($iradcport)

IF ($currirdistance >= $maxirdistance)

ControlCommand ( "Auto Position", AutoPositionAction, "Attack")

servo (D11,100)

ControlCommand( "Soundboard V4", Track_4 )
Sleep (100)

servo (D11,50)

WaitFor($AutoPositionStatus = 0)

ENDIF

Sleep (100)

Goto (detect)

#2  
Shouldn't that also be a <=? If I am reading this right, it is biting when the target is not near it, instead of when it is in range.

Alan
PRO
Synthiam
#3  
Ah yeah - I don't know which way the sensor returns. Does that sharp sensor return a higher voltage when near and lower voltage when away? I forget - I believe it's the latter. I feel the sensors output voltage is relative to the amount of IR received from the IR Receiver, which would mean higher voltage is closer object. In which case, he would have it correct with a >=


*EDIT: Yes, he has it correct according to the sharp datasheet graph


User-inserted image