Friday, May 18, 2012

Mech: Legs designed in 3D

I had to work a few more bugs out of the location computing and rendering systems. I think the image is still flipped but I'll deal with that later.

For now, I have the legs and hip sections modeled. Not just their current location, but even their kinematics are modeled in this rendering system: If I adjust the actuators the entire structure will move and react. And all in about 70 lines of code, including constants and comments.

#Leg attributes

actThighInit = 1.0

actCalfInit = 1.0

actHipDis = 1.0

actThighDis = 1.0

actKneeDis = 1.0

actCalfDis = 1.0

thighLen = 5.0

calfLen = 5.0

legBoneDis = 2.0

hipWidth = 8.0

#DISPLAY PROPS

leftLegDispProp = displayProperties([100,100,255],2)

rightLegDispProp = leftLegDispProp

actDispProp = displayProperties([255,255,100],4)

hipDispProp = displayProperties([255,100,100],2)

leftHipBack = location(0,0,0)

leftHipActuator = location(actHipDis,0,0)

self.struct = structureSeed(leftHipBack,leftHipActuator)

s = self.struct

#LEFT LEG

leftThighActuator = s.addJoint(leftHipBack,actThighDis,leftHipActuator,actThighInit,location(0,1,0),'f',dispPropA=leftLegDispProp,dispPropB=actDispProp)

leftKneeBack = s.addJoint(leftHipBack,thighLen,leftThighActuator,dispPropA=leftLegDispProp)

leftHipFront = s.addJoint(leftHipActuator,legBoneDis+actHipDis,leftHipBack,dispPropA=leftLegDispProp)

leftKneeFront = s.addJoint(leftHipFront,thighLen,leftKneeBack,legBoneDis,leftHipBack,'f',dispProp=leftLegDispProp)

leftKneeBrace = s.addJoint(leftKneeBack,math.sqrt(1.0+legBoneDis*legBoneDis),leftKneeFront,1.0,leftHipBack,'n',dispProp=leftLegDispProp)

leftKneeActuator = s.addJoint(leftKneeBrace,math.sqrt(1.0+actKneeDis*actKneeDis),leftKneeFront,actKneeDis,leftKneeBack,'f',dispProp=leftLegDispProp)

leftCalfActuator = s.addJoint(leftKneeActuator,actCalfInit,leftKneeFront,actCalfDis,leftKneeBrace,'f',dispPropA=actDispProp,dispPropB=leftLegDispProp)

leftAnkleFront = s.addJoint(leftKneeFront,calfLen,leftCalfActuator,dispProp=leftLegDispProp)

leftAnkleBack = s.addJoint(leftAnkleFront,legBoneDis,leftKneeBack,calfLen,leftKneeActuator,'f',dispProp=leftLegDispProp)

#HIP

legHipSupportLen = 1.0

legHipWingLen = 0.5

hipPostLowerPoint = 0.1

hipPostUpperPoint = 1.0

hipCockpitDis = 1.0

cockpitWidth = 6.0

actHipInit = sqrt(sq(hipCockpitDis)+sq(actHipDis))

# Main leg supports

leftHipSupportBack = s.addJoint(leftHipBack,legHipSupportLen,leftHipActuator, sqrt( sq(legHipSupportLen) + sq(actHipDis)),leftThighActuator, sqrt(sq(actThighDis)+sq(legHipSupportLen)),dispProp=leftLegDispProp)

leftSupportAttachFront = s.addJoint(leftHipFront,actThighDis,leftKneeFront,dispProp=leftLegDispProp)

leftHipSupportFront = s.addJoint(leftHipFront,legHipSupportLen,leftHipBack, sqrt(sq(legBoneDis)+sq(legHipSupportLen)),leftSupportAttachFront, sqrt(sq(actThighDis)+sq(legHipSupportLen)),dispProp=leftLegDispProp)

# Hip post

leftHipWingBack = s.addJoint(leftThighActuator,sqrt(sq(actThighDis)+sq(legHipWingLen)),leftHipBack,legHipWingLen,leftHipFront,sqrt(sq(legBoneDis)+sq(legHipWingLen)),dispProp=leftLegDispProp)

leftHipPostUpper = s.addJoint(leftHipBack,hipPostUpperPoint,leftHipFront,sqrt(sq(legBoneDis)+sq(hipPostUpperPoint)),leftHipWingBack,sqrt(sq(legHipWingLen)+sq(hipPostUpperPoint)),dispProp=leftLegDispProp)

