Welcome to Synthiam!

Program robots using technologies created by 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
Resolved Resolved by bhouston!

How To Make My Robot Give Different Responses When The Robot's Camera Detects 3

I want to make my robot do a function in such a way that for example, when it detects a red colour object, the robot responses as "I see a red colour object" and it does the same thing for blue or green object.

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.
#1  
Use the tracking script in the camera control and the variable $CameraObjectColor to return the colour detected...

User-inserted image


User-inserted image
Canada
#2  
this is a portion of script I am using to track a red tag to navigate in a room:

# Search for color tag containing QR code to help find destination
# set Color tracking ex:red
# start scanning for red card
# move to an open space ( adjust distance sensors to a larger detection area)
# if not found move to next open space
# on tracking result successful move toward it
# set QR code tracking on
# read code and move according to the code

$target=0

if ($destination = 1)
$target= ("Office")

ElseIf ($destination = 2)
$target= ("bedroom")

ElseIf ($destination = 3)
$target= ("lodge")

ElseIf ($destination = 4)
$target= ("workshop")

EndIf

If ($destination > 0)
ControlCommand("Camera", CameraColorTracking, "red") Enable red detection


Say("Scanning around to find red tag showing direction to the"+ $target)

# scan with head and/or body to detect color tag
# If no success move to an open space
endif

$CameraVerticalQuadrant= "Unknown" # reset variable for subsequent reading

RepeatUntil ($CameraVerticalQuadrant="Middle") # Variable switching state when red color is detected
Sleep(500)

EndRepeatUntil

$CameraVerticalQuadrant= "Unknown" # reset variable
Say("found red tag")
#3  
Aerius, I dont want it to detect one colour. I want multiple colours. If it detects Red colour, i expect the robot to do action A. If it detects Blue, action B and if Yellow, Action C.
#4  
@NYP.Shank_95 ... See my post above... You use $CameraObjectColor to determine which colour the camera is tracking....
#5  
@NYP.Shank_95
Here's a script that does what you want. You have to calibrate your colors in the "Multi Color" tab in the Camera control.

Code:


$sent = "Ok looking for different colors"
ControlCommand("2 Text to Speech", ScriptStart)

:loop
ControlCommand("Camera", CameraServoTrackEnable)
ControlCommand("Camera", CameraMultiColorTracking)

Waitfor($cameraverticalquadrant = "middle" and $camerahorizontalquadrant = "middle",1000)

If($CameraObjectColor = "red")
$sent = "red" # says red
ControlCommand("2 Text to Speech", ScriptStart)
ControlCommand("Camera", CameraMultiColorTrackingDisable)

endif
sleep(500)
ControlCommand("Camera", CameraServoTrackEnable)
ControlCommand("Camera", CameraMultiColorTracking)

Waitfor($cameraverticalquadrant = "middle" and $camerahorizontalquadrant = "middle",1000)

if($CameraObjectColor = "blue")
$sent = "blue" #says blue
ControlCommand("2 Text to Speech", ScriptStart)
ControlCommand("Camera", CameraMultiColorTrackingDisable)

endif
sleep(500)
ControlCommand("Camera", CameraServoTrackEnable)
ControlCommand("Camera", CameraMultiColorTracking)

Waitfor($cameraverticalquadrant = "middle" and $camerahorizontalquadrant = "middle",1000)

if($CameraObjectColor = "green")
$sent = "green" #says green
ControlCommand("2 Text to Speech", ScriptStart)
ControlCommand("Camera", CameraMultiColorTrackingDisable)

endif
sleep(500)
ControlCommand("Camera", CameraServoTrackEnable)
ControlCommand("Camera", CameraMultiColorTracking)

Waitfor($cameraverticalquadrant = "middle" and $camerahorizontalquadrant = "middle",1000)

if($CameraObjectColor = "yellow")
$sent = "yellow" #says yellow
ControlCommand("2 Text to Speech", ScriptStart)
ControlCommand("Camera", CameraMultiColorTrackingDisable)

endif

goto(loop)

You can put in whatever you want the robot to do after it detects the color. I have it just saying the color it sees.

Edit: It says the last color detect over and over again until it sees a different color. I'm working on that, if anyone has any suggestions, let me know
#7  
Richard, it has been there right from beginning. I was actually looking for something like what bhouston commented.
#8  
@NYP.Shank_95 You mean you wanted one of us to write the code for you?.... Ok, but it is hard to learn when you just copy someone else's work... I always try to do something myself first. I don't like asking for help (because I feel like I am admitting defeat) but sometimes If I get really stuck I ask here as there are a lot of smarter guys on here than me...
#9  
I've been working on this a little more and I have found that trying to use "Multi Color Tracking" it gets a lot of false positives due to other objects in the room. It's difficult to fine tune the colors. I do have it working using "Color Tracking" looking for red, green or blue.
#10  
You should make the script check for red, pause if no red found. then check for blue if none found check for green.

this could all be in the same script so it will look as if the robot is looking for all three and will give you the same results.
#11  
@ Luis, that's what I did in another script. In fact I used a basic script you posted a while ago and expanded it.
PRO
Synthiam
#12  
The multi color was designed for exactly what you're looking to do:)

Define each multi color. Then edit the "tracking start" script. Add an IF condition for each color that you are looking to detect. There is a variable that holds the current multi color detected :). It was quoted earlier in this thread.
#13  
bhouston, Luis Vazquez & DJ Sures, I have made my own If-Else code using the idea from bhouston and Luis. The syntax was correct but the camera gave me flop results for eg. I show Blue object, it either says it doesn't detect or it says it detects red or green. I have changed the contrast and saturation. Still the same. What should I do?

This is my coding:

Code:


If ($CameraObjectColor = "Red")
SayEZB(" I see Red object")
Sleep(1000)
ElseIf($CameraObjectColor = "Green")
SayEZB("I see Green object")
Sleep(1000)
ElseIf($CameraObjectColor = "Blue")
SayEZB("I see Blue object")
Sleep(1000)
EndIf
Canada
#14  
@NYP.Shank_95

Using Color Detection often gives unstable results depending of the light condition or object in the same nuance.
Example in my environment if I want to detect red, the camera will see my skin, my cabinet and other objects.
I am not telling it wont work, but you will need to select an object with a bright color and adjust "Min Object Size" and "Object Brightness"until you have stable result.

Personally I prefer using the Multi-Color tracking function. It gives you more set-up to play with.

User-inserted image


User-inserted image


as you can see, in multi color tracking mode the camera will detect strictly these colors.

you may also try this short script to experiment with it:

ControlCommand("Camera", CameraStart)

$CameraObjectColor = ("Unknown") # define variable

ControlCommand("Camera", CameraMultiColorTrackingEnable) # activate multi-color-tracking
:loop
$CameraObjectColor = ("Unknown") # clear variable at begining of the loop
SayWait("let me look")

IF ($CameraObjectColor = "Unknown") # if no detection of color define
SayWait(" No I do not see these color")
ENDIF

IF ($CameraObjectColor != "Unknown") # when variable is different than "Unknown"

SayWait(" Yes, yes I see" + $CameraObjectColor)
SayWait("the object is in" +$CameraVerticalQuadrant +"and" + $CameraHorizontalQuadrant) # tell localisation of color
ENDIF

goto (loop)

Here is the STL file
Multi-ColorTest.EZB