Need A Ez Script Hint

 
#1

Hi all,

I'm having a centering issue. I'm trying to have the waist of my B9 robot turn left, right and then go to center. Right now I have 3 scripts, one for each movement (left, right and center). My goal it to have one script that will let my waist move back and forth past center and then return to center.

The motor is a DC motor controlled with an H-Bridge and the position feedback is a multi-turn Pot. The Pot is attached to an ADC port to get Current feedback.

Each script is working but when I run the centering script the motor rocks back and forth past center till it finds the exact value. I'm using the = Condition in an "if" statement. Here's a section from my script:

#####################
:Start

1.$adcCurrent = GetADC(adc1)

if ($adcCurrent $adcSpecified)
goto(RotateRight)

if ($adcCurrent = $adcSpecified)
goto(RotateStop)

goto(Start)
###################

Here's the goto(RotateStop) section:

##################
:RotateStop
1.Set(d5, off)
1.Set(d4, off)
Halt()
##################

It seems like the = Condition is too tight of a tolerance for the pot feedback. Watching the Variable Watch panel the $adcCurrent value will rise past the $adcSpecified value and then the motor will reverse back to get back to the Specified value. Depending how fast the motor is going sometimes the motor will switch directions continuously trying to find center.

My Question; I there a way to state a way I can stop the motor between two value Current values and not a = value?This may give me more tolerance and the motor wont react to try to bring itself back to "Exact" center. Or.... is there a different way to write this scriptto keep the motor from rocking back and forth to find center?

Of course you can tell I'm new to any kind of script writing. Thanks for any help.

Dave Schulpius

#2

I have noticed that when posting code snippits lately there seems to be the odd line or symbol missing Smile Makes it harder to show an example without actually posting the .EZB

So, without my posting any code Tongue Try using the GreaterThan and LessThan parameters instead of Equals. Then set a range of values that match the center area (i.e. center is 50 then use 45 and 55) and have your your IfThen statement activate the :RotateStop when your Current is GreaterThan 45 or LessThan 55 (depending on direction). By the time the motor stops it should be close to center... if it still overshoots then increase the range. You could then follow up in a second or so with what you have for a slower true center move.

Hope this makes sense Smile

#3

Also, if I recall your B9 will have 360 deg rotation at the waist. Once you have the moment scripts down, you can have "center" and multiple "quadrant" or "octant" points so the same movements scripts can have him turning and stopping at designated points all the way around.

#4

I truly appreciate your help. As I said I'm new to scripting of any kind so I need to reread your suggestions and give them some thought. They sound like wise suggestions but I need to "digest" them a little till I understand better.

Actually Gunner, B9 could have 360 deg rotation but I have limit switches installed near the rear of the radius so he can only turn about 300 deg. They already have helped me avoid certain disaster.

Thanks again and I hope I can ask for more help on this later.

Dave Schulpius

#5

oops. Stupid mistake on this post attempt. Please skip.

#6

After working on this problem all last night I finally have things working ( Kind of). I couldn't get the motor to move back to center useing the > or and < In the same script depending on the direction.
Now I need to have a separate script for each point I want to stop at and then use the centering scripts to bring it home. I can then write another script useing the ControlCommand Entries for different routines. This seems like a lot of scripts. There must be a better way. Can I do the same thing with less scripts or better writing?
Thanks, Dave Schulpius

#7

OK, just checking in.

I'm making progress. I actually got a single script to work for centering without the rocking issue. I went back and tried gunner's suggestion again. Must have mistyped something or gave up too soon in frustration last night. Now it works perfectly! Here's what I came up with. Consider my mid value is 125:

If ($adcCurrent >120 and $adcCurrent <130)
goto(RotateStop)

I think I'm getting the hang of this a little. Now that I have the movement scripts working I need to figure out how to get them to stop at "center", multiple "quadrant" and "octant" points in a routine
like Gunner suggested. I still don't know how to do this without having one EZ Script for each stopping point as a call script with ControlCommand Entries for different rotation patterns.

The GetRandom and GetRandomUnique functions sound interesting here. However again I have no idea how to apply a randomly attained number to a stopping point on my waist rotation.
Thanks for listening to my ramblings.

Dave Schulpius

#8

Hi,

I'm not sure what event you are using to turn the body but lets say your using sound to determine a direction...

use IF statements for the event and then GOTO a routine to turn the body..

EI:

Sudo code:

:main

If sound is on the left then
left
If sound is on the right then
right

goto main

:left
turn body to POT reading ###

goto main

:right
turn body to POT reading ###

goto main

you could add in any number of positions you like by just naming them different like ....left1 , left2, ....
right1, right2....or center


put them all in 1 big script then call that script from say the personality script or wherever.

#9

Glad to hear it worked!

Use a variable (i.e. $stop) instead of numbers for your stopping point, then modify your script like this

Code:


If (($adcCurrent >($stop - 5) and $adcCurrent <($stop + 5)))
goto(RotateStop)



This way you can adjust the value of $stop and B9 will stop wherever you want Smile

I have found that every time you put a sub-grouped qualifier or math - Sorry I don't know the correct terms Tongue - in a script like I just did, you need to group them in () and add the same to the beginning and end of the whole "equation"... I cannot remember the exact rule of placement, so I just experiment until it works Tongue. But I have noticed that missing one or more brackets may NOT give an "syntax" error when saving, but when running your code it will just stop at the line with the "error"... and easy enough to find when using debug.

#10

Thanks for the help and suggestions Gunner and Putt Putt. As I said before; I need all I can get sometimes. I'd be dead in the water without it. A little push in the right direction is all I need sometimes.

These suggestions are just what I'm looking for and what I need to make B9 do what I want him to do. The waist rotation animation is going to be one of the most important movement processes so as to make him appear like the real thing. This process will also be used in his radar/bubble section above his collar. If you remember from the TV show Lost in Space, at times his waist would move one way and his radar/bubble section move the other and then go back the other way to catch up with the waist. Anyway, both sections had the same movement patterns but were very independent of each other.

Just a couple questions;

Gunner, if I follow you, the value of $stop needs to be stated somewhere at the start if the script? I'm thinking this should be my center value? So, if my center value is 125 the script may look like this?:
#############################
:Start

1.$adcCurrent = GetADC(adc1)
$stop= 125

If (($adcCurrent >($stop - 5) and $adcCurrent <($stop + 5)))
goto(RotateStop)

goto(Start)

:RotateStop
1.Set(d5, off)
1.Set(d4, off)
Halt()
############################

Putt Putt,
Pardon my ignorance but I see your suggestion looks totally different then Gunner's. Is it in a different language? I have read that EZ-B can understand different languages like C#, VB and C++. Is this what is happening here? I suspect this because I cant find a lot of these functions or qualifiers (? - I'm still learning the terminology) on the sidebar function list in an EZ Script window. Can I place these different languages in an EZ Script and get them to work? I see there is a C# Script choice in the Add Control tool in EZ Builder. Do I need to use this instead?

Also I've noticed when people post scripts sometimes it's inserted in a Yellow window like I see in Gunner's post above. Where does that come from? Looks like it's added from outside somehow or cut and pasted from a different program.

Thanks again for all the help,
Dave Schulpius