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

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

#25  

I think I corrected the flow errors. Here is the new version. It's not yet working. I don't know which are the statement errors. Something case sensitive ?

User-inserted image

#26  

I've found that EZ Script is not case sensitive.

Also, line 26 & 27 look odd to me. I'm not sure you should have a label inside an '"If" statement.

PRO
USA
#27  

Leonardo,

Quick feedback.

Dave is right, that is one of the "flow structure errors" if, elseif, else blocks work as logical block.

I understand why you made the mistake, assembly language don't have restrictions to jump to an address.

PRO
USA
#28  

Leonardo,

Can you try this script:


#stop the robot if is moving
Stop()

:loop

if (GetADC(adc0)>50) 
  if ($direction!="Forward")
    SayEZB("Far") 
    Forward() 
  endif
else
  if ($direction="Forward")
    SayEZB("Near") 
    Stop()
    
    #check rotation side 
    if (GetADC(ADC1)>GetADC(ADC2))
      Left()
    else
      Right()
    endif 
    
  endif 
endif

Sleep(250)
Goto(loop)

I didn't tested, i just followed your specs. Let me know if it works.

sometimes reading multiple ultrasonic sensors can create interference, but it depends how you setup them (angles).

#29  

No,ptp, it doesn't work. It starts and stops randomly the motors in the forward direction, sensors seem not influncing what's going on.To make it do something you have to click more than once the forward button in the movement panel. No interference among sensors. The same robot with a PIC it worked well.

PRO
USA
#30  

Leonardo,

Can you try this variant:


#stop the robot if is moving
Stop()

DefineArray($adc0_reads, 10, 0)
repeat($adc0_ix, 0, 9, 1)
  $adc0_reads[$adc0_ix]=GetADC(adc0)
  Sleep(100)
endrepeat 

:loop

#read one 
$adc0_ix=$adc0_ix+1
if ($adc0_ix>=10)
  $adc0_ix=0
endif 
$adc0_reads[$adc0_ix]=GetADC(adc0)

#calculate avg last 10 readings
$adc0_avg=0
repeat($x, 0, 9, 1)
  $adc0_avg=$adc0_avg+$adc0_reads[$x]
endrepeat 
$adc0_avg=$adc0_avg/10

if ($adc0_avg>50) 
  if ($direction!="Forward")
    SayEZB("Far") 
    Forward() 
  endif
else
  if ($direction="Forward")
    SayEZB("Near") 
    Stop()
    
    #check rotation side 
    if (GetADC(ADC1)>GetADC(ADC2))
      Left()
    else
      Right()
    endif 
    
  endif 
endif

Sleep(250)
Goto(loop)

PRO
USA
#31  

Leonardo,

Did you tried the script ?

#32  

I'm writing .It's a long job. By the way, is there some way to import your code to my ARC without writing it, i.e. such as a sort of executable file ?