
leonardo46
Italy
Asked
— Edited

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.
Rick,
yes
problem solving is not straightforward, a problem can be solved in multiple ways it's important to explain the logic used.
the $direction variable is created and affected by the Movement Control, the control will assign the following values (case sensitive): "Stop", "Forward", "Reverse", "Left", "Right"
$moving and $prevMoving are user(our) script variables
assuming the movement control is in "charge" of the motors, we will use the $direction to detect if the robot is moving, so moving will be true if $direction has a value different from "Stop".
example #1 we have WaitForChange($direction), the script will hold there and wait for a change in variable $direction.
(that is the reason why i didn't add the sleep, unless you are generating multiple direction actions in milliseconds you don't a sleep).
we know the code after of WaitForChange only will run when the $direction changes.
this:
will run multiple times inside the loop while the robot is moving ($moving)
but i wanted to detect the transition between not moving and moving. So the idea is to add another variable $prevMoving (prev = previous) and you keep the value from the previous loop execution.
To achieve that you affect the variable only in the end of the loop, and you need to affect the variable before the loop.
if ($moving!=$prevMoving) means something changed, the robot stopped or robot started moving.
Adding this to the previous condition
this:
we can achieve the objective.
7) Scripts Start & Stop are independent, it's not like a monolithic program where everything starts at same time, so the question is should we initialize $prevMoving with true or false ?
makes sense to initialize $prevMoving with the same logic like $moving, so $prevMoving will be true if $direction is different than "Stop".
That will work. So if you start our user script, and then you press Forward, Stop, Reverse, everything works.
If you stop your user script, and you start again, you will notice that the last Movement is reverse, so the robot is moving and your script didn't detect the initial moving.
Maybe is important, maybe not so to detect always the initial move even when the script starts while the robot is moving, I changed the $prevMoving logic (before the loop) to be the opposite of $moving.
Sorry if everything was obvious, but i deal with multiple programmers, and not all the time is obvious each one logic.
Hello PTP,
Thanks for the detailed and fast and quick clarification to my question ! Very awesome ! Rick
Leonardo,
ARC, EZ-Script are high level tools, they allow people to focus on the fun part when building robots without spending time in low level details.
if you are used to low level tools like assembler, C, micro-controllers, it's much more easier for you to get a long with ARC than the opposite.
Can you provide some examples of what is not working or you don't know how to use ?
PTP, I'm aware of what you say. I'm used with assembler, but for robots there are no strict speed requirements, I use a compiled basic. When I knew EZB, I realized at once its huge power, and I am trying to migrate to it. It's a basic-like language, things should be the same, I thought. But the code written does not execute as I expected. Some statements are not executed. Some work in a random way. DJ Sures says " statements are executed in a multitasking way ("threaded")". I do not understad how to write a program where statements are executed this way. I'm asking him for some explanation. I attach an example for you to see what I'm doing. Thanks for your answer.
Leonardo,
Your code has a few errors, statement errors and flow structure errors.
if you pay attention to the debug console you will see the complains.
I can try help cleaning or organizing your logic, some questions:
what kind of sensors are adc0 and adc1 ?
what kind of values (range) are expected for far or close proximity ?
How you want to drive the robot based in the adc readings ?
I 'm replying only now. we have many hours of difference. Here it was night.
This code is intended to migrate to ezb the basic code that is working well in a simple rover I had made. Certainly the migration is wrong ! I haven't yet learned how to use EZB. There are 3 MaxSonar EZ3-MB1030 proximity sensors. (one in front , one left, one right). I'm using their analog output. The code is started by a Forward command from a Hbridge PWM movement panel. It should work as follows: The front sensor should check the distance. If it's more than a theshold of about 10 inches, motors should keep going forward,saying the wall is "far". Else it should say "near" and go to see at what side it has more space, and command motors to turn to that direction. The scripts for right and left simply say " turning right" or left, and do nothing else. After turning the rover goes forward again until it arrives near another wall, and everything goes on as before.
Extremely simple, it worked well with a basic program in a PIC. Thanks for your help.
I had forgotten to say that flags $FL and $FL1 are used to avoid instability that may sometimes occur and can cause endless oscillations between right and left. it's like a "Schmitt trigger" circuit, you know. The attached flowchart describes this better than words.
e.g. if it's turning left, it will go on turning left until it has enough space at the front sensor to be able to go straight. It will not attempt to go right and cause oscillations.