2013-08-12

First ODE based IK screenshot

I finally managed to coax ODE into accepting my IK rig. It was not easy, I can tel you that. The ODE documentation is a nightmare. I still haven't figured out why some of my code does not work. But I decided to leave it be and focus on what's more important. I have built the rig without actuators. It runs in a simulator that draws out a simple representation of the world in OpenGL. I also have a Qt5 form where I can add some widgets to control the simulation as I go along. In the screen-shot, the robot is actually in free fall, because it becomes really unpleasant to look at after it lands.

Devol Robot Simulator first screenshot
And here is the code that actually assembles the robot:

void LimbRigController::buildRig(){
    Vector center(-2,0,5);
    int NUM_LEGS=6;
    Vector axisBase(1,0,0);
    float thighToShinRatio=0.75;
    float legLength=1.0;
    float innerRad=0.5;
    float kneeRad=innerRad+(legLength*thighToShinRatio)/(legLength*thighToShinRatio+legLength/thighToShinRatio);
    float toeRad=kneeRad+(legLength/thighToShinRatio)/(legLength*thighToShinRatio+legLength/thighToShinRatio);
    float kneeHeight=0.0;
    float stepAng=(360)/NUM_LEGS;
    float ang=0;
    float legRadius=0.1;
    float baseRadius=2;
    DynamicObject *base=new DynamicObject(world,space,center,center +Vector(0,0.01,innerRad/baseRadius),Vector(0,0,1),baseRadius,0x008888ff,DynamicObject::CYL);
    //base->join(0,center,Vector(0,0,1));
    dobs.push_back(base);
    for(int i=0;i pelvis(0,innerRad,0);
        pelvis.rotate(ang,0,0,1);
        pelvis+=center;
        Vector knee(0,kneeRad,kneeHeight);
        knee.rotate(ang,0,0,1);
        knee+=center;
        Vector toe(0,toeRad,0);
        toe.rotate(ang,0,0,1);
        toe+=center;
        Vectoraxis=axisBase;
        axis.rotate(ang,0,0,1);
        DynamicObject *thig=new DynamicObject(world,space,pelvis,knee,axis,legRadius,0x00ff8888,DynamicObject::CYL);
        DynamicObject *shin=new DynamicObject(world,space,knee,toe,axis,legRadius,0x0088ff88,DynamicObject::CYL);
        base->join(thig,pelvis,axis,-M_PI*0.5,M_PI*0.5);
        shin->join(thig,knee,axis,-M_PI*0.5,0);
        dobs.push_back(thig);
        dobs.push_back(shin);
        ang+=stepAng;
    }
}

No comments:

Post a Comment