1 月 09
This page was maily translated from http://demura.net/archives/9ode by Babel Fish Translation.
It continues to the last time, utilizes the dJointFeedback structure. This time the joint (the joint) the sample cord/code which acquires the power which catches is introduced.
When this is applied, you attach to the sole of a humanoid robot, you can simulate the pressure sensor which is utilized in the measurement of ZMP.
It continues to the last time, utilizes the dJointFeedback structure. This time the joint (the joint) the sample cord/code which acquires the power which catches is introduced.
When this is applied, you attach to the sole of a humanoid robot, you can simulate the pressure sensor which is utilized in the measurement of ZMP.
- void dJointSetFeedback (dJointID and dJointFeedback *); The dJointFeedback structure is set to the joint JointID which acquires the information of power and torque. typedef struct dJointFeedback { dVector3 f1; // The power which the joint has caused to body 1 dVector3 t1; // The torque which the joint has caused to body 1 dVector3 f2; // The power which the joint has caused to body 2 dVector3 t2; // The torque which the joint has caused to body 2 } dJointFeedback;
- dJointFeedback *dJointGetFeedback (dJointID); Information of power and torque of the joint which it is designated with dJointID is acquired.
CODE:
- // sensor.cpp by Kosei Demura 2006-7-26
- #include
- #include
- static dWorldID world;
- static dSpaceID space;
- static dGeomID ground;
- static dJointID fixed;
- static dJointGroupID contactgroup;
- dJointFeedback *feedback = new dJointFeedback;
- dsFunctions fn;
- typedef struct {
- dBodyID body;
- dGeomID geom;
- dReal radius,length,width,height,mass;
- } myLink;
- myLink box,sensor;
- static void nearCallback (void *data, dGeomID o1, dGeomID o2)
- {
- static int MAX_CONTACTS = 10;
- int i;
- // do not collide if two bodies are conneted by a joint
- dBodyID b1 = dGeomGetBody(o1);
- dBodyID b2 = dGeomGetBody(o2);
- if (b1 && b2 && dAreConnected (b1,b2)) return;
- dContact contact[MAX_CONTACTS]; //
- int numc = dCollide(o1,o2,MAX_CONTACTS,&contact[0].geom,
- sizeof(dContact));
- if (numc> 0) {
- for (i=0; i
- contact[i].surface.mode = dContactSoftCFM | dContactSoftERP;
- contact[i].surface.mu = dInfinity; //
- contact[i].surface.soft_cfm = 1e-8;
- contact[i].surface.soft_erp = 1.0;
- dJointID c = dJointCreateContact(world,contactgroup,&contact[i]);
- dJointAttach (c,dGeomGetBody(contact[i].geom.g1),
- dGeomGetBody(contact[i].geom.g2));
- }
- }
- }
- static void simLoop (int pause)
- {
- static int steps = 0;
- dSpaceCollide(space,0,&nearCallback);
- dWorldStep(world,0.01);
- dJointGroupEmpty(contactgroup);
- feedback = dJointGetFeedback(fixed); // get force and torque information
- printf("%5d Force fx=%6.2f ",steps++,feedback->f1[0]); // x coordinate
- printf("fy=%6.2f ",feedback->f1[1]); // y coordinate
- printf("fz=%6.2f \n",feedback->f1[2]); // z coordinate
- // draw a box
- dsSetColor(1.0,0.0,0.0);
- dReal sides1[] = {box.length,box.width,box.height};
- dsDrawBoxD(dBodyGetPosition(box.body),
- dBodyGetRotation(box.body),sides1);
- // draw a sensor
- dsSetColor(0.0,0.0,1.0);
- dReal sides2[] = {sensor.length,sensor.width,sensor.height};
- dsDrawBoxD(dBodyGetPosition(sensor.body),
- dBodyGetRotation(sensor.body),sides2);
- }
- void start()
- {
- static float xyz[3] = {0.0,-3.0,1.0};
- static float hpr[3] = {90.0,0.0,0.0};
- dsSetViewpoint (xyz,hpr);
- }
- void setDrawStuff() {
- fn.version = DS_VERSION;
- fn.start = &start;
- fn.step = &simLoop;
- fn.command = NULL;
- fn.stop = NULL;
- fn.path_to_textures = "../../drawstuff/textures";
- }
- int main (int argc, char **argv)
- {
- setDrawStuff();
- world = dWorldCreate();
- space = dHashSpaceCreate(0);
- contactgroup = dJointGroupCreate(0);
- dWorldSetGravity(world,0,0,-9.8);
- ground = dCreatePlane(space,0,0,1,0);
- dMass m1;
- dReal x0 = 0.0, y0 = 0.0, z0 = 0.0;
- // a sensor (blue box)
- sensor.length = 0.2; sensor.width = 0.2;
- sensor.height = 0.2; sensor.mass = 1.0;
- sensor.body = dBodyCreate(world);
- dMassSetZero(&m1);
- dMassSetBoxTotal(&m1,sensor.mass,sensor.length,sensor.width,sensor.height);
- dBodySetMass(sensor.body,&m1);
- dBodySetPosition(sensor.body, x0, y0, 0.5 * sensor.height + z0);
- sensor.geom = dCreateBox(space,sensor.length,sensor.width,sensor.height);
- dGeomSetBody(sensor.geom,sensor.body);
- // a box (red box)
- box.length = 0.2; box.width = 0.2;
- box.height = 0.2; box.mass = 1.0;
- box.body = dBodyCreate(world);
- dMassSetZero(&m1);
- dMassSetBoxTotal(&m1,box.mass,box.length,box.width,box.height);
- dBodySetMass(box.body,&m1);
- dBodySetPosition(box.body, x0, y0, sensor.height + 0.5 * box.height + z0);
- box.geom = dCreateBox(space,box.length,box.width,box.height);
- dGeomSetBody(box.geom,box.body);
- // a fixed joint
- fixed = dJointCreateFixed(world,0);
- dJointAttach(fixed,box.body,sensor.body);
- dJointSetFixed(fixed);
- // Set a joint to retrieve force and torque information
- dJointSetFeedback(fixed,feedback);
- dsSimulationLoop(argc,argv,352,288,&fn);
- dWorldDestroy(world);
- return 0;
- }
投稿:07年01月09日

