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

Experience the transformation – subscribe to Synthiam ARC Pro and watch your robot evolve into a marvel of innovation and intelligence.

PRO
USA
#49  

Leonardo,

My ezb has a different address, when you save a project the ip address goes in.

You see a textbox before the connect button, you will need to change the ip address from 192.168.18.84 (mine) to 192.168.1.1 (yours).

Then save the project.

#50  

OK, PTP, much better. Reaction time decreased from 3 sec to 1 sec. Good. It's almost ok. I'll experiment for even better performance.

Another issue for this robot was some code to avoid endless oscillations between right and left occurring in some circumstances. It's necessary, when ,for example, turning right, to disable any attempt to turn left until the front sensor has a free space before it. Turning left should be enabled only after the rover has started to go straight. Same thing should happen for turning left. To do this there were two flags FL and FL1, as you see in the attached flowchart. Can you implement this function in your code ? This would be enough for this thread.

User-inserted image

#51  

translation from italian: iniz=initialization libero av=free space before me av =go straight ostac dx=osbtacle at right ostac sx=obstacle at left dx=right sx=left ost= a label

FL and FL1 = Flags

PRO
USA
#52  

Leonardo,

My logic is already doing that, look the code:


if ($adc0_avg>50) 
  #1

  if ($direction!="Forward")
    #2  
    Forward() 
  endif

else
  #3

  if ($direction="Forward")
    #4 
    Stop()
    
    if (GetADC(ADC1)>GetADC(ADC2))
      #5
      Left()
    else
      #6
      Right()
    endif 
    
  endif 
endif

I put some comments #1-#6

The current logic is:

  1. when the robot detects an obstacle will enter #3
  2. if robot is driving forward not spinning will enter #4, stop, starts spinning left or right based on adc1 or adc2 values

robot keeps spinning same direction (no oscillation) until the forward sensor is ok, once is ok will enter #1 and drives forward.

PRO
USA
#53  

Leonardo,

I added some logic to avoid oscillation going left, forward, right, forward, left.


#stop the robot if is moving
Stop()

#set true to use average readings
$use_average=false

$spin_counter=0

#-1=left; 0-fw; 1=right
$spin_direction=0

if ($use_average)
  DefineArray($adc0_reads, 10, 0)
  repeat($adc0_ix, 0, 9, 1)
    $adc0_reads[$adc0_ix]=GetADC(adc0)
    Sleep(50)
  endrepeat 
endif

:loop


if ($use_average)
  $adc0_ix++
  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
else
  #read one 
  $adc0_avg=GetADC(adc0)
endif

if ($adc0_avg>50) 
  if ($direction!="Forward")
    Forward() 
  endif
else
  if ($direction="Forward")
    Stop()
    
    #adjust the value 20 to your needs
    if ($spin_direction!=0 AND $spin_counter<20)
      if ($spin_direction<0)
        Left()
      else
        Right()
      endif
    else
      $spin_counter=0
      if (GetADC(ADC1)>GetADC(ADC2))
        $spin_direction=-1
        Left()
      else
        $spin_direction=1
        Right()
      endif 
    endif
  else
    $spin_counter++
  endif 
endif

Sleep(50)
Goto(loop)

you will need to tweak the value 20 based on your observations, can be higher or low.

relevant lines:


    #adjust the value 20 to your needs
    if ($spin_direction!=0 AND $spin_counter<20)

#54  

very well,PTP, it's running. I will have only to fine tune some parameter to have a performance approaching the very fast one of pic.

Thank you for having shown me what ezb can do. i'll study your code. Programming that way is different from basic or assembly on pics I was used to. I'll try to get the relevant know-how.

One last detail. I'd like to avoid those annoying windows coming out when you start ezb i.e. mounting instructions, fine tune profile, tutorials for robots I will never have,etc. I have to skip or close them every time.

After this thread I will experiment with servos, actions and frames, and will certainly ask for support in other threads.

I'll be reading you there.

#55  

Hi ptp. You're the member who solved ! Now I understand how to use adc reading. To have fast results it's better to use a hardware comparator on board . It can make such operations in 100 nS !.....