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

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?

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
#5  
how would you say
"if the ping sensor value=(3 quarters of the full value),
move servo full left. if value is below (3 quarters of the full value),
start "left" script for 1500 milliseconds
if value is above (3 quarters of full value)
move servo full right. if value is below (3 quarters of full value),
start "right" script for 1500 milliseconds
if value is still above(3 quarters of full value),
start "reverse" script for 1500 milliseconds
then check again.
turn towards lower value
then start over
United Kingdom
#6  

Quote:

if the ping sensor value=(3 quarters of the full value)

Full is 255, so 3/4 is 191.25 (I'll skip the maths). So make it 191 since it needs to be an integer really.

Code:


IF(GetPing($trig,$echo) = 191)
# Start script (fill in the blank with proper ControlCommand() params)
ENDIF

If it needs to be greater than or equal to then change the = for >=

Quote:

if value is below (3 quarters of the full value)

Code:


IF(GetPing($trig,$echo) < 191)
# Start script (fill in the blank with proper ControlCommand() params)
ENDIF


You cannot ControlCommand to run a script for a time period, that would need to be part of the script itself.

Use a label (i.e. :loop) and a goto to loop around. Add in a Sleep to avoid saturating the communications and bogging down ARC. Sleep(50) or Sleep(100) is usually all that's needed.

To turn towards the lower value you would need to use an if...

Code:


IF($value1 < $value2)
# Turn towards value 1
Else
# Turn towards value 2
ENDIF
#8  
oh and I was playing with your ping avoidance script and changed a couple things. i'll post the code so you can proof read.

Code:

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

# Adjust values below for configuration
$pingport = D0 # Change for Ping Port
$echoport = D1 # 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)
IF ($sweepcurrent = $sweepmin)
controlcommand("Right", scriptstart)
ELSEIF ($sweepcurrent = $sweepmax)
controlcommand("left",scriptstart)
Sleep(1500)

ELSE
Servo($sweepservo,$sweepmin)
$pingmin = GetPing($pingport, $echoport)
Servo($sweepservo,$sweepmax)
$pingmax = GetPing($pingport, $echoport)
Servo($sweepservo,$sweepcenter)
IF ($pingmin > $pingmax)
controlcommand("Right", scriptstart)
ELSE
controlcommand("Left", scriptstart)
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()
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.

Code:


# 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.
#17  
just started working on a siren script that will use motion tracking and a soundboard.

I need a way to say: start motion tracking(with horizontal servo moving back and forth slowly)
if motion detected start siren(track 1)
wait 5 seconds. if no motion detected go back to motion tracking.
United Kingdom
#18  
ControlCommands will start those, check the control section of EZ-Script for the commands.

You will need to create a loop so it goes for 5 seconds, with sleeps and a sound the correct length or have the sound 5 seconds long since soundboard doesn't loop the sound.

To loop for 5 seconds you'll need a counter and an if;

Code:


# 5 second loop
$x = 0
:loop
IF ($x <= 5)
$x = $x++
Sleep(1000)
Goto(loop)
EndIf


Depending on the sound, you may need to increase the condition of the if and reduce the sleep, say if $x <= 50 and sleep(100)
#20  
Hi guys sorry to butt in but I have a question.
I'm not very familiar with ARCs code yet but I do know programming in general so I have to ask,
I see you declare $onlyforward as 0 and check it to see if it's 1 but I don't see where it ever gets set to 1. Is it being set in one of the scripts you're calling?
#21  
It's a good question. I'm twelve so I don't have very much programing knowledge.

If your saying that you declare $onlyforward as 0 and it changes to 1, that could be caused by another script.
just my guess.
also, it would be better to make a new post for your question because it doesn't directly relate to what me and rich are talking about.

Rich should be able to answer that
United Kingdom
#22  
At the top of the script in the config area. There are options for everything. Setting this to 1 here before running the script will make it check for forward movement before doing anything.

Quote:


# Adjust values below for configuration
...
$onlyforward = 0 # Only if moving forwards? 0 = no, 1 = yes
#23  
My question was about your code specifically. For some reason I was thinking that $onlyforward was saying to go only forward, not trigger the script only if it is moving forward. I was reading it wrong. Thanks for you answers. I'll let you guys get back to it. I hope you get it all worked out. :-)
#24  
is this right? i'm working on my ar drone and I made this script to warn me when the battery is at minimum point.

Code:


#Low Battery script

$DroneBatterymin=14

:start

IF($DroneBattery=$DroneBatterymin)
Controlcommand("soundboard", Track_0)
ENDIF
Goto(start)