Asked — Edited
Resolved Resolved by ptp!

Testing Ez-Scripts

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.


ARC Pro

Upgrade to ARC Pro

ARC Pro is your passport to a world of endless possibilities in robot programming, waiting for you to explore.

PRO
Synthiam
#1  

Here you go...


sayezbwait("man")
:auto
$av=getadc(adc0)
if ($av>20)
sayezbwait("dog")
else
sayezbwait("cat")
endif 
Sleep(100)
goto(auto)

where are you executing this script? What is a "forward action panel"?

#2  

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) ?

PRO
Synthiam
#3  

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.

PRO
USA
#5  

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:

User-inserted image

solution:

  1. movement script you assign a variable with a direction. creates and sets a variable $direction.

  2. 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

#6  

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 !

#7  

please modify my example code , so I can understand how it had to be written

PRO
USA
#8  

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.


:loop

WaitForChange($Direction)

if ($direction="Forward")
  Say("Going forward")
elseif ($direction="Reverse")
  Say("Going Reverse")
elseif ($direction="Left")
  Say("Going Left")
elseif ($direction="Right")
  Say("Going Right")
elseif ($direction="Stop")
  Say("Stopped!")
endif


Goto(loop)