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

Discover the limitless potential of robot programming with Synthiam ARC Pro – where innovation and creativity meet seamlessly.

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.

#9  

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 ARC. 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

#10  

OK Putt Putt, I think I may have showed my newness to this again. I think what you were trying to show me was how to structure a script with functions and statements that Gunner was showing. This way the script will work the way I want my robot to act? Not a different language. Duhh.

Anyway Gunner's statement worked nicely and seems like a more of an elegant way to do it. Now I've got my movement scripts down to one. I just have to change the one variable (i.e. $stop) to get it to stop anywhere! Thanks!

Now I need to study and structure my script in a way like Putt Putt suggests. I hadn't really considered yet how I'd activate the script. Depending on how that will be done (ie. voice, personality of just at startup) I may have to have other call scripts (I think).

Anyway, things are progressing nicely. I'm learning slowly. Thanks for the help.

Dave Schulpius

#11  

Hey Dave, no worries with anything..

One thing ( like you picked up on ) is that no that is not any code that you would use it is just a " Sudo Code " meaning that it is sort of how you would go about it but with all proper syntax for whatever variant of code a person would use.

Don't worry about your newness as you put it, you may not be able to write code yet but you can sure build one hell of a fantastic robot that probably most on here are drooling over every time they see it!

As for me I can glean information from everyone that contributes ( good or bad ) and then apply it to a bot but like you I need that push ( and sometime a swift kick ).

I look at some of my bots and think to myself " did i build that? " , I that that comes with age or lost brain cells but o-well.

Hey I just have fun and hope you do too.

Putt Putt Dave

#12  

Hi Dave,

Thanks for the very kind words. It's good to know there are people out there like you willing to lend a hand to help a guy out bring his hard work and dreams to life. Yes, this is more fun then I've had in a long time and although it's frustrating at times I love the challange.

Thanks to you and Gunner I was able to figure out how to get my rotation working nicely and to also understand what I was doing. I now have just one script that will send the waist rotation to any point I need around the radius. All I have to do is have what ever activates the script send the Specified Variable of the point I want to stop at and the script name it's self (to start the script). I'll be able to set whole routines if and when needed.

So this may be my last entry to this thread discussing how to get it to work.

Many thanks again to both you and Gunner.

Dave Schulpius