United Kingdom
Asked — Edited

Ir Object Avoidance

Another script I've been writing is for the IR object avoidance as the built in control for IR doesn't work correctly with my IR sensor. I'm also trying to get to grips with EZ-Script so playing around is always a great idea in my book.

Adjust and/or comment on as you see fit. I've written it so it can be easily adjusted to suit your settings (and to show how variables can be used to make for easy adjustment over different projects/people)


# IR Detector Script
# Object avoidance using IR sensor on ADC port

# Adjust values below for configuration
$iradcport = ADC6 # Change for ADC Port with sensor attached
$maxirdistance = 35 # Change for maximum distance from object before avoiding in units
$irreverseturn = 0 # Reverse before turn? 0 = no, 1 = yes
$irturndirection = 0 # Change 0 = left or 1 = right
$irturnamount = 500 # Change for how long to turn for in ms
$irreverseamount = 500 # Change for how long to reverse for in ms (if applicable)
$irmovementspeed = 255 # Change for movement speed


# -- Do not modify below this line --
Goto(detect)

:avoid
IF ($irreverseturn = 1)
  reverse($irmovementspeed,$irreverseamount)
ELSEIF ($irturndirection = 0)
  Left($irmovementspeed,$irturnamount)
ELSE 
  Right($irmovementspeed,$irturnamount)
ENDIF 
Return()

:detect
$currirdistance = GetADC($iradcport)
IF ($currirdistance >= $maxirdistance)
  Goto(avoid)
ENDIF 
Sleep (50)
Goto(detect)

Also available on the EZ-Cloud here


ARC Pro

Upgrade to ARC Pro

Experience the transformation – subscribe to Synthiam ARC Pro and watch your robot evolve into a marvel of innovation and intelligence.

United Kingdom
#10  

# IR Detector Script
# Object avoidance using 2 IR sensors on 2 ADC ports

# Adjust values below for configuration
$iradcport1 = ADC6 # Change for ADC Port with sensor 1 attached
$iradcport2 = ADC7 # Change for ADC Port with sensor 2 attached
$maxirdistance = 35 # Change for maximum distance from object before avoiding in units
$ironlyforward = 0 # Only if moving forwards? 0 = no, 1 = yes
$irreverseturn = 0 # Reverse before turn? 0 = no, 1 = yes
$irturndirection = 0 # Change 0 = left or 1 = right
$irturnamount = 500 # Change for how long to turn for in ms
$irreverseamount = 500 # Change for how long to reverse for in ms (if applicable)
$irmovementspeed = 255 # Change for movement speed


# -- Do not modify below this line --

# The detection script
:detect
IF ($ironlyforward = 1)
  IF ($Direction = "Forward")
    GOTO (detectstart)
  ELSE 
    GOTO (detect)
  ENDIF 
ELSE 
  :detectstart
  $currirdistance1 = GETADC($iradcport1)
  $currirdistance2 = GETADC($iradcport2)
  IF ($currirdistance1 >= $maxirdistance OR $currirdistance2 >= $maxirdistance)
    GOTO(avoid)
  ENDIF 
  SLEEP (50)
  GOTO(detect)
ENDIF 

# The avoidance script
:avoid
IF ($irreverseturn = 1)
  reverse($irmovementspeed,$irreverseamount)
ENDIF 
IF ($irturndirection = 0)
  LEFT($irmovementspeed,$irturnamount)
ELSE 
  RIGHT($irmovementspeed,$irturnamount)
ENDIF 
RETURN()

That should do it I think, however it is untested (and I really need to revisit this code to change a few things I dislike about how I wrote it - which don't change how it works, it's just me being picky)

Edit: Or use Robot-Docs script (that'll teach me to post and eat dinner at the same time, I missed the updates...)

Canada
#11  

LoL thanks. I will try it out and see. The more I'm looking at it. The more sense the code makes. LoL know what I mean.

United Kingdom
#12  

Yep, I know exactly what you mean. That is what I try to achieve with my scripts too, hence the comments throughout most of them.

Give it a go, see what happens, I'm usually around to guide you if you get stuck.

Canada
#13  

:D hey Rich it works great. man, thanks, and i know i will be asking a few more questions later

#14  

Is the green face supposed to be:D or D Is the yellow face supposed to be;) or )

Canada
#15  

green is : D yellow is " )

Canada
#16  

no spaces, but it might not matter...