1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/*************************************************************************
* *
* Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
* All rights reserved. Email: russ@q12.org Web: www.q12.org *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of EITHER: *
* (1) The GNU Lesser General Public License as published by the Free *
* Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. The text of the GNU Lesser *
* General Public License is included with this library in the *
* file LICENSE.TXT. *
* (2) The BSD-style license that is included with this library in *
* the file LICENSE-BSD.TXT. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
* LICENSE.TXT and LICENSE-BSD.TXT for more details. *
* *
*************************************************************************/
//234567890123456789012345678901234567890123456789012345678901234567890123456789
// 1 2 3 4 5 6 7
////////////////////////////////////////////////////////////////////////////////
// This file creates unit tests for some of the functions found in:
// ode/src/joint.cpp
//
//
////////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <UnitTest++.h>
#include <ode/ode.h>
#include "../ode/src/config.h"
#include "../ode/src/joints/joints.h"
/*
* Tests for contact friction
*/
SUITE(JointContact)
{
struct ContactSetup
{
dWorldID world;
dBodyID body1;
dBodyID body2;
dJointID joint;
ContactSetup()
{
world = dWorldCreate();
body1 = dBodyCreate(world);
body2 = dBodyCreate(world);
dBodySetPosition(body1, -1, 0, 0);
dBodySetPosition(body2, 1, 0, 0);
}
~ContactSetup()
{
dBodyDestroy(body1);
dBodyDestroy(body2);
dWorldDestroy(world);
}
};
TEST_FIXTURE(ContactSetup,
test_ZeroMu)
{
dxJoint::Info1 info1;
dReal dummy_J[3][16] = {{0}};
int dummy_findex[3];
dReal info2_fps = 100;
dReal info2_erp = 0;
dReal *J1 = dummy_J[0];
dReal *J2 = dummy_J[0] + 8;
dReal *rhscfm = dummy_J[0] + 6;
dReal *lohi = dummy_J[0] + 14;
unsigned rowskip = 16;
int *findex = dummy_findex;
#define ZERO_ALL do { \
memset(dummy_J, 0, sizeof dummy_J); \
std::fill(dummy_findex, dummy_findex+3, -1); \
} \
while (0)
dContact contact;
contact.surface.mode = dContactMu2 | dContactFDir1 | dContactApprox1;
contact.geom.pos[0] = 0;
contact.geom.pos[1] = 0;
contact.geom.pos[2] = 0;
// normal points into body1
contact.geom.normal[0] = -1;
contact.geom.normal[1] = 0;
contact.geom.normal[2] = 0;
contact.geom.depth = 0;
contact.geom.g1 = 0;
contact.geom.g2 = 0;
// we ask for fdir1 = +Y, so fdir2 = normal x fdir1 = -Z
contact.fdir1[0] = 0;
contact.fdir1[1] = 1;
contact.fdir1[2] = 0;
/*
* First, test with mu = 0, mu2 = 1
* Because there is no friction on the first direction (+Y) the body
* is allowed to translate in the Y axis and rotate around the Z axis.
*
* That is, the only constraint will be for the second dir (-Z):
* so J[1] = [ 0 0 -1 0 1 0 0 0 1 0 1 0 ]
*/
contact.surface.mu = 0;
contact.surface.mu2 = 1;
joint = dJointCreateContact(world, 0, &contact);
dJointAttach(joint, body1, body2);
joint->getInfo1(&info1);
CHECK_EQUAL(2, (int)info1.m);
ZERO_ALL;
joint->getInfo2(info2_fps, info2_erp, rowskip, J1, J2,
rowskip, rhscfm, lohi, findex);
CHECK_CLOSE(0, dummy_J[1][0], 1e-6);
CHECK_CLOSE(0, dummy_J[1][1], 1e-6);
CHECK_CLOSE(-1, dummy_J[1][2], 1e-6);
CHECK_CLOSE(0, dummy_J[1][3], 1e-6);
CHECK_CLOSE(1, dummy_J[1][4], 1e-6);
CHECK_CLOSE(0, dummy_J[1][5], 1e-6);
CHECK_CLOSE(0, dummy_J[1][8], 1e-6);
CHECK_CLOSE(0, dummy_J[1][9], 1e-6);
CHECK_CLOSE(1, dummy_J[1][10], 1e-6);
CHECK_CLOSE(0, dummy_J[1][11], 1e-6);
CHECK_CLOSE(1, dummy_J[1][12], 1e-6);
CHECK_CLOSE(0, dummy_J[1][13], 1e-6);
CHECK_EQUAL(0, dummy_findex[1]); // because of dContactApprox1
dJointDestroy(joint);
/*
* Now try with no friction in the second direction. The Jacobian should look like:
* J[1] = [ 0 1 0 0 0 1 0 -1 0 0 0 1 ]
*/
// try again, with zero mu2
contact.surface.mu = 1;
contact.surface.mu2 = 0;
joint = dJointCreateContact(world, 0, &contact);
dJointAttach(joint, body1, body2);
joint->getInfo1(&info1);
CHECK_EQUAL(2, (int)info1.m);
ZERO_ALL;
joint->getInfo2(info2_fps, info2_erp, rowskip, J1, J2,
rowskip, rhscfm, lohi, findex);
CHECK_CLOSE(0, dummy_J[1][0], 1e-6);
CHECK_CLOSE(1, dummy_J[1][1], 1e-6);
CHECK_CLOSE(0, dummy_J[1][2], 1e-6);
CHECK_CLOSE(0, dummy_J[1][3], 1e-6);
CHECK_CLOSE(0, dummy_J[1][4], 1e-6);
CHECK_CLOSE(1, dummy_J[1][5], 1e-6);
CHECK_CLOSE(0, dummy_J[1][8], 1e-6);
CHECK_CLOSE(-1, dummy_J[1][9], 1e-6);
CHECK_CLOSE(0, dummy_J[1][10], 1e-6);
CHECK_CLOSE(0, dummy_J[1][11], 1e-6);
CHECK_CLOSE(0, dummy_J[1][12], 1e-6);
CHECK_CLOSE(1, dummy_J[1][13], 1e-6);
CHECK_EQUAL(0, dummy_findex[1]); // because of dContactApprox1
dJointDestroy(joint);
}
}
|