Shop OBEX P1 Docs P2 Docs Learn Events
inverse kinematics — Parallax Forums

inverse kinematics

BritannicusBritannicus Posts: 98
edited 2012-02-20 10:33 in Robotics
Well, I'm just about to bolt the legs on my bigger hexapod this Friday - key milestone as I get all 12 Sevos in place. I'll be posting some pics soon. Ultimately I hope to go to independant 3DOF legs and 18 servos, but one thing at a time !

I have a Prop based servo controller with which I plan to wiggle them in the appropriate order to do the usual hexapod dance we all love to see on youtube.

I'd simply thought to define a series of constants for each servo (forward/ back/centre up/down/centre for a 2DOF leg) then to string each step command with 12 out of the 36 options. This seems to fit with how the PROP servo controller likes things, if I understand it right. I found this quite easy for the 3Servo hexapod I posted a bit back.

BUT !....

I hear discussions from time to time about Inverse Kinematics. I think I understand the concept ("I want to move the leg to position A - go calculate the angles of the servos") . What I'm uncertain of is how (or if) the IK approach is really implemented with kit like the STAMP - is there anywhere I can get my hands on some "IK for Dummies" type stuff? I'm figuring this might take me into the realm of something more complex than SPIN - so I might get scared at this point - but hey ! nothing ventured nothing gained they say

Maybe some of you good chaps out there have code you could share either for STAMP (which I use now) or Props with SPIN, (which I intend to dabble with once I get my head above the inbox).

