
Boon
Netherlands
Asked
— Edited
hi,
I want to do some simple scripting in ez-builder. But i cant find the syntax for some mathematical functions:
-arcsin/arccos
-power/square root
What is the code for those?
Hoep that helps
Alan
At the moment i am working on my own version of the radar. Ill have full control over when and where to measure distance. The robot will determine what kind of bends and manouvres it can make to avoid collision. And will do radar sweeps at specific angle ranges during these manouvres.
To calculate the desired steering wheel position these functions will come in handy.
Alan
Also i cannot promise any time of completion. I am new to ez-robot and college has priority.
here's a snippet of the radar code:
FileDelete("C:\...\newsweep.txt")
# Variables
# radarspeed is just like the servo increment speed in DJ's Radar Scan
$radardirection = 1
$radarspeed = 4
$servomax = 85
$servomin = 15
# d14 is the horizontal servo with the ping sensor on it
servo(d14,50)
:sweep
# first wait for fresh ping data
sleep(100)
$servopos = getservo(d14)
$distance = getping(d12,d13)
# calculate
# alpha is the angle of looking with center position being 0
# negative x is to the left of sensor, positive to the right
# (servo is below the sensor in this case)
$alpha = (50-$servopos)*$pi/($servomax-$servomin)
$y = cos($alpha)*$distance
$y = round($y,2)
$x = sin($alpha)*$distance
$x = round($x,2)
# i have a right and left led that light up but you could ignore this whole part
# it does give an idea how to use our data.
################
$dim = 100 - $distance
IF ($dim > 80)
$dim = 80
ELSEIF ($dim < 0)
$dim = 0
ENDIF
# (the width of my robot is about '40', with the sensor in the middle so '20' to either side)
IF ($x > -20 and $x <= 0 and $distance < 255)
# collision left
pwm(d4,$dim)
pwm(d5,0)
ELSEIF ($x >= 0 and $x < 20 and $distance <255)
# collision right
pwm(d4,0)
pwm(d5,$dim)
ELSE
pwm(d4,0)
pwm(d5,0)
ENDIF
##############
# save data
FileWriteLine("C:\...\newsweep.txt", "servo pos:$servopos:distance:$distance:x:$x:y:$y")
# Move the servo
# This could be adjusted to any desired behaviour
# i'm thinking of 1 or 2 full sweeps left to right, next decide how to drive
# and then sweep while driving, maybe look at interesting points more
IF ($radardirection = 1)
IF (($servopos+$radarspeed)<$servomax)
servoup(d14,$radarspeed)
ELSE
servo(d14,$servomax)
$radardirection = 0
goto(sweep)
ENDIF
ELSE
IF (($servopos-$radarspeed)>$servomin)
servodown(d14,$radarspeed)
ELSE
servo(d14,$servomin)
$radardirection = 1
ENDIF
ENDIF
goto(sweep)