Asked — Edited

Halloween Is Coming Soon

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


ARC Pro

Upgrade to ARC Pro

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.

#1  

Yes, any camera recognized by windows should be able to work in ARC.

#2  

I hope it works. I assume I will have to set the contrast settings full to make it track. I will post my tests.

#3  

Hello to All,

My Madame Ninndo, the fortune teller is progressing well. I will post pictures soon.

I have built a number of Auto Position actions. I listed them in the script manager. I can run each of them by clicking the corresponding start button in the manager. Works well !

I want to activate the action by pressing a push button. Upon completion I also want to have the next action to be ready to run. Sort of like a sequencer. (FIFO) Upon the pressing of the button again, the next action will run, and upon completion advance to ready the next one. Can someone help?

I planned on using a standard push button on a digital input to be the signal. Do I need to build an anti-bounce circuit?

My scripting skills are minimal, but I want to learn.

Thanks,

Ron R

United Kingdom
#4  

Monitor the digital port with the push button on it. If it's on D0 for example


WaitUntil(d0 = true)

NB: I haven't used EZ-Script for over 6 months so my commands may be rusty, I'm unable to find the EZ-Script manual online so can't confirm WaitUntil() is a valid command or the syntax is correct.

Have a counter which increments so you can cycle through actions.


$counter = 0

Increment it each time the button is pushed


$counter++

Run the required script dependant on the counter


IF($counter = 1)
  ControlCommand...
ElseIF($counter = 2)
  ControlCommand...
...

Build in some kind of loop to avoid the counter going over the number of actions at the end of the if nest


...
ElseIF($counter > 10)
  $counter = 0
EndIF

#5  

Thanks Rich, I will give it a try.

Ron R

#6  

Hi Rich,

I wasn't able to get the script you gave me to work. I understand how it flows but must be missing something. I am trying to get some thing easy to work to learn the basics, but I am missing something.

I tried the following to confirm the input script is ok, but it doesn't work. I must not have the right code.

If (d0= true)

Sleep(500)

Say ("EZB is on") Sleep (500)

Endif

)I also tried it without the Sleep commands)

I tried WaitUntil (d0=true) but no good.

I put a digital read block to see if the input works and it does.

Do you know of any working examples anywhere ? The sequencer is the last part needed for this project, and I want to get it working by Wednesday.

Thanks

Ron R

#7  

Ron you should use the UBB code when posting things like code snippets... Try this... It waits for a digital change then executes the "if" condition...


:top
# Digital_Wait(D0, ON, 50) waits 50ms for digital change
WaitForChange(GetDigital(D0))
If(GetDigital(D0)=1) #true
Sleep(500)

Say ("EZB is on")
Sleep (500)

else #false
#do something else
endif
goto(top)

#8  

Hello Richard R,

Thanks, I will try the code.

My next step is a sequencer. This script is just to check to be sure the input works and doesn't bounce thus skipping steps.

Ron R

#9  

Rich and Richard R, I need an example of a running counter, and how to set it up.

I don' know the way to set up the code to identify the counter, set the initial count to zero, and make it increment,. Rich showed me the code needed but I need an example somewhere to get a idea.

I would think this would be a good tutorial. Multiple digital inputs could operate different sequences. I know others new to scripting would use it.

Ron R

#10  

Hello

Here is the code I tried for the counter/sequencer. I know I am missing something, but I think I am on the right track. Any advice?

Digital_Wait(D0, ON, 50) waits 50ms for digital change

WaitForChange(GetDigital(D0))

$counter=0

if(GetDigital(D0)=1) #true Sleep(500)

$counter++

if($counter =1)

Say("EZB is on") Sleep (500)

if($counter=2)

Say("one, two") sleep(500)

if($counter=>3) #false do something

endif

The digital switch works now. I assume I need to add a 10k resistor from signal to ground to hold it low and work when I push the button.

Ron R

#11  

Once I get the counter running I will want it to loop. I will change the last line to

If($counter=>10)

$counter=0

Do I put in some kind of Goto to bring it to the top or leave an endif? I want it to run until I stop it in the script box.

Ron R

#12  

Hi Richard R, Rich and All,

The button is working and I can run single scripts. I am still trying to get the counter to work. It is the last part needed to finish Mandame Ninndo. The code I tried hasn't worked. I know I am close, but missing something. A working 3 step counter with a loop example would help me. I need to build the 25 step sequencer to run the "fortune" list and animation.

@Rich The example is the function I want, but I need to know a little more on how to build the counter.

I also need to learn how to post the code from my script list. @Richard R mentioned it. Is there a tutorial?

Any help would be appreciated. My deadline is coming up soon.

Thanks,

Ron R

#13  