Comments

  • LeonLeon Posts: 7,620
    edited 2011-06-08 09:08
    Scilab has a Robotics Toolbox that includes inverse kinematics:

    http://rtss.sourceforge.net/docs/index.
  • Martin_HMartin_H Posts: 4,051
    edited 2011-06-08 09:46
    Inverse kinematics are a coordinate transform from a rotational coordinate system to a Cartesian one. As a result there's a whole lot of trigonometry and signed arithmetic involved. I've found them to be fairly easy to do in Spin and here's a Spin example of inverse kinematics for my robot arm:

    Arm.spin

    I probably have a newer version of that code now. It's possible to do trigonometric transforms in PBasic, but the lack of properly signed arithmetic will drive you nuts. If you want to use a stamp consider getting the floating point co-processor Parallax sells as there are inverse kinematic samples for it.

    Inverse kinematics are nearly an absolute requirement for an arm, but a leg might be able to get away with a hard coded motion script. Basically the leg has a lift up motion, and a push down and back motion.
  • ercoerco Posts: 20,255
    edited 2011-06-08 21:34
    IF YOU CAN'T DO IT WITH A STAMP, YOU SHOULDN'T BE DOING IT! :)

    Love,

    Cranky old man erco
  • BritannicusBritannicus Posts: 98
    edited 2011-06-09 01:31
    Cheers Chaps ! - something to think about there -

    Martin I'll have a quick squint at your code - really appreciate your sharing.I've no experience of Spin, but it doesn't look so scary.

    Leon - I'm getting the dreaded 404 when I try your link, but I can already see that I'm going to have to brush up my triganometry - last time I used it in anger was 25 years ago as a student doing mapping. I think for the moment I'll stick with a fairly "stompy" up/down/ centre approach with thecurrent bot before I try doing anything more fancy. When I get to mor DOF on each leg they start behaving more like an arm (but six of them !), so I'm seriously going to have to look at and understand this to move on.

    Erco - I appreciate your zeal for the stamp, but I still prefer a glass for my beer ! :smile::smile::smile:
  • LeonLeon Posts: 7,620
    edited 2011-06-09 01:45
    It was OK yesterday, but there now seems to be a problem with it. Try this link:

    http://rtss.sourceforge.net/
  • Martin_HMartin_H Posts: 4,051
    edited 2011-06-10 05:58
    Erco, come over to the Dark Side, as PJ Allen says, we have cookies.
  • HumanoidoHumanoido Posts: 5,770
    edited 2011-06-10 10:05
    Martin_H wrote: »
    Erco, come over to the Dark Side, as PJ Allen says, we have cookies.
    Erco, don't listen to Martin! Next thing you know, PJ IS YOUR FATHER and when you reach for the cookies you lose a hand!

    :)
  • ercoerco Posts: 20,255
    edited 2011-06-10 10:12
    @H: PJ and I certainly share similar fiesty viewpoints, but I'm not so sure about calling him Dad. Chronologically, that's a time paradox. :)
  • ercoerco Posts: 20,255
    edited 2011-06-10 11:21
    It's not quite inverse kinematics, but I like the idea of puppeteering a robot arm or robot leg: you pose it in position and it records that frame. Simple with pricey digital servos, but who wants to pay for those? And besides, that's cheatin'...!

    I think it was Beau who posted an incredibly ingenious scheme for reading an analog servo's position using lower voltage and a frequency sweep. I can never find that post when I need it. PLEASE MAKE THAT POST A STICKY AT THE TOP OF THIS FORUM. It should be required reading for any would-be roboteer!

    Once you record a few critical frames of robot arm/leg positions, you could connect them all with IK.

    And a STAMP!

    Edit: Found it at http://forums.parallax.com/showthread.php?84991-Propeller-Application-Proportional-feedback-from-a-Standard-Hobby-Servo-(Upda&highlight=read+analog+servo
  • HumanoidoHumanoido Posts: 5,770
    edited 2011-06-15 00:01
    erco wrote: »
    @H: PJ and I certainly share similar fiesty viewpoints, but I'm not so sure about calling him Dad. Chronologically, that's a time paradox. :)
    You're right - well, time travel IS a reality and you have heard about the TWIN PARADOX. (relax, I am not calling your twins a paradox even if you think so!)

    :)
  • BritannicusBritannicus Posts: 98
    edited 2011-06-16 05:50
    Leon wrote: »
    It was OK yesterday, but there now seems to be a problem with it. Try this link:

    http://rtss.sourceforge.net/

    Cheers LEon - seems to work, just ned some time to look at this and understand it !
  • ercoerco Posts: 20,255
    edited 2012-01-27 18:54
    @Martin_H: You're a staunch supporter of IK. Silly question 4U. Seems like it might be possible with pricey digital servos with 1024 resolution, feedback etc. (like Duane's schmancy Dynamixel units, each with its own onboard processor). But analog servos (especially the $2 cheapies I like) aren't particularly linear over their range of travel. Wouldn't you have to individually map out each servo's pulsout input to output shaft angle to use IK? Then support that with a processor with trig functions & floating point math?

    It's likely I'll stick with brute force canned scripts, simple processors & cheap servos in the near future, but I want to make sure I'm not missing out on anything juicy.
  • Martin_HMartin_H Posts: 4,051
    edited 2012-01-27 19:31
    You are correct that the nonlinear response of servos complicates things a bit. But I found that measuring three pulse widths for three joint angles (+Pi/2, 0, -Pi/2) and linear interpolation gave me linear enough response over the full range. So I measured those values for each joint and created a translation function for each joint to compute the pulse width for a desired angle. I suspect more data points will result in better behavior, but I can always add more.

    The reason I like inverse kinematics is that they let you work in Cartesian coordinates which are easier to programmatically generate. So my tower of Hanoi can support any number of disks (when I solve the gripper problem). I think you could also add a g code front end. At that point use CAM software to generate gripper paths, but I am still learning about this.

    I can see the appeal of motion scripts because you trade away complexity, but generation of the scripts seems like a fair amount of work too.
  • ercoerco Posts: 20,255
    edited 2012-01-27 19:46
    Martin_H wrote: »
    I can see the appeal of motion scripts because you trade away complexity, but generation of the scripts seems like a fair amount of work too.

    Far more importantly, Inverse Kinematics is just a cooler buzzword. :)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-01 11:42
    erco wrote: »
    Then support that with a processor with trig functions & floating point math?

    Sorry, I haven't been following this thread lately. (I think this is my first post to it.)

    Yesterday, I was trying to figure out how many floating point trig calculations I could do within the 20ms refresh period of servos. (I want to add a pendulum type motion to my servo demo.) It turns out there's enough time to do several FP trig calculations on 32 servos within 20ms. Lonesock has really sped up the Propeller's ability to do floating point calculations with his object F32.

    So if you're only using the 18 servos most hexapods use, there should be plenty of time to compute inverse kinematics with a Prop.

    I haven't looked at Martin's code yet, but some sort of inverse kinematic pseudo sinudoidal beast is in my future. I didn't buy all those servos to leave them taped to a board.
  • GeorgeCollinsGeorgeCollins Posts: 132
    edited 2012-02-01 17:44
    Duane Degn wrote: »
    Sorry, I haven't been following this thread lately. (I think this is my first post to it.)

    Yesterday, I was trying to figure out how many floating point trig calculations I could do within the 20ms refresh period of servos. (I want to add a pendulum type motion to my servo demo.) It turns out there's enough time to do several FP trig calculations on 32 servos within 20ms. Lonesock has really sped up the Propeller's ability to do floating point calculations with his object F32.

    So if you're only using the 18 servos most hexapods use, there should be plenty of time to compute inverse kinematics with a Prop.

    I haven't looked at Martin's code yet, but some sort of inverse kinematic pseudo sinudoidal beast is in my future. I didn't buy all those servos to leave them taped to a board.

    I would like to comment on this because I have made a bunch of walking robots with propellers and I have experimented with IK code, interpolating from a table of positions, and a technique called central pattern generation. By the way, they all work. IK is probably the most versatile. But when you get to twelve or more servos the calculations are not that fast and the code and variables really eat up space on the chip. You need the FP library, a lot of code to do IK, and a bunch of memory to store the position and orientation of each joint.

    The other part of the problem is, once you have an IK system what are you going to do with it? If you are going to cycle six legs through the same relative positions as you walk you are going to be doing the same complicated calculations over and over again. You might as well store the results in a table. You will save on memory and free up the processor to calculate. IK is potentially really useful if you are integrating the position of the legs and body with sensors like an accelerometer and touch sensors to alter your stance dynamically. That's more complicated then writing code to get three joint positions from three coordinates. I can't say for sure, but I think that is getting beyond the processing power of a prop chip. I think it would make more sense if you were using the prop for IO and doing your dynamic position calculations on a small ARM board.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-20 07:48
    I would like to comment on this because I have made a bunch of walking robots with propellers and I have experimented with IK code, interpolating from a table of positions, and a technique called central pattern generation. By the way, they all work. IK is probably the most versatile. But when you get to twelve or more servos the calculations are not that fast and the code and variables really eat up space on the chip. You need the FP library, a lot of code to do IK, and a bunch of memory to store the position and orientation of each joint.

    The other part of the problem is, once you have an IK system what are you going to do with it? If you are going to cycle six legs through the same relative positions as you walk you are going to be doing the same complicated calculations over and over again. You might as well store the results in a table. You will save on memory and free up the processor to calculate. IK is potentially really useful if you are integrating the position of the legs and body with sensors like an accelerometer and touch sensors to alter your stance dynamically. That's more complicated then writing code to get three joint positions from three coordinates. I can't say for sure, but I think that is getting beyond the processing power of a prop chip. I think it would make more sense if you were using the prop for IO and doing your dynamic position calculations on a small ARM board.

    George,

    Thanks for your comments. I've been hesitant to reply since I have very little experience with trying to build a walking robot When you made your post I hadn't any experience.

    I've been working on a hexapod over the last few weeks. As I've tried writing code for the bot I realized three legs are making very similar movements with each step so instead of having to compute the servo position for all 18 servos, one only needs to compute the positions for 6 of them (and 6 mirror positions which are simple to calculate).

    With my attempt at IK, these 6 servo calculations take about 7ms including all the overhead to make updates to the servo object. I personally think all 18 servo positions could probably be calculated within the 20ms servo refresh period. I'm not very confident I'm using the optimal calculations for IK. There may be some tricks I don't know to simplify the calculations. I wanted to try writing my own IK algorithms so I haven't looked much to see if there are faster ways of computing the needed angles.

    I'm relatively sure the calculations could be sped up by not using floating point calculations for the legs return movement through the air. When the feet of the robot are on the ground, I want the feet to move in a straight line and at a constant speed with respect to the robot. These movements require the computation intense floating point calculations. However, the position and speed of the feet as they move through the air is not very important so these positions could be calculated with normal integer math. My current program uses the same computation intense IK algorithms for the return movement as it does for movement of the feet on the ground. Using integer math for the return movement is a way to cut the needed floating point calculations in half. So the current 7ms computation time should be able to be significantly reduced.

    I wonder if you have used the souped up version of the floating point object? Lonesock's F32 (the souped up version I just mentioned) runs in a single cog (it used to take two cogs for the full floating point library). Not only does F32 only use one cog but Lonesock has also optimized many of the algorithms so it runs much faster than the original floating point library.

    So far, my program uses three of the eight cogs. The main program uses one cog. F32 requires a single cog as does the servo object, bringing the total to three cogs. (I frequently use a couple of extra cogs while debugging.) My confidence in thinking the Propeller can handle all the IK calculations needed for most walking robots has been steadily increasing. I'd think the remaining five cogs would be enough to handle monitoring many of the common robot sensors and controlling many additional devices that are common in a hobby robot.

    I'll agree there are plenty of tasks that are beyond the abilities of the Propeller (such some machine vision tasks) but I'm now pretty confident that IK is a task the Propeller can handle.

    I built my robot out of popsicle sticks and small cheap servos. I'm afraid it's woefully too weak for its long legs. It might be able to walk tethered to a power supply, but my first attempts at having it carry NiMH batteries as a power supply have been failures. Hopefully I'll post pictures and video of my first attempt at a walking robot later today. While the robot has yet to walk, I'm relatively confident I have the IK calculations working. The legs look like they are making the correct movements through space.
  • ercoerco Posts: 20,255
    edited 2012-02-20 08:38
    I wanna see that, Duane! ASAP!

    Pretty heady math you're getting into there, Pal. Sounds like you're on the right track. When I see a hexapod or other walker, I watch how the feet contact the ground while walking. The good ones plant their feet and they stay in one place as the leg pivots around them. When they skid around (sideways or forward/back), there is clearly some more work to do...

    Lots of tethered walkers out there, don't be shy. Servos need lots of current and batteries are heavy. Big stresses and deflections when servos support lots of weight and lightweight flexible legs are put to the task. The robot arm I built showed me that just moving itself around (no payload) is not a trivial task.

    So don't wait until it's perfect. Start a thread and share what you've done so far!

    Now you got me wanting to get on my Altoids quadropod...
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-20 10:33
    erco wrote: »
    So don't wait until it's perfect. Start a thread and share what you've done so far!

    Roger that.
Sign In or Register to comment.