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

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

PRO
USA
#9  

example #2:

  1. script detects when the robot is moving
  2. while moving keeps reading the adc port 0
  3. if the adc port reaches a threshold more than 128, stops the robot

#prevMoving is inverted to detect first state as a change
if ($direction="Stop")
  $prevMoving = true
else
  $prevMoving = false
endif

:loop

$delay = false

if ($direction="Stop")
  $moving = false
else
  $moving = true
endif

if ($prevMoving!=$moving AND $moving)
  Say("We are moving!") 
endif

#keep the direction before any stop
$prevDirection = $direction

if ($moving)
  #if moving check a sensor on port Adc0
  $a0=getadc(adc0)
  
  #set a delay because we will keep pulling the adc
  $delay = true
  
  if ($a0>128)
    Say("sensor threshold reached, stopping the robot")
    Stop()

    if ($prevDirection="Forward")
      #shall we try going reverse ?
    elseif ($prevDirection="Reverse")
      #shall we try going forward ?
    endif 

  endif
endif     

if ($delay)
  #add a delay to avoid communication saturation
  Sleep(250)
endif 

$prevMoving = $moving

Goto(loop)

#10  

Hello PTP,

I was looking at this post as I am interested in doing similar things. Just want to clarify what is going on in the following statement line:

if($prevMoving!=$moving AND $moving)

Are we saying here that if the previousMoving state is not equal to moving (false) AND the variable $moving is now equal to true then we are moving?

Also when doing comparisons like if($direction="Stop") shouldn't this statement read: if($direction=="Stop")?

Just curious about these two issues and thanks as always for your clarification and help !Rick :):)

#11  

PTP, I see I have a lot to learn... despite some decades in programming PICs.

Please, to help, write a few lines, doing simply this:

read adc0, sayezb "up" if >128, or "down" if <128, and do this for ever.

I'd expect a up/down message from ezb whenever the voltage crosses the treshold.

This way I could hopefully understand how to work with EZB.

#12  

I'm going on testing some code , regarding getadc(adc0). I used the control called "read adc", to check the wiring , and I was surprised seeing that there I read , for adc0 , always 1,05 V, (value=82) whatever voltage I input to adc0 (0-to 3.3 V), even with the pin non connected . I have a meter connected to the pin. Same thing happens for other adc pins.

This explains some unexpected behavior of my code.

Can somebody explain why "read adc" doesn't work ? What's going on ?

#13  

Hi,ptp. Never mind about my previous posts. I solved my banal problem myself : some missing parenthesis, and wrong pin for adc. (a0 exchanged with a7 , I thought a0 on the same side as d0, I didn't look at the datasheet). Sorry, I'm a newcomer in EZB.

PRO
USA
#14  

@Rick,

EZ-Script is neither a BASIC or C compliant language, so there are some curiosities:

  1. Equal Operator ( = ) like Basic, C uses ( == )

  2. Not Equal operator ( != ) like C, Basic uses ( <> )

  3. Label is ( :my_label ) , C / BASIC is ( my_label: )

  4. ElseIf, BASIC does not have, C is (else if)

  5. if ( condition ), BASIC does not need braces, C requires braces

making short = is the equal operator

to avoid mistakes you need to rely on the ARC EZ-Script helps or look for examples in the forums.

#15  

Thanks PTP,

Was I correct in my thoughts on the moving statement in my post above? Thanks again ! Rick:)

#16  

Hi, DJ Sures. I wrote some simple code. But often I had unpredictable results, i.e. statements not executed, or executed more than once, or with unpredictable timing, etc. I never worked in a multi tasking environment, and don't understand how to manage many statements working together (as you say, " threaded"). Nothing about this in any tutorials. Can you help? Where to learn such things? Otherwise I'll have to go back to my beloved PICs, where everything is reliable, exactly timed, extremely fast, and no Os to interfere with my code.