Your code re-worked to run in a loop... You need an "endif" for every "if" statement used (see below)... to post code use the UBB code on the right side of the page... look down where it says code... use .... [codes] then your code you want to post [/codes] after your code... NOTE codes above should be code not codes.... Had to use codes or the format wouldn't show when I posted this... example...

[codes] ... (note you will type code not codes)

#your code you want to post

[/codes] ... (note you will type code not codes)


$counter=0
:loop
WaitForChange(GetDigital(D0))

if(GetDigital(D0)=1) # button press was true
Sleep(500)

$counter++ #add 1 to the button counter

if($counter =1)

Say("EZB is on")
Sleep (500)

elseif($counter=2)

Say("one, two")
sleep(500)

elseif($counter=>3) 

print("do something else")

endif
endif
goto(loop)

#14  

Thanks Richard R.

I did't know what statements to use with what, but I am learnring. I will test out what you showed me, then build it larger and try and run the first section of the "fortunes".

Ron R

#15  

Hello,

Sequencer update.. All is working.. I advance every time the button is pressed. It loops back to zero after 30 skits. I hope to run full skits, which includes movement, text to speech and relay controlled lighting next week.

It works in pieces, but the full test will be next week. I will post my progress then.

Ron R

#17  

Hello to All,

I have a final bug which I need help with. I have loaded all the code and I found the push button counter script kind of works. It advances to the next skit when pushed, and sequences properly.

My problem is the audio seems to work ok but the servos do not operate correctly when I use the sequence script. If I advance the script manager using the start button for a script, each script plays correctly. When I use the input button with the sequencer the servos begin to step slowly through their movement, and the time to run the Auto Position frames slows way down.

I think my problem is the signal to the script manager from the sequence script because the command from the sequencer is maintained. Could this causing the problem? or should it be that way? When I shut off the script I wrote for the sequencer during the running of the script, the skit then runs at normal speed.

This is the sequence script and is in a script box by it self.


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

if(GetDigital(D8)=1) # button press was true
Sleep(5)

$counter++ #add 1 to the button counter

if($counter =1)

Sleep (5)
Set(D11, on)
ControlCommand("Script Manager", ScriptStart, "Script 1") 

Sleep (5) 
Set(D11, off) 

elseif($counter=2) 

sleep(5)
Set(D11,on)
ControlCommand("Script Manager", ScriptStart, "Script 2") 


sleep(5)
Set(D11,off) 
elseif($counter=3)
ControlCommand("Script Manager", ScriptStart, "Script 3") 



sleep(5)

elseif($counter=4)
ControlCommand("Script Manager", ScriptStart, "Script 4") 



sleep(50)

elseif($counter=5)
ControlCommand("Script Manager", ScriptStart, "Script 5") 



sleep(50)

elseif($counter=6)
ControlCommand("Script Manager", ScriptStart, "Script 6") 



sleep(50)

elseif($counter=7)
ControlCommand("Script Manager", ScriptStart, "Script 7") 


sleep(50)

elseif($counter=8)
ControlCommand("Script Manager", ScriptStart, "Script 8") 



sleep(50)

elseif($counter=9)
ControlCommand("Script Manager", ScriptStart, "Script 9") 


sleep(50)

elseif($counter=10)
ControlCommand("Script Manager", ScriptStart, "Script 10") 


sleep(50)

elseif($counter=11)
ControlCommand("Script Manager", ScriptStart, "Script 11") 


sleep(50)

elseif($counter=12)
ControlCommand("Script Manager", ScriptStart, "Script 12") 


sleep(50)

elseif($counter=13)
ControlCommand("Script Manager", ScriptStart, "Script 13") 

sleep(50)

elseif($counter=14)
ControlCommand("Script Manager", ScriptStart, "Script 14") 


sleep(50)

elseif($counter=15)
ControlCommand("Script Manager", ScriptStart, "Script 15") 


sleep(50)

elseif($counter=16)
ControlCommand("Script Manager", ScriptStart, "Script 16") 


sleep(50)

elseif($counter=17)
ControlCommand("Script Manager", ScriptStart, "Script 17") 



sleep(50)

elseif($counter=18)
ControlCommand("Script Manager", ScriptStart, "Script 18") 


sleep(50)

elseif($counter=19)
ControlCommand("Script Manager", ScriptStart, "Script 19") 


sleep(50)

elseif($counter=20)
ControlCommand("Script Manager", ScriptStart, "Script 20") 

$counter=0

Sleep(50) 

elseif($counter=20) 

print("return")

endif
endif
goto(loop)

Anyone see why it doesn't run correctly?

Ron R

PS I hope the UBB code works

#18  

A quick look. Almost done once sequencer works.

User-inserted image

Ron R

#19  

