Question
Asked September 9 2015

Community Question

Hello To All,

This time of year my old plc controllers and arduino ends up at my friends Halloween Barn. I program a number of displays for our friends, both fiends and ghouls amusement.

This year my poor robots will become brainless for a while and two of my ezbv4's will become an addition to the party. One may run a talking head with facial tracking.

I was wondering if the object tracking mode works with an IR camera hooked to my computer? I would like to use my second ezb to run servos and a couple relays using object location and tracking (people) in the dark.

Any experiences or ideas?

Ron R
October 24 2015
Hello @Richard R,

I posted to the cloud, the whole program of Madame Ninndo. I think you can look at the programming I used, instead of me posting pieces.

What you see works. I hope to refine it once I complete all my other projects. I need it running for the party so it is rough, but works. I have to add more "fortunes" and steps which will take some time and we are getting down to the last minute and I still have two more displays to get running.

If you look it over and see a problem I should fix, let me know.

Thanks for your help on this project. Remember, I am new to this programming.

Ron R
November 3 2015
Saw the videos of the Madam, they were great. As is the project.

Anyway, I've had a little time to look over your code and I thought I'd make one recommendation now. All those If-ElseIF statements in the main script can be eliminated by doing this:

Code:


$counter=0
:loop
WaitForChange(GetDigital(D8))
Sleep(5)

if(GetDigital(D8)=1) # button press was true
$counter++
ControlCommand("Script Manager", ScriptStart, "Script "+$Counter)
Sleep (25000)
endif
Goto(loop)


The "Script "+$Counter part is the trick. It makes the appropriate string such that the proper script will be called.

NOTE: Don't leave out the space at the end of the word Script. If you do, the script name would be Script1 or Script10, instead of Script 1 or Script 10 like it must be to match the actual script names.

A variation on that would be to use the GetRandomUnique() function like this:

Code:


$counter=0
:loop
WaitForChange(GetDigital(D8))
Sleep(5)
if(GetDigital(D8)=1) # button press was true
$Counter =GetRandomUnique(1,21)
if($Counter > 21)
$Counter =20
endif
ControlCommand("Script Manager", ScriptStart, "Script "+$Counter)
Sleep (25000)
endif
Goto(loop)

That will run one of the 20 scripts at random each time the button ispressed.

FYI, the GetRandom and GetRandomUnique functions have a bug in them that won't allow the max value to come up very often, if ever. That's why the extra lines are in the code above:

Code:


if($Counter > 21)
$Counter =20
endif

Notice that I put 21 in the GetRandomUnique function as the max value and not 20. Doing that makes 20 come up as often as any other number, overcoming the bug. But there is no 21st routine to run, so if 21 ever does come up, it will be set right back to 20. In this particular case, if it tried to call the nonexistent Script 21 nothing would probably happen anyway, but it's better to be safe.

I think I see why the ScriptStartWait I had recommended in a previous post didn't work as I thought it would, but I'll need to run some tests to be sure. I'll get back to you on it.
November 3 2015
Hi @WBS00001,

I had hoped you enjoyed the project. The scripting was my first attempt and proved to be a challenge. I thank you for your original help.

This new scripting you have shown me really improves the opportunities. I had planned on adding more fortunes to the program and the changes you proposed will really add a lot to the overall running.

I also have a project I have been working on,(Lillian) which, with this scripting, will make it work more like I want. It will run the phrases so they don't sound like "out of the can".

Thanks for the information and again I am happy you liked the "Madame".

Ron R
November 3 2015
Good, I hope the changes help. At least you won't have to add another elseif if you add another skit. In fact if you define the max number of skits at the start of the code, you won't have to change the number in all the places it's used. Like this:
$MaxLoop =20

That way, in the places you use 20 (or a number based on 20), you can do this instead:

Code:


|
if($Counter >= $MaxLoop )
$Counter =$MaxLoop
endif
|

Same for the Random number chooser:

Code:


$Counter =GetRandomUnique(1,$MaxLoop+1)
if($Counter >= $MaxLoop+1)
$Counter =MaxLoop
endif


That way you only have to change the $MaxLoop =20 to whatever number of skits is at any given time. All the places the number is used will automatically change to work properly.

Also, I realized I put the line Sleep(5) in the wrong place. It should have gone right after the WaitForChange(GetDigital(D8)) line. It needs to happen before you check it's state. I changed it in the pervious post.

Annnnd, I left out the set back to 0 at the count of 20 in the overall loop in the first example. No doubt you would have realized that, but being the stickler (meaning pest) I tend to be I thought I'd mention it anyway. :)
November 3 2015
Thanks for the updates.. and the details. I will try it soon, and will post any questions.

Ron R