Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
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.

#36  
Fast job ! I didn't know ezb was capable to support copy/paste !...

Code tested. It does no more than stop at once after the forward command. I eliminated the stop() command at the beginning.
After that it goes forward, until the front sensor gets near an obstacle and then it stops, after several seconds (a long time!...). The voltage in READ ADC control panel, instead, changes immediately.
Other sensors seem to have no influence in what's going on. No change in direction triggered by left/right sensors.

I saw in the code there is some average of adc reads. Could this help ?
What had this code to do? Why side sensors not working?
I have in ezb screen a voltage panel for each sensor, correctly measuring each distance in real time.
#37  
I forgot to say that ezb never says "near" or "far".
It only says "stop", because I have sayezb ("STOP") in stop script.
PRO
USA
#38  
Leonardo,

Can you upload/attach your project ?
#39  
More tests.
I eliminated the 2nd stop() statement, (it stopped there !). now it reacts to the side sensors, turning right or left as required.
But it keeps turning for ever, even when the loop is executed again with the front sensor without obstacles ("far" situation).
It never says near or far. Only says what's in right,left,or stop scripts.

But the worrying issue is : response time is extremely long !
Note that the 3 READ ADC control panels for sensors change in realtime.
EZBv4 , instead, reacts after some 2-3 seconds !...
I DON'T UNDERSTAND WHY IT'S SO SLOW.
This way is useless for controlling a robot !
#41  
PTP, thanks for the answer. I don't want to hijack this thread so no need to respond to my posts on my script questions anymore. However just to answer you; I'm still just a student of easy script and have no advance. I'm just asking questions to learn. I'm amazed at the different ways we can write script and have it do the same thing. For example I thought you could only have one If statements in a block and everything else needed to compare to it. Then each If block needed it's own EndIf statement. I didn't know you could stack them up at the bottom like you do. I write my scripts much like you've second example to my. That's more readable to me. Lol

Anyway, ignore me now. Sounds like the op is getting close to resolution. I wish him luck. ;)
#42  
Leonardo, click the pause box on the adc monitors. This is probably what is slowing down your setup. That feature is very resource hungry. I can't run more than one at a time without seeing my system slow to a crawl. See if this helps.
#44  
OK PTP. Now it works. I'll study your code to learn what you have done.

But the problem now is : WHY it's so slow ? it takes at least 3 seconds to actually change the direction.
Within that time the robot will crash against the wall !
The same robot , with a PIC, reacted in milliseconds.
PRO
USA
#45  
@leonardo,

Please try:
test_r1.EZB

Changes:
1) vocal messages removed from the main script
2) Decreased the delay to 50

*** #1 edit:begin ***
3)
Dave suggestion, is very relevant.

I paused all the analog controls, they have short (<1000ms) refresh intervals .

Our focus is to troubleshoot the navigation script. You can try later activate one by one to see if they affect the performance

*** #1 edit:end ***


4) Important:

as it is, is using a single read on adc0 to use average readings you will need change the code to:

Code:


#set true to use average readings
$use_average=true


Please let me know if the results are better.


PS: Congratulations Soccer Euro 2016 - Italy is moving forward !
Conte did a fantastic job beating Spain is not easy!
#46  
As far as being slow, did you see my post above. Give that a try to see if it helps.
#48  
PTP. This version doesn't connect to ezb#0. . timed out.
I don't understand what's going on.
It connects to other ezbs, #1,2,etcthat I don't have.
No test possible.

Thanks for our soccer team. They were really convinced to win.
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:

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.

Code:


#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:

Code:


#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 !.....