
leonardo46
Italy
Asked
— Edited

I'm a basic and assembler programmer ( PIC MCUs). I'm trying to put ezb scripts at work. I have a pot connected to adc0 (i.e. 0-3.3 V) and move the pot. I write this easy script in movement script, triggered by "forward" action panel :
sayezbwait("man") :auto $av=getadc(adc0) if $av>20 sayezbwait("dog") else sayezbwait("cat") endif goto(auto)
"man" is spoken once. Nothing else happens. I should have missed some banal detail Please help.
Here you go...
where are you executing this script? What is a "forward action panel"?
I havethe script in movement script. I click "forward" in Hbridge PWM movement control. Motors start correctlly, movement script panel says "forward". Only "man" said by ezb. No more audio. I'd expect "cat" or "dog" said by ezb.
Why you added "sleep(100) ?
because you will flood the data channel by querying a port without any delay. It would be higher priority than anything else. It would be like talking at someone and not letting anyone else talk.
On your microchip pic, your code runs linear one command at a time.
With ezrobot your program is threaded. Meaning there's many commands at a time running - like multitasking. You have to provide adequate time for other commands to have room. This is how programming in threaded environments works. The concept of a linear program is for microcontrollers Without an rtos.
so, how would you modify my code ?
Leonardo,
If you are using a "Custom Movement"
https://synthiam.com/Tutorials/Help.aspx?id=182
you can't block the code or use cpu intensive scripts
Check the picture:
solution:
movement script you assign a variable with a direction. creates and sets a variable $direction.
you add a new script control with your script, you start monitoring the variable from point 1, and you can keep a closed loop but you need to keep the delay in the loop to avoid flooding the ezb with multiple requests e.g. analog reads
You mean I might fix my code adding,e.g., a 100 ms delay after each time consuming operation , such as an a/d conversion ? I love PIC MCUs. No OS to disturb my program, and each statement executed in less than a uS !
please modify my example code , so I can understand how it had to be written
Leonardo,
I don't know what you want to do but i'll provide some examples.
example #1:
script monitors the $direction variable, when the variable changes a specific action (Say) is executed.