One problem I see is the amount of time you have given the Control Commands to execute may not be long enough. The Sleep time is in milliseconds so ;


Sleep(1000) # sleep for 1 second
Sleep(5) # sleep for 5 milliseconds 

Maybe try increasing the sleep commands to give time for everything to run.

#20  

I have changed the time ranges from 50 to 500 and still had the same problem. The original time was 500. It signals and advances every time, but the problem is the effect on the script. I seems to slow the script it calls way down. I don't know how to make it pulse the "Script start" ?

Ron R

#21  

How long does it take for each of your CC ' s to run? I know in my scripting if it takes 3 seconds for a CC to run, I have a 3 second Sleep after it. That way the script won't move to the next function until that one has run. If I don't give a CC enough time to run weird things happen.

#22  

My scripts are driven by a sequencer. When a push button hooked to D8 is pushed the script starts. The problem is the servos move real steppy and slow. If I shut the script box which holds the button and sequencer script off while the script is running, everything speeds up to normal. If I operate a script using the script manager the scripts work fine.

The problem is in the button / sequencer script, but I don't know why. I messed with timing, but it doesn't change or resolve the problem.

Ron R

#23  

Hi @bhouston

I got weird things happening so I will add a lot of sleep time (5000) and give it a try. I will let you know if it helps

Thanks,

Ron R

#24  

Try using ScriptStartWait instead of ScriptStart. This keeps the program from proceeding until the skit ends. There may be unintended interactions occurring by letting the program flow continue right after starting the script for a given skit. That way the timing should not be so critical either.

#25  

Thanks, I will give that a shot too.

Ron R

#26  

Hello @bhouston and @WBS00001. You guys were right ! It was a timing issue. I put a 20 second sleep (upper average skit time) in between the CC and the problem went away.

I will put the program on the cloud when I am done.

Thanks for the replies which helped a lot.

I will post a video soon.

Ron R

#27  

Right on ! Glad you got it working. Looking forward to seeing the video.

#28  

I'm curious, did you try the ScriptStartWait thing? I would have thought it would have eliminated the need for any delay since it would have prevented anything from proceeding until the skit was done. Also, the same goes for any of the sub-scripts you run for the actual actions. If there are any CC calls there, they should be using the ScriptStartWait as well.

The only thing I can think of, offhand, that the ScriptStartWait would not take into consideration would be the actual movement of the servos since they are asynchronous to everything. That's where I would think delays might be needed. To give the servos time to do their thing before allowing the script to proceed.

#29  

Hi @WSB00001

When I tried the ScriptStartWait it didn't seem to work. The servos did the same slow step thing, but the audio still ran ok like normal. I then tried writing a Sleep with a time of 30 seconds (just a guess number) and the problem went away. The real problem is the interaction between my sequencer and the script manager and the sleep time assures enough time to run the script/skit. I am past my deadline so I loaded the sleeps based on the longest script/skit time, which fixed / patched the problem. Once everything is running, I will review the whole Sequercer / ContolCommand section and see if I can debug more and simplify it.

I will be posting the whole program to the cloud once it is done as it is now. That way you can look at what I did and how it runs.

I am a beginner at writing scripts so you may see weird program logic, but I am happy I wrote something with everyone's help that works.

Thanks for the thought of ScriptStartWait. (I learned a new command). It still may be the way to go.

Ron R

#30  

Would like to see a video of this project in action when you get the chance.... :)

#31  

I will be posting it soon. Look for it under the post "the Great Madame Ninndo"

Ron R

#32  

@ANDY ROID Have you changed the servo speeds at all or are you running all servos at the default "full" speed? Also be aware that the autopostioner controls servo speeds to an extent depending on whether you are using "jump to" or "Transition to" and CC commands...

Can you post an example of one of your actual servo movement scripts?

#33  

Hi Richard, I am working today so It will be a while. Just for information, I only had the problem when I ran the sequencer. The Auto Position scripts work fine from the Auto Position panel. (I am using some old VEX servos I was given, which are not the greatest, and run a bit lumpy, but they work.)

I am using the default settings for the servos, and the CC command is like we discussed earlier. I think the problem was caused by the control command. Maybe this caused a loop which would "pulse" the Auto Position file and cause the "steppy" problem. Once I added a time delay to allow the script to run to the end, the problem went away.

I would think the servo action shouldn't change by using the sequencer the way it did ? The added time delay seems to have fixed the original problem.

Anyway I will try to post it later today.

Thanks,

Ron R

#34  

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

#35  

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:


$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:


$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:


  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.

#36  

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

#37  

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:


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

Same for the Random number chooser:


  $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. :)

#38  

Thanks for the updates.. and the details. I will try it soon, and will post any questions.

Ron R