Asked — Edited

Use Camera As A Button

You can use a Camera in ARC as a button without any external code. I created a custom multicolor named "Dark" and set it a orange/red range and I set it to the maximum size for detection. This is what worked best for me as I discovered the orange/red color range was reflected off my hand as it moved toward the camera to block the view.

I started out using the darkest shade of blue possible but that color did not perform as well for me. I encourage you to experiment as skin tone, lighting conditions and even the type of camera will very from user to user.

Below is my script which I named CamBlocked It only looks for the $CameraObjectColor value to change and so this scripts acts as a sort of "hair trigger".


#updated 7/21/14
$CameraObjectColor = ""

:Start
IF ($CameraObjectColor = "Dark")
    ControlCommand("Bender Sounds", Track_19)
sleep(500)
ENDIF 

$CameraObjectColor = ""
sleep(500)

goto(start)

The line below is the action I have chosen to perform when my "Dark" multicolor object is detected.

ControlCommand("Bender Sounds", Track_19)

Video Tutorial:

Here is an alternative take on the script. Rich's modified script uses the WaitForChange function and $CameraIsTracking value. My tests showed that I had to wave my hand slowly more closely in front of the camera for 1-3 seconds in order to trigger the event.


#from Rich 7/21/2014
$CameraObjectColor = ""
WaitForChange($CameraObjectColor)

:Start
IF ($CameraObjectColor = "Dark")
ControlCommand("Bender Sounds", Track_19)
EndIf

WaitForChange($CameraIsTracking)

$CameraObjectColor = ""

WaitForChange($CameraObjectColor)

Goto(start)

If you test the two scripts, please let us know the results.


ARC Pro

Upgrade to ARC Pro

Elevate your robot's capabilities to the next level with Synthiam ARC Pro, unlocking a world of possibilities in robot programming.

United Kingdom
#9  

Dude, Python is a pain, it depends too much on indentation if memory serves me correctly. While I know bits of Python it's not a language I wanted to spend more time than was necessary on. Good luck to you!

#10  

Thank you Richard! My hats off to you for learning Python. I have a virtual VMware Raspberry pi but I never have time to play with it. I'd like to hear about your experience with it as you learn more.

#11  

I hear you Rich... I am learning C too via arduino... one has to try new things to figure out for oneself what works and what doesn't... I mean if someone told me (and if I listened to them) that ez robot was lame, quite possibly I would have never discovered the awesomeness of EZ Robot.... Bottom line, I just want to expand my knowledge and contribute to some threads I previously had no idea what was being discussed... Just want to lean, that's all...

United Kingdom
#12  

Oh don't get me wrong, I wasn't saying don't learn Python at all (learn it, that way I can call on you for help!). I'm in the same boat, trying to learn, just never seem to have the time to sit down with my Arduino or Visual Studio at the moment. The decent weather we are having at the moment doesn't help, we don't see the sun often so when it's out so am I:)

Back on topic for a moment though, the main script may work better if you used a WaitForChange() rather than a sleep. The way it runs at the moment it waits half a second after each pass of the IF and will repeat the command(s) in the IF if your hand if held over the camera for too long. Where if you used a WaitForChange() and didn't reset the variable back to nothing it would only loop back when the variable changes.

I haven't tried it so don't know if it would open up any problems but that's just my first thoughts on the script part of it. I'll give it a try when I get chance but just putting it out there if anyone fancied trying a different method to the scripting part.

#13  

That did not work at all. Unless I'm not implementing it the way you are describing?


$CameraObjectColor = ""

:Start
IF ($CameraObjectColor = "Dark")
    ControlCommand("Bender Sounds", Track_19)
ENDIF 

WaitForChange(500)

goto(start)

United Kingdom
#14  
WaitForChange($CameraObjectColor)

It'll hold at that line until the colour changes.

#15  

Ok, I didn't catch the variable went in the brackets, my bad. I have this code now:


$CameraObjectColor = ""

:Start
IF ($CameraObjectColor = "Dark")
ControlCommand("Bender Sounds", Track_19)
ENDIF 

WaitForChange($CameraObjectColor)

goto(start)

It'll detect the "Dark" multicolor, but the variable $CameraObjectColor no longer changes. It seems to make the above script work once and done. I believe in part it is because I am not currently tracking any other multicolor. I added another multicolor and the above script worked again after another multicolor was detected.

If I wanted to look for the color dark....then ignore it until another color was detected and then watch for it again I think the WaitForChange would work.

I think part of your idea Rich was to show a way to avoid multiple triggers of the camera button function? In my video Bender usually detected the multicolor a couple of times so the "gasp" sound file had the effect of being pressed, play, play, play. Which sounds cool when used as a way to make the robot appear afraid. But if you were using the camera as a button to active another function like a motor control you would not want forward, forward, forward or script start, start, start - that might be bad!

I added an extra sleep within the IF statement and this appears to correct for multiple triggers.


$CameraObjectColor = ""

:Start
IF ($CameraObjectColor = "Dark")
    ControlCommand("Bender Sounds", Track_19)
Sleep(500)
ENDIF 

$CameraObjectColor = ""
Sleep(500)

goto(start)

United Kingdom
#16  

I've just got home so give me 5 or 10 minutes and I'll have had a proper look at the script:)