Asked — Edited

I Have A Tiny Question.

I'm going to make my rc car robot autonomous.

theres just one problem... It's an rc car! it has custom turn and drive scripts!

does anyone have an idea or example on how to make a script for radar? one that I can modify to accomidate my custom movements?


ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

United Kingdom
#9  

You can use ControlCommand to stop scripts, so use to to start, sleep for however long then stop script.

United Kingdom
#11  

In EZ-Script on the right you can click on the tap for controls and it lists them all, click on the right one and it instantly pastes it in the script.

Depending on if it's a script on it's own or part of script manager will depend on the command. But the easiest way is to do as I described above.

User-inserted image

#12  

heres the script updated.


# Ping Object Avoidance
# Using Ultra Sonic Ping Sensor on servo for avoidance

# Adjust values below for configuration
$pingport = D5 # Change for Ping Port
$echoport = D6 # Change for Echo Port
$maxdistance = 35 # Change for maximum distance from object before avoiding in units
$onlyforward = 0 # Only if moving forwards? 0 = no, 1 = yes
$reverseturn = 0 # Reverse before turn? 0 = no, 1 = yes
# centreturndirection removed
$turnamount = 500 # Change for how long to turn for in ms
$reverseamount = 500 # Change for how long to reverse for in ms (if applicable)
$movementspeed = 255 # Change for movement speed

# Sweep variables
$sweepmin = 25 # Change for min limit
$sweepmax = 77 # Change for max limit
$sweepcenter = 52 # Change for center position
$sweepservo = "D3" # Change for servo port
$sweepprevious = 1000 # Do not change

# -- The Script --

GOTO(sweep)

# Check if only to detect when moving forwards
:detect
IF ($onlyforward = 1)
  IF ($Direction = "Forward")
    GOTO (detectstart)
  ELSE 
    GOTO (detect)
  ENDIF 
ELSE 
  :detectstart
  $currentdistance = GetPing($pingport, $echoport)
  IF ($currentdistance <= $maxdistance)
    GOTO(avoid)
  ENDIF 
    
    # Sweep the servo to the next position
  GOTO(sweep)
  
  SLEEP (50)
  GOTO(detect)
ENDIF 
  
  # The avoidance script
:avoid
controlcommand("reverse",scriptstart)
Sleep(1500)
controlcommand("reverse",scriptstop)
IF ($sweepcurrent = $sweepmin)
  controlcommand("Right", scriptstart)
  Sleep(1500)
  controlcommand("Right", scriptstop)
ELSEIF ($sweepcurrent = $sweepmax)
  controlcommand("left",scriptstart)
  Sleep(1500)
  controlcommand("left",scriptstop)
ELSE 
  Servo($sweepservo,$sweepmin)
  $pingmin = GetPing($pingport, $echoport)
  Servo($sweepservo,$sweepmax)
  $pingmax = GetPing($pingport, $echoport)
  Servo($sweepservo,$sweepcenter)
  IF ($pingmin > $pingmax)
    controlcommand("Right", scriptstart)
    Sleep(1500)
    controlcommand("Right", scriptstop)
  ELSE 
    controlcommand("Left", scriptstart)
    Sleep(1500)
    controlcommand("Left",scriptstop)
  ENDIF 
ENDIF 
RETURN()

# The sweep script
:sweep
# Check for previous position, if no position assume to be $sweepmax
IF ($sweepprevious = 1000)
  $sweepprevious = $sweepmax
ENDIF 
  
  # Get the current position
$sweepcurrent = GetServo($sweepservo)

# Move in the correct direction and store previous position
IF ($sweepcurrent = $sweepmin)
  $sweepprevious = $sweepcurrent
  Servo($sweepservo, $sweepcenter)
ELSEIF ($sweepcurrent = $sweepcenter and $sweepprevious = $sweepmin)
  $sweepprevious = $sweepcurrent
  Servo($sweepservo, $sweepmax)
ELSEIF ($sweepcurrent = $sweepcenter and $sweepprevious = $sweepmax)
  $sweepprevious = $sweepcurrent
  Servo($sweepservo, $sweepmin)
ELSE 
  $sweepprevious = $sweepcurrent
  Servo($sweepservo, $sweepcenter)
ENDIF 
  
  # Return back to the main script
Return()

is this good?

United Kingdom
#13  

Upon a quick scan through that looks like it'll work.

One thing you could do though since your movement differs to the normal and you will have different factors which determine turning. How about adding in some code so left and right are based on previous travel direction?

For instance, if the car is moving forwards then a left turn would be forward and left or right would be forward and right. But, if the sensor reading is very close to an object then make it back up and turn a little, then forwards and turn.

Excuse the crude sketch but something like this...

User-inserted image

#14  

ok so make it back up then turn if value is 220-255(very close)?

United Kingdom
#15  

very close on a ping sensor is the lower end. so 1 to 15 or so... I think it measures inches but not 100% sure since I use IR (which are the other way around)

However, it should never get to a distance where it needs to back up since the further distance of forward turning will happen first, unless it turns into a wall. But you could have other variables and sensors etc. set up to have it decide what action to take.

#16  

ok. i'll look into it. will probably post it tomorrow. maybe tonight.