friction.cpp 6.5 KB

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