leftHipActuatorPost = s.addJoint(leftHipBack,sqrt(sq(hipPostUpperPoint)+sq(actHipDis)),leftHipActuator,hipPostUpperPoint,leftHipPostUpper,actHipDis,dispProp=leftLegDispProp)

# Hip center

leftHipCockpitUpper = s.addJoint(leftHipPostUpper,hipCockpitDis,leftHipActuatorPost,actHipInit,leftHipBack,sqrt(sq(hipCockpitDis)+sq(hipPostUpperPoint)),dispPropA=actDispProp,dispPropB=hipDispProp,dispPropC=hipDispProp)

leftHipCockpitLower = s.addJoint(leftHipCockpitUpper,hipPostUpperPoint,leftHipBack,hipCockpitDis,leftHipPostUpper,sqrt(sq(hipCockpitDis)+sq(hipPostUpperPoint)),dispProp=hipDispProp)

rightHipCockpitUpper = s.addJoint(leftHipPostUpper,cockpitWidth+hipCockpitDis,leftHipCockpitUpper,dispProp=hipDispProp)

rightHipCockpitLower = s.addJoint(leftHipBack,cockpitWidth+hipCockpitDis, leftHipCockpitLower,dispProp=hipDispProp)

rightHipPostUpper = s.addJoint(rightHipCockpitUpper,hipCockpitDis,rightHipCockpitLower,sqrt(sq(hipCockpitDis)+sq(hipPostUpperPoint)),leftHipCockpitLower,'f',dispProp=hipDispProp)

rightHipBack = s.addJoint(rightHipCockpitLower,hipCockpitDis,rightHipCockpitUpper,sqrt(sq(hipCockpitDis)+sq(hipPostUpperPoint)),leftHipCockpitUpper,'f',dispProp=hipDispProp)

# Hip post

rightHipActuatorPost = s.addJoint(rightHipBack,sqrt(sq(actHipDis)+sq(hipPostUpperPoint)),rightHipPostUpper,actHipDis,rightHipCockpitUpper,actHipInit,dispPropA=rightLegDispProp,dispPropB=rightLegDispProp,dispPropC=actDispProp)

rightHipActuator = s.addJoint(rightHipActuatorPost,hipPostUpperPoint,rightHipBack,actHipDis,rightHipPostUpper,sqrt(sq(hipPostUpperPoint)+sq(actHipDis)),dispProp=rightLegDispProp)

#RIGHT LEG

rightHipWingBack = s.addJoint(rightHipPostUpper,sqrt(sq(hipPostUpperPoint)+sq(legHipWingLen)),rightHipActuator,sqrt(sq(legHipWingLen)+sq(actHipDis)),rightHipBack,legHipWingLen,dispProp=rightLegDispProp)

rightThighActuator = s.addJoint(rightHipActuator,actThighInit,rightHipBack,actThighDis,rightHipWingBack,sqrt(sq(legHipWingLen)+sq(actThighDis)),dispPropB=rightLegDispProp,dispPropA=actDispProp,dispPropC=rightLegDispProp)

rightKneeBack = s.addJoint(rightHipBack,thighLen,rightThighActuator,dispPropA=rightLegDispProp)

rightHipFront = s.addJoint(rightHipActuator,legBoneDis+actHipDis,rightHipBack,dispPropA=rightLegDispProp)

rightKneeFront = s.addJoint(rightHipFront,thighLen,rightKneeBack,legBoneDis,rightHipBack,'f',dispProp=rightLegDispProp)

rightKneeBrace = s.addJoint(rightKneeBack,math.sqrt(1.0+legBoneDis*legBoneDis),rightKneeFront,1.0,rightHipBack,'n',dispProp=rightLegDispProp)

rightKneeActuator = s.addJoint(rightKneeBrace,math.sqrt(1.0+actKneeDis*actKneeDis),rightKneeFront,actKneeDis,rightKneeBack,'f',dispProp=rightLegDispProp)

rightCalfActuator = s.addJoint(rightKneeActuator,actCalfInit,rightKneeFront,actCalfDis,rightKneeBrace,'f',dispPropA=actDispProp,dispPropB=rightLegDispProp)

rightAnkleFront = s.addJoint(rightKneeFront,calfLen,rightCalfActuator,dispProp=rightLegDispProp)

rightAnkleBack = s.addJoint(rightAnkleFront,legBoneDis,rightKneeBack,calfLen,rightKneeActuator,'f',dispProp=rightLegDispProp)

rightSupportAttachFront = s.addJoint(rightHipFront,actThighDis,rightKneeFront,dispProp=rightLegDispProp)

rightHipSupportFront = s.addJoint(rightHipBack,sqrt(sq(legBoneDis)+sq(legHipSupportLen)),rightHipFront,legHipSupportLen,rightSupportAttachFront,sqrt(sq(actThighDis)+sq(legHipSupportLen)),dispProp=rightLegDispProp)

rightHipSupportBack = s.addJoint(rightHipActuator,sqrt(sq(actHipDis)+sq(legHipSupportLen)),rightHipBack,legHipSupportLen,rightThighActuator,sqrt(sq(actThighDis)+sq(legHipSupportLen)),dispProp=rightLegDispProp)

Friday, May 11, 2012

Mech: The 3D rendering and image export works

I've got the new 3-d rendering system online, rendering, and exporting images. The image shown here was built using the code below

The first three lines of this code are the basic bootstrapping. We put two locations in space. We build out structure seed from that. I then define a display property to be able to highlight one of the spans. Then, the first two 'add joint' commands are using the 2D building ability. When building an object from only two points, I have to make up a third one in order to define what plane the new point should be in. I also need to say 'far' or 'near' relative to the made-up point that defines the plane since there are usually two possible solution points. The last 'add joint' is a regular 3D joint, made from three of the other joints.

You might notice that we constructed this pyramid without all of the pieces. In designing machines, this will actually be a valuable feature since it prevents you from making machines that *can* bind. This way, you must make models that are minimally determined and thus maximally able to move when their joints move.

nearL = location(0,0,0)

nearR = location(1,0,0)

s = structureSeed(nearL,nearR)

highlightDisProp = displayProperties([100,100,255],7)

farL = s.addJoint(nearL,1,nearR,math.sqrt(2),location(0,0,1),'f')

farR = s.addJoint(nearL,math.sqrt(2),nearR,1,location(0,0,1),'f')

top = s.addJoint(nearL,1,nearR,1,farL,1,dispPropA=highlightDisProp)

Lastly, I've uploaded the code for this. It requires both pygame and imagemagick (just to apt-get installs on them). Run the command 'python main.py' to make it do it's thing.

https://docs.google.com/open?id=0B1S9HNoTaV32Y20wRjVhNzBfd0U

Monday, May 7, 2012

Mech: Building the 3D simulator

I needed a 3D simulator. There are lots of programs that let you draw objects and place them. I didn't see offhand any that have the simulator compute the locations of things based on their distances from other things. And it would have taken me a while to find the right one with the right APIs so I just didn't.

Instead I'm making a 3D simulator. Like the 2D version I already made it computes locations based on relative distances from other locations. I've added compatibility with 2D as well as lines for convenience.

Today, I got it computing locations even for the complex 3D cases. The interesting part of this was doing a bunch of rotations until the points were in a plane where I could compute the solutions to them.

I solve the problem in two major parts. Each part is essentially solving for the intersection of two points. So let's say I have joints A,B,C and distance dA,dB,dC from the new joint D that we're going to place. I start with joint A and joint B. I solve for where D is relative to them. But in a 3D world that's actually a circle. Based on the location of C and dC I can find a specific point on the circle D. Below are the exact steps:

  • STEP 0: Copy initial points so they never drift with repeated transformations
  • STEP 1: Translate to make point 1 the origin
  • STEP 2: Rotate around Y axis till point 2 lies in Z=0 plane
  • STEP 3: Rotate around Z axis till point 2 lies in Y=0 plane (now must be on the X-axis)
  • STEP 4: Solve for point 4(new point)'s to find the X and Y. The X here will end up being the real X in this space. The Y is simply the radius.
  • STEP 5: The problem now starts over, remaking a new point A and B based on the X,Y we solved and point 3
  • STEP 6: Translate to make point newA's X=0
  • STEP 7: Rotate around Y axis 90 degrees to make the solution circle lie at Z=0
  • STEP 8: Rotate around Z axis till point newB lies on the Y=0 plane (it now must be on the X-axis)
  • STEP 9: Solve for point 4(new point)'s to find the new X and Y locations. The transformations we've already done will fill out all the other data found along the way.
  • STEP 10: Build the solution
  • STEP 11: Back out all transformations

If you spend a few minutes thinking about this, you'll notice that the points and distances is not enough to determine an exact point. It determines one of two points. As with the 2D system, I'm solving this by using the right hand rule. If you list the points clockwise from your perspective, whatever perspective you choose, the plane those points in will be between you and the new point. Take a sec to think about it.

To give an example test case I run:

#Test case: 3D joint

j = joint()

j.jointA = location(1.0,0,0)

j.jointB = location(0.0,1.0,0.0)

j.jointC = location(0.0,0.0,1.0)

j.spanA = span(1.0)

j.spanB = span(math.sqrt(1+1+1))

j.spanC = span(1.0)

j.computeLocation()

if(j.x > 1.01 or j.x < 0.99 or j.y > 0.01 or j.y < -0.01 or j.z > 1.01 or j.z < 0.99):

\t p = False

\t print "ERROR on test case 8: %s"%j.toString()

I've decided to call the new rendering and computing engine MindFuck3D. From this post, I hope you can begin to see why. Once I try to actually design in this new language I think it will really win it's name. It will be difficult to get good at but very quick and powerful once I have it down.

Wednesday, April 25, 2012

Mech: Visualizing a simple walk sequence

I've added color and sequencing to the simulator. I've also added a cockpit (red) and an engine (grey) to the mech to show better what it will look like.

The simulator is good enough to be able to simulate many possible walk sequences. I wrote a function that tries many many actuator combinations to come up with a walk sequence that fits a few basic criteria:

  • Starts with both feet on the ground
  • Does not drop the cockpit height below 8'
  • Maximize stride (I've not yet modified it to maximize efficiency)

I then fed the computer-chosen result through a function to show the sequence and spit out some diagnostics about the walking movement:

  • Stride length: 6.7'
  • Actuator displacement through a single step: 1.4'
  • Efficiency (stride/displacement): 4.79

I noticed in the course of doing this that the certain actuator positions increased efficiency. However, I suspect they also rely on greater actuator strength. Right now I'm counting all actuator displacement to be made equal. In reality, the difficult of moving the actuator isn't just in the distance it travels but also the force on it. To compute this function automatically I'll have to add a ton of statics equations to the simulator.

Notice that in addition to the simple walking sequence I've added the crouch distance. For this configuration it stands with a hip height of 8.7' and a minimum crouch distance of 4'.

Wednesday, April 18, 2012

More mech simulator

Added some more functionality to the simulator. In particular colors. We can see now the two legs and the actuators that control them. We can also execute commands to lengthen or reduce the length of those actuators. I'll be adding stats and auto-calculation of the structure next. This one will be particularly interesting. I've not yet decided if I'm going to calculate it or have the machine find it by trial and error. After that probably a third dimension.

Monday, April 16, 2012

The beginnings of the mech simulator


I decided I needed some computer aided design, beyond the excel spreadsheet I was using. I need a mech simulator. The mech simulator has several goals:

  • V1: Show the mech based on the dimensions and actuator positions

  • V2: Indicate bob-height when walking

  • V2: Indicate stride when walking

  • V2: Indicate max/min height

  • V2: Indicate foot colissions when running walking sequence

  • V3: Export information to open-scad for 3-d rendering and model printing

  • VNext: Load calculations

  • VNext: Inertia calculations



After a bit of playing around I found the best way was just to specify new joints and place them at distances from previous joints. I wanted to make something easier/cheaper and more specific to this project but there was no value in not making it general. This joint-adding approach makes it easy to write out the dimensions of whatever you're making. It works for single-leg-bone designs. It works for parallel-leg-bone designs like what I will probably use.

I still have to work out the dimensions myself, but once I have a sequence of commands and information about walking I'll be able to play with that much more dynamically.

Eventually the V2-VNext features will allow me to expand and finalize my designs while still being able to react to fuck-ups I make.

Wednesday, April 11, 2012

So I've decided to build a mech and I want your help


There's a lot of work to do.
1. Statics analysis on how a two-bone leg is different from a one bone leg. I can eliminate an actuator by doing design A and don't think it changes the force equations much but I don't know. At some point I'll do the statics equations but anyone can do that right now. (see diagram)
2. Research availability and prices on hydraulic cylinders/actuators that have built-in encoders. As in a measure of how far the cylinder has extended. All the exterior encoders I've seen will mountings, calibration, etc. It must be something with a price, at least a quote if not an add-to-cart style for purchasing. There's a lot of industrial parts makers that do not actually handle distribution and we need a distributor.
3. Other large-scale walking robots. Especially bipedal. I haven't seen any that actually walk. If there's not a video of it moving it's a BS project. Best I've seen is a 6-legged logging robot that's build not to damage foliage as it moves through the forest.

Pick one. Tell me what you find out.