Asked — Edited

Need A Ez Script Hint

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


ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

Canada
#1  

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

So, without my posting any code:P 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:)

Canada
#2  

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.

#3  

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

#4  

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

#5  

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

#6  

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

#7  

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.

Canada
#8  

Glad to hear it worked!

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


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

I have found that every time you put a sub-grouped qualifier or math - Sorry I don't know the correct terms:P - 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:P. 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.