Spin Grammar
jaeg
Posts: 156
I'm working on a biped as I stated in my last topic (sorry for starting a new one, I go to a lot of forums where they jump on you for asking different questions in the same thread). I originally was using an Arduino and I designed a class to contain each joint in the robot so I can easily retrieve and set angles amongst various other things. Now to do this in Spin I'm assuming I would design the object the same way the Servo driver is designed (like any other program). So this is my question: Is it gramatically correct for me to do this?
LHip : "Joint.spin"
LKnee : "Joint.spin"
LAnkle : "Joint.spin"
RHip : "Joint.spin"
RKnee : "Joint.spin"
LAnkle : "Joint.spin"
Joint.spin will have functions for setting the pin number the joint is operating on, getting angles, converting angles into frequencies, etc etc.
Right direction?
LHip : "Joint.spin"
LKnee : "Joint.spin"
LAnkle : "Joint.spin"
RHip : "Joint.spin"
RKnee : "Joint.spin"
LAnkle : "Joint.spin"
Joint.spin will have functions for setting the pin number the joint is operating on, getting angles, converting angles into frequencies, etc etc.
Right direction?
Comments
Part of my goal was to use it as a data bag so I could have in contain angle, max, min, and other data along with several new functions. I'm use to programming in C++ if that explains my intentions at all haha
That's a ruff version of it so far. I'm implementing an angle system so I can just set the limb to say 0 degrees or 90 degrees instead. I'm not use to programming with cogs so does the joint having a servo object cause it to use up too many cogs when used like this?
This is the approach I took with my hexapod project. I have arrays to hold the various servo parameters.
Here are some byte sized arrays.
Those are actually just a few of the many parameters. I think you could guess the constant "_LegsInUse" has a value of six and "_ServosInUse" is set to 18.
Early in my program I assign the servo IDs to each joint.
This lets me use methods that have either servo indexes or leg indexes as parameters depending on which index makes more sense logically to use.
I've been holding off studying Paul's code to see how much I could figure out myself but I bet (based on his results) there is a lot one could learn about controlling servos by reading Paul's code.
There's nothing wrong with your original proposal. It just creates separate instances of the same object whose VAR variables can contain the state of each one. Another way to do the same thing is:
Then you can access the various instances by joint[LHip].method, joint[RHip].method, etc.
-Phil
EDIT
By the way in case anyone wants it here is how I convert degrees to frequencies:
There are limitations though. No angles with decimal values. Also this is assuming a 500 to 2500 range. It is really easy to figure a new constant though: (center frequency - min frequency) / 90. If you want to change the min angle change 500 in the equation.
I figured out how to do this today after a little number crunching and hadn't seen anything about it on Google so I figured I'd share.
-Phil
You can jump into the Alpha test now. And if you're a Windows user then Jazzed (Steve) has created a beautiful little IDE that installs the works and has you up and running in about a minute (Linux and Mac ports are in the works).
-- http://forums.parallax.com/showthread.php?138404-SimpleIDE-Version-0-5-0-Available
Funny, I think C is "funky" and have no trouble with Spin and PASM, but I am using Prop-GCC to learn C now so that my (EFX-TEK) customers can have more programming language choices with our Propeller-powered boards.