joint.cpp 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047
  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 <UnitTest++.h>
  31. #include <ode/ode.h>
  32. #include "../ode/src/joints/joints.h"
  33. ////////////////////////////////////////////////////////////////////////////////
  34. // Testing the Hinge2 Joint
  35. //
  36. SUITE(JointHinge2)
  37. {
  38. struct Hinge2GetInfo1_Fixture_1
  39. {
  40. Hinge2GetInfo1_Fixture_1()
  41. {
  42. wId = dWorldCreate();
  43. bId1 = dBodyCreate(wId);
  44. dBodySetPosition(bId1, 0, -1, 0);
  45. bId2 = dBodyCreate(wId);
  46. dBodySetPosition(bId2, 0, 1, 0);
  47. jId = dJointCreateHinge2(wId, 0);
  48. joint = (dxJointHinge2*)jId;
  49. dJointAttach(jId, bId1, bId2);
  50. dJointSetHinge2Anchor (jId, REAL(0.0), REAL(0.0), REAL(0.0));
  51. }
  52. ~Hinge2GetInfo1_Fixture_1()
  53. {
  54. dWorldDestroy(wId);
  55. }
  56. dJointID jId;
  57. dxJointHinge2* joint;
  58. dWorldID wId;
  59. dBodyID bId1;
  60. dBodyID bId2;
  61. dxJoint::Info1 info;
  62. };
  63. TEST_FIXTURE(Hinge2GetInfo1_Fixture_1, test_hinge2GetInfo1)
  64. {
  65. // ^Y
  66. // |---| HiStop
  67. // | | ^Y /
  68. // |B_2| | /
  69. // |---| | /
  70. // | ----- | /
  71. // Z <-- * Z<--|B_2|--*
  72. // / | \ ----- | \
  73. // /|---|\ |---| \
  74. // / | | \ | | \
  75. // / |B_1| \ |B_1| \
  76. // / |---| \ |---| \
  77. //LoStop HiStop LoStop
  78. //
  79. //
  80. //
  81. //
  82. dMatrix3 R;
  83. dJointSetHinge2Param(jId, dParamLoStop, -M_PI/4.0);
  84. dJointSetHinge2Param(jId, dParamHiStop, M_PI/4.0);
  85. dxJoint::Info1 info;
  86. dxJointHinge2* joint = (dxJointHinge2*)jId;
  87. // Original position inside the limits
  88. joint->getInfo1(&info);
  89. CHECK_EQUAL(0, joint->limot1.limit);
  90. CHECK_EQUAL(4, info.m);
  91. // Move the body outside the Lo limits
  92. dBodySetPosition (bId2, 0, 0, 1);
  93. dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0);
  94. dBodySetRotation (bId2, R);
  95. joint->getInfo1(&info);
  96. CHECK_EQUAL(1, joint->limot1.limit);
  97. CHECK_EQUAL(5, info.m);
  98. // Return to original position
  99. // Keep the limits
  100. dBodySetPosition (bId2, 0, 1, 0);
  101. dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0));
  102. dBodySetRotation (bId2, R);
  103. joint->getInfo1(&info);
  104. CHECK_EQUAL(0, joint->limot1.limit);
  105. CHECK_EQUAL(4, info.m);
  106. // Move the body outside the Lo limits
  107. dBodySetPosition (bId2, 0, 0, 1);
  108. dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0);
  109. dBodySetRotation (bId2, R);
  110. joint->getInfo1(&info);
  111. CHECK_EQUAL(1, joint->limot1.limit);
  112. CHECK_EQUAL(5, info.m);
  113. // Return to original position
  114. // and remove the limits
  115. dBodySetPosition (bId2, 0, 1, 0);
  116. dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0));
  117. dBodySetRotation (bId2, R);
  118. dJointSetHinge2Param(jId, dParamLoStop, -2*M_PI);
  119. dJointSetHinge2Param(jId, dParamHiStop, 2*M_PI);
  120. joint->getInfo1(&info);
  121. CHECK_EQUAL(0, joint->limot1.limit);
  122. CHECK_EQUAL(4, info.m);
  123. // Set the limits
  124. // Move pass the Hi limits
  125. dJointSetHinge2Param(jId, dParamLoStop, -M_PI/4.0);
  126. dJointSetHinge2Param(jId, dParamHiStop, M_PI/4.0);
  127. dBodySetPosition (bId2, 0, 0, 1);
  128. dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0);
  129. dBodySetRotation (bId2, R);
  130. joint->getInfo1(&info);
  131. CHECK_EQUAL(2, joint->limot1.limit);
  132. CHECK_EQUAL(5, info.m);
  133. // Return to original position
  134. // Keep the limits
  135. dBodySetPosition (bId2, 0, 1, 0);
  136. dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0));
  137. dBodySetRotation (bId2, R);
  138. joint->getInfo1(&info);
  139. CHECK_EQUAL(0, joint->limot1.limit);
  140. CHECK_EQUAL(4, info.m);
  141. // Move the pass the Hi limit
  142. dBodySetPosition (bId2, 0, 0, 1);
  143. dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0);
  144. dBodySetRotation (bId2, R);
  145. joint->getInfo1(&info);
  146. CHECK_EQUAL(2, joint->limot1.limit);
  147. CHECK_EQUAL(5, info.m);
  148. // Return to original position
  149. // and remove the limits
  150. dBodySetPosition (bId2, 0, 1, 0);
  151. dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0);
  152. dBodySetRotation (bId2, R);
  153. dJointSetHinge2Param(jId, dParamLoStop, -2*M_PI);
  154. dJointSetHinge2Param(jId, dParamHiStop, 2*M_PI);
  155. joint->getInfo1(&info);
  156. CHECK_EQUAL(0, joint->limot1.limit);
  157. CHECK_EQUAL(4, info.m);
  158. /// Motorize the first joint angle
  159. dJointSetHinge2Param(jId, dParamFMax, 2);
  160. joint->getInfo1(&info);
  161. CHECK_EQUAL(0, joint->limot1.limit);
  162. CHECK_EQUAL(5, info.m);
  163. /// Motorize the second joint angle
  164. dJointSetHinge2Param(jId, dParamFMax2, 2);
  165. joint->getInfo1(&info);
  166. CHECK_EQUAL(0, joint->limot1.limit);
  167. CHECK_EQUAL(6, info.m);
  168. /// Unmotorize the first joint angle
  169. dJointSetHinge2Param(jId, dParamFMax, 0);
  170. joint->getInfo1(&info);
  171. CHECK_EQUAL(0, joint->limot1.limit);
  172. CHECK_EQUAL(5, info.m);
  173. }
  174. } // End of SUITE(JointHinge2)
  175. ////////////////////////////////////////////////////////////////////////////////
  176. // Testing the Universal Joint
  177. //
  178. SUITE(JointUniversal)
  179. {
  180. struct UniversalGetInfo1_Fixture_1
  181. {
  182. UniversalGetInfo1_Fixture_1()
  183. {
  184. wId = dWorldCreate();
  185. bId1 = dBodyCreate(wId);
  186. dBodySetPosition(bId1, 0, -1, 0);
  187. bId2 = dBodyCreate(wId);
  188. dBodySetPosition(bId2, 0, 1, 0);
  189. jId = dJointCreateUniversal(wId, 0);
  190. joint = (dxJointUniversal*)jId;
  191. dJointAttach(jId, bId1, bId2);
  192. dJointSetUniversalAnchor (jId, REAL(0.0), REAL(0.0), REAL(0.0));
  193. }
  194. ~UniversalGetInfo1_Fixture_1()
  195. {
  196. dWorldDestroy(wId);
  197. }
  198. dJointID jId;
  199. dxJointUniversal* joint;
  200. dWorldID wId;
  201. dBodyID bId1;
  202. dBodyID bId2;
  203. dxJoint::Info1 info;
  204. };
  205. TEST_FIXTURE(UniversalGetInfo1_Fixture_1, test_hinge2GetInfo1_RotAroundX)
  206. {
  207. // ^Y
  208. // |---| HiStop
  209. // | | ^Y /
  210. // |B_2| | /
  211. // |---| | /
  212. // | ----- | /
  213. // Z <-- * Z<--|B_2|--*
  214. // / | \ ----- | \
  215. // /|---|\ |---| \
  216. // / | | \ | | \
  217. // / |B_1| \ |B_1| \
  218. // / |---| \ |---| \
  219. //LoStop HiStop LoStop
  220. //
  221. //
  222. //
  223. //
  224. dMatrix3 R;
  225. dJointSetUniversalParam(jId, dParamLoStop, -M_PI/4.0);
  226. dJointSetUniversalParam(jId, dParamHiStop, M_PI/4.0);
  227. dJointSetUniversalParam(jId, dParamLoStop2, -M_PI/4.0);
  228. dJointSetUniversalParam(jId, dParamHiStop2, M_PI/4.0);
  229. dxJoint::Info1 info;
  230. dxJointUniversal* joint = (dxJointUniversal*)jId;
  231. // Original position inside the limits
  232. joint->getInfo1(&info);
  233. CHECK_EQUAL(0, joint->limot1.limit);
  234. CHECK_EQUAL(4, info.m);
  235. // Move the body outside the Lo limits
  236. dBodySetPosition (bId2, 0, 0, 1);
  237. dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0);
  238. dBodySetRotation (bId2, R);
  239. joint->getInfo1(&info);
  240. CHECK_EQUAL(1, joint->limot1.limit);
  241. CHECK_EQUAL(5, info.m);
  242. // Return to original position
  243. // Keep the limits
  244. dBodySetPosition (bId2, 0, 1, 0);
  245. dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0));
  246. dBodySetRotation (bId2, R);
  247. joint->getInfo1(&info);
  248. CHECK_EQUAL(0, joint->limot1.limit);
  249. CHECK_EQUAL(4, info.m);
  250. // Move the body outside the Lo limits
  251. dBodySetPosition (bId2, 0, 0, 1);
  252. dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0);
  253. dBodySetRotation (bId2, R);
  254. joint->getInfo1(&info);
  255. CHECK_EQUAL(1, joint->limot1.limit);
  256. CHECK_EQUAL(5, info.m);
  257. // Return to original position
  258. // and remove the limits
  259. dBodySetPosition (bId2, 0, 1, 0);
  260. dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0));
  261. dBodySetRotation (bId2, R);
  262. dJointSetUniversalParam(jId, dParamLoStop, -2*M_PI);
  263. dJointSetUniversalParam(jId, dParamHiStop, 2*M_PI);
  264. joint->getInfo1(&info);
  265. CHECK_EQUAL(0, joint->limot1.limit);
  266. CHECK_EQUAL(4, info.m);
  267. // Set the limits
  268. // Move pass the Hi limits
  269. dJointSetUniversalParam(jId, dParamLoStop, -M_PI/4.0);
  270. dJointSetUniversalParam(jId, dParamHiStop, M_PI/4.0);
  271. dBodySetPosition (bId2, 0, 0, 1);
  272. dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0);
  273. dBodySetRotation (bId2, R);
  274. joint->getInfo1(&info);
  275. CHECK_EQUAL(2, joint->limot1.limit);
  276. CHECK_EQUAL(5, info.m);
  277. // Return to original position
  278. // Keep the limits
  279. dBodySetPosition (bId2, 0, 1, 0);
  280. dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0));
  281. dBodySetRotation (bId2, R);
  282. joint->getInfo1(&info);
  283. CHECK_EQUAL(0, joint->limot1.limit);
  284. CHECK_EQUAL(4, info.m);
  285. // Move the pass the Hi limit
  286. dBodySetPosition (bId2, 0, 0, 1);
  287. dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0);
  288. dBodySetRotation (bId2, R);
  289. joint->getInfo1(&info);
  290. CHECK_EQUAL(2, joint->limot1.limit);
  291. CHECK_EQUAL(5, info.m);
  292. // Return to original position
  293. // and remove the limits
  294. dBodySetPosition (bId2, 0, 1, 0);
  295. dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0);
  296. dBodySetRotation (bId2, R);
  297. dJointSetUniversalParam(jId, dParamLoStop, -2*M_PI);
  298. dJointSetUniversalParam(jId, dParamHiStop, 2*M_PI);
  299. joint->getInfo1(&info);
  300. CHECK_EQUAL(0, joint->limot1.limit);
  301. CHECK_EQUAL(4, info.m);
  302. /// Motorize the first joint angle
  303. dJointSetUniversalParam(jId, dParamFMax, 2);
  304. joint->getInfo1(&info);
  305. CHECK_EQUAL(0, joint->limot1.limit);
  306. CHECK_EQUAL(5, info.m);
  307. /// Motorize the second joint angle
  308. dJointSetUniversalParam(jId, dParamFMax2, 2);
  309. joint->getInfo1(&info);
  310. CHECK_EQUAL(0, joint->limot1.limit);
  311. CHECK_EQUAL(6, info.m);
  312. /// Unmotorize the first joint angle
  313. dJointSetUniversalParam(jId, dParamFMax, 0);
  314. joint->getInfo1(&info);
  315. CHECK_EQUAL(0, joint->limot1.limit);
  316. CHECK_EQUAL(5, info.m);
  317. }
  318. TEST_FIXTURE(UniversalGetInfo1_Fixture_1, test_hinge2GetInfo1_RotAroundY)
  319. {
  320. // ^Y
  321. // |---| HiStop
  322. // | | ^Y /
  323. // |B_2| | /
  324. // |---| | /
  325. // | ----- | /
  326. // Z <-- * Z<--|B_2|--*
  327. // / | \ ----- | \
  328. // /|---|\ |---| \
  329. // / | | \ | | \
  330. // / |B_1| \ |B_1| \
  331. // / |---| \ |---| \
  332. //LoStop HiStop LoStop
  333. //
  334. //
  335. //
  336. //
  337. dMatrix3 R;
  338. dJointSetUniversalParam(jId, dParamLoStop, -M_PI/4.0);
  339. dJointSetUniversalParam(jId, dParamHiStop, M_PI/4.0);
  340. dJointSetUniversalParam(jId, dParamLoStop2, -M_PI/4.0);
  341. dJointSetUniversalParam(jId, dParamHiStop2, M_PI/4.0);
  342. dxJoint::Info1 info;
  343. dxJointUniversal* joint = (dxJointUniversal*)jId;
  344. // Original position inside the limits
  345. joint->getInfo1(&info);
  346. CHECK_EQUAL(0, joint->limot1.limit);
  347. CHECK_EQUAL(4, info.m);
  348. // Move the body outside the Lo limits
  349. dBodySetPosition (bId2, 0, 0, 1);
  350. dRFromAxisAndAngle (R, 0, 1, 0, M_PI/2.0);
  351. dBodySetRotation (bId2, R);
  352. joint->getInfo1(&info);
  353. CHECK_EQUAL(1, joint->limot2.limit);
  354. CHECK_EQUAL(5, info.m);
  355. // Return to original position
  356. // Keep the limits
  357. dBodySetPosition (bId2, 0, 1, 0);
  358. dRFromAxisAndAngle (R, 0, 1, 0, 0);
  359. dBodySetRotation (bId2, R);
  360. joint->getInfo1(&info);
  361. CHECK_EQUAL(0, joint->limot2.limit);
  362. CHECK_EQUAL(4, info.m);
  363. // Move the body outside the Lo limits
  364. dBodySetPosition (bId2, 0, 0, 1);
  365. dRFromAxisAndAngle (R, 0, 1, 0, M_PI/2.0);
  366. dBodySetRotation (bId2, R);
  367. joint->getInfo1(&info);
  368. CHECK_EQUAL(1, joint->limot2.limit);
  369. CHECK_EQUAL(5, info.m);
  370. // Return to original position
  371. // and remove the limits
  372. dBodySetPosition (bId2, 0, 1, 0);
  373. dRFromAxisAndAngle (R, 0, 1, 0, 0);
  374. dBodySetRotation (bId2, R);
  375. dJointSetUniversalParam(jId, dParamLoStop2, -2*M_PI);
  376. dJointSetUniversalParam(jId, dParamHiStop2, 2*M_PI);
  377. joint->getInfo1(&info);
  378. CHECK_EQUAL(0, joint->limot2.limit);
  379. CHECK_EQUAL(4, info.m);
  380. // Set the limits
  381. // Move pass the Hi limits
  382. dJointSetUniversalParam(jId, dParamLoStop2, -M_PI/4.0);
  383. dJointSetUniversalParam(jId, dParamHiStop2, M_PI/4.0);
  384. dBodySetPosition (bId2, 0, 0, 1);
  385. dRFromAxisAndAngle (R, 0, 1, 0, -M_PI/2.0);
  386. dBodySetRotation (bId2, R);
  387. joint->getInfo1(&info);
  388. CHECK_EQUAL(2, joint->limot2.limit);
  389. CHECK_EQUAL(5, info.m);
  390. // Return to original position
  391. // Keep the limits
  392. dBodySetPosition (bId2, 0, 1, 0);
  393. dRFromAxisAndAngle (R, 0, 1, 0, 0);
  394. dBodySetRotation (bId2, R);
  395. joint->getInfo1(&info);
  396. CHECK_EQUAL(0, joint->limot2.limit);
  397. CHECK_EQUAL(4, info.m);
  398. // Move the pass the Hi limit
  399. dBodySetPosition (bId2, 0, 0, 1);
  400. dRFromAxisAndAngle (R, 0, 1, 0, -M_PI/2.0);
  401. dBodySetRotation (bId2, R);
  402. joint->getInfo1(&info);
  403. CHECK_EQUAL(2, joint->limot2.limit);
  404. CHECK_EQUAL(5, info.m);
  405. // Return to original position
  406. // and remove the limits
  407. dBodySetPosition (bId2, 0, 1, 0);
  408. dRFromAxisAndAngle (R, 0, 1, 0, -M_PI/2.0);
  409. dBodySetRotation (bId2, R);
  410. dJointSetUniversalParam(jId, dParamLoStop2, -2*M_PI);
  411. dJointSetUniversalParam(jId, dParamHiStop2, 2*M_PI);
  412. joint->getInfo1(&info);
  413. CHECK_EQUAL(0, joint->limot2.limit);
  414. CHECK_EQUAL(4, info.m);
  415. /// Motorize the first joint angle
  416. dJointSetUniversalParam(jId, dParamFMax, 2);
  417. joint->getInfo1(&info);
  418. CHECK_EQUAL(0, joint->limot2.limit);
  419. CHECK_EQUAL(5, info.m);
  420. /// Motorize the second joint angle
  421. dJointSetUniversalParam(jId, dParamFMax2, 2);
  422. joint->getInfo1(&info);
  423. CHECK_EQUAL(0, joint->limot2.limit);
  424. CHECK_EQUAL(6, info.m);
  425. /// Unmotorize the first joint angle
  426. dJointSetUniversalParam(jId, dParamFMax, 0);
  427. joint->getInfo1(&info);
  428. CHECK_EQUAL(0, joint->limot2.limit);
  429. CHECK_EQUAL(5, info.m);
  430. }
  431. } // End of SUITE(JointUniversal)
  432. // // //
  433. // Testing the PR Joint
  434. //
  435. SUITE(JointPR)
  436. {
  437. struct PRGetInfo1_Fixture_1
  438. {
  439. PRGetInfo1_Fixture_1()
  440. {
  441. wId = dWorldCreate();
  442. bId1 = dBodyCreate(wId);
  443. dBodySetPosition(bId1, 0, -1, 0);
  444. bId2 = dBodyCreate(wId);
  445. dBodySetPosition(bId2, 0, 1, 0);
  446. jId = dJointCreatePR(wId, 0);
  447. joint = (dxJointPR*)jId;
  448. dJointAttach(jId, bId1, bId2);
  449. dJointSetPRAnchor (jId, REAL(0.0), REAL(0.0), REAL(0.0));
  450. }
  451. ~PRGetInfo1_Fixture_1()
  452. {
  453. dWorldDestroy(wId);
  454. }
  455. dJointID jId;
  456. dxJointPR* joint;
  457. dWorldID wId;
  458. dBodyID bId1;
  459. dBodyID bId2;
  460. dxJoint::Info1 info;
  461. };
  462. ////////////////////////////////////////////////////////////////////////////////
  463. // Test when there is no limits.
  464. // The 2 bodies stay aligned.
  465. //
  466. // Default value for axisR1 = 1,0,0
  467. // Default value for axisP1 = 0,1,0
  468. ////////////////////////////////////////////////////////////////////////////////
  469. TEST_FIXTURE(PRGetInfo1_Fixture_1, test1_PRGetInfo1_)
  470. {
  471. dJointSetPRParam(jId, dParamLoStop, -dInfinity);
  472. dJointSetPRParam(jId, dParamHiStop, dInfinity);
  473. dJointSetPRParam(jId, dParamLoStop2, -M_PI);
  474. dJointSetPRParam(jId, dParamHiStop2, M_PI);
  475. joint->getInfo1(&info);
  476. CHECK_EQUAL(0, joint->limotP.limit);
  477. CHECK_EQUAL(0, joint->limotR.limit);
  478. CHECK_EQUAL(4, info.m);
  479. }
  480. ////////////////////////////////////////////////////////////////////////////////
  481. // Test when there is limits for the prismatic at -10 and 10
  482. // The Body 2 is moved -100 unit then at 100
  483. //
  484. // Default value for axisR1 = 1,0,0
  485. // Default value for axisP1 = 0,1,0
  486. ////////////////////////////////////////////////////////////////////////////////
  487. TEST_FIXTURE(PRGetInfo1_Fixture_1, test2_PRGetInfo1)
  488. {
  489. dJointSetPRParam(jId, dParamLoStop, -10);
  490. dJointSetPRParam(jId, dParamHiStop, 10);
  491. dJointSetPRParam(jId, dParamLoStop2, -M_PI);
  492. dJointSetPRParam(jId, dParamHiStop2, M_PI);
  493. dBodySetPosition(bId2, 0, -100, 0);
  494. joint->getInfo1(&info);
  495. CHECK_EQUAL(2, joint->limotP.limit);
  496. CHECK_EQUAL(0, joint->limotR.limit);
  497. CHECK_EQUAL(5, info.m);
  498. dBodySetPosition(bId2, 0, 100, 0);
  499. joint->getInfo1(&info);
  500. CHECK_EQUAL(1, joint->limotP.limit);
  501. CHECK_EQUAL(0, joint->limotR.limit);
  502. CHECK_EQUAL(5, info.m);
  503. // Reset Position and test
  504. dBodySetPosition(bId2, 0, 1, 0);
  505. dMatrix3 R_final = { 1,0,0,0,
  506. 0,1,0,0,
  507. 0,0,1,0
  508. };
  509. dBodySetRotation (bId2, R_final);
  510. joint->getInfo1(&info);
  511. CHECK_EQUAL(0, joint->limotP.limit);
  512. CHECK_EQUAL(0, joint->limotR.limit);
  513. CHECK_EQUAL(4, info.m);
  514. }
  515. ////////////////////////////////////////////////////////////////////////////////
  516. // Test when there is limits for the prismatic at -10 and 10
  517. // and for the rotoide at -45deg and 45deg.
  518. // The Body 2 is only rotated by 90deg since the rotoide limits are not
  519. // used this should not change the limit value.
  520. //
  521. // Default value for axisR1 = 1,0,0
  522. // Default value for axisP1 = 0,1,0
  523. //
  524. ////////////////////////////////////////////////////////////////////////////////
  525. TEST_FIXTURE(PRGetInfo1_Fixture_1, test3_PRGetInfo1)
  526. {
  527. dJointSetPRParam(jId, dParamLoStop, -10);
  528. dJointSetPRParam(jId, dParamHiStop, 10);
  529. dJointSetPRParam(jId, dParamLoStop2, -M_PI/4.0);
  530. dJointSetPRParam(jId, dParamHiStop2, M_PI/4.0);
  531. dMatrix3 R;
  532. dBodySetPosition (bId2, 0, 0, 1);
  533. dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0);
  534. dBodySetRotation (bId2, R);
  535. joint->getInfo1(&info);
  536. CHECK_EQUAL(0, joint->limotP.limit);
  537. CHECK_EQUAL(1, joint->limotR.limit);
  538. CHECK_EQUAL(5, info.m);
  539. // Reset Position and test
  540. dBodySetPosition(bId2, 0, 1, 0);
  541. dMatrix3 R_final = { 1,0,0,0,
  542. 0,1,0,0,
  543. 0,0,1,0
  544. };
  545. dBodySetRotation (bId2, R_final);
  546. joint->getInfo1(&info);
  547. CHECK_EQUAL(0, joint->limotP.limit);
  548. CHECK_EQUAL(0, joint->limotR.limit);
  549. CHECK_EQUAL(4, info.m);
  550. }
  551. // The joint is now powered. (i.e. info->fmax > 0
  552. struct PRGetInfo1_Fixture_2
  553. {
  554. PRGetInfo1_Fixture_2()
  555. {
  556. wId = dWorldCreate();
  557. bId1 = dBodyCreate(wId);
  558. dBodySetPosition(bId1, 0, -1, 0);
  559. bId2 = dBodyCreate(wId);
  560. dBodySetPosition(bId2, 0, 1, 0);
  561. jId = dJointCreatePR(wId, 0);
  562. joint = (dxJointPR*)jId;
  563. dJointAttach(jId, bId1, bId2);
  564. dJointSetPRAnchor (jId, REAL(0.0), REAL(0.0), REAL(0.0));
  565. joint->limotP.fmax = 1;
  566. }
  567. ~PRGetInfo1_Fixture_2()
  568. {
  569. dWorldDestroy(wId);
  570. }
  571. dJointID jId;
  572. dxJointPR* joint;
  573. dWorldID wId;
  574. dBodyID bId1;
  575. dBodyID bId2;
  576. dxJoint::Info1 info;
  577. };
  578. ////////////////////////////////////////////////////////////////////////////////
  579. // Test when there is no limits.
  580. // The 2 bodies stay align.
  581. //
  582. // Default value for axisR1 = 1,0,0
  583. // Default value for axisP1 = 0,1,0
  584. //
  585. ////////////////////////////////////////////////////////////////////////////////
  586. TEST_FIXTURE(PRGetInfo1_Fixture_2, test1_PRGetInfo1)
  587. {
  588. dJointSetPRParam(jId, dParamLoStop, -dInfinity);
  589. dJointSetPRParam(jId, dParamHiStop, dInfinity);
  590. dJointSetPRParam(jId, dParamLoStop2, -M_PI);
  591. dJointSetPRParam(jId, dParamHiStop2, M_PI);
  592. joint->getInfo1(&info);
  593. CHECK_EQUAL(0, joint->limotP.limit);
  594. CHECK_EQUAL(0, joint->limotR.limit);
  595. CHECK_EQUAL(5, info.m);
  596. }
  597. ////////////////////////////////////////////////////////////////////////////////
  598. // Test when there is limits for the prismatic at -10 and 10
  599. // The Body 2 is moved -100 unit then at 100
  600. //
  601. // Default value for axisR1 = 1,0,0
  602. // Default value for axisP1 = 0,1,0
  603. //
  604. ////////////////////////////////////////////////////////////////////////////////
  605. TEST_FIXTURE(PRGetInfo1_Fixture_2, test2_PRGetInfo1)
  606. {
  607. dJointSetPRParam(jId, dParamLoStop, -10);
  608. dJointSetPRParam(jId, dParamHiStop, 10);
  609. dJointSetPRParam(jId, dParamLoStop2, -M_PI);
  610. dJointSetPRParam(jId, dParamHiStop2, M_PI);
  611. dBodySetPosition(bId2, 0, -100, 0);
  612. joint->getInfo1(&info);
  613. CHECK_EQUAL(2, joint->limotP.limit);
  614. CHECK_EQUAL(0, joint->limotR.limit);
  615. CHECK_EQUAL(5, info.m);
  616. dBodySetPosition(bId2, 0, 100, 0);
  617. joint->getInfo1(&info);
  618. CHECK_EQUAL(1, joint->limotP.limit);
  619. CHECK_EQUAL(0, joint->limotR.limit);
  620. CHECK_EQUAL(5, info.m);
  621. // Reset Position and test
  622. dBodySetPosition(bId2, 0, 1, 0);
  623. dMatrix3 R_final = { 1,0,0,0,
  624. 0,1,0,0,
  625. 0,0,1,0
  626. };
  627. dBodySetRotation (bId2, R_final);
  628. joint->getInfo1(&info);
  629. CHECK_EQUAL(0, joint->limotP.limit);
  630. CHECK_EQUAL(0, joint->limotR.limit);
  631. CHECK_EQUAL(5, info.m);
  632. }
  633. ////////////////////////////////////////////////////////////////////////////////
  634. // Test when there is limits for the prismatic at -10 and 10
  635. // and for the rotoide at -45deg and 45deg
  636. // The Body 2 is only rotated by 90deg since the rotoide limits are not
  637. // used this should not change the limit value.
  638. //
  639. // Default value for axisR1 = 1,0,0
  640. // Default value for axisP1 = 0,1,0
  641. //
  642. ////////////////////////////////////////////////////////////////////////////////
  643. TEST_FIXTURE(PRGetInfo1_Fixture_2, test3_PRGetInfo1)
  644. {
  645. dJointSetPRParam(jId, dParamLoStop, -10);
  646. dJointSetPRParam(jId, dParamHiStop, 10);
  647. dJointSetPRParam(jId, dParamLoStop2, -M_PI/4.0);
  648. dJointSetPRParam(jId, dParamHiStop2, M_PI/4.0);
  649. dMatrix3 R;
  650. dBodySetPosition (bId2, 0, 0, 100);
  651. dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0);
  652. dBodySetRotation (bId2, R);
  653. joint->getInfo1(&info);
  654. CHECK_EQUAL(0, joint->limotP.limit);
  655. CHECK_EQUAL(1, joint->limotR.limit);
  656. CHECK_EQUAL(6, info.m);
  657. // Reset Position and test
  658. dBodySetPosition(bId2, 0, 1, 0);
  659. dMatrix3 R_final = { 1,0,0,0,
  660. 0,1,0,0,
  661. 0,0,1,0
  662. };
  663. dBodySetRotation (bId2, R_final);
  664. joint->getInfo1(&info);
  665. CHECK_EQUAL(0, joint->limotP.limit);
  666. CHECK_EQUAL(0, joint->limotR.limit);
  667. CHECK_EQUAL(5, info.m);
  668. }
  669. ////////////////////////////////////////////////////////////////////////////////
  670. // Test the setting and getting of parameters
  671. ////////////////////////////////////////////////////////////////////////////////
  672. TEST_FIXTURE(PRGetInfo1_Fixture_1, test_SetPRParam)
  673. {
  674. dJointSetPRParam(jId, dParamHiStop, REAL(5.0) );
  675. CHECK_EQUAL(REAL(5.0), joint->limotP.histop);
  676. dJointSetPRParam(jId, dParamVel, REAL(7.0) );
  677. CHECK_EQUAL(REAL(7.0), joint->limotP.vel);
  678. #ifdef dParamFudgeFactor1
  679. dJointSetPRParam(jId, dParamFudgeFactor1, REAL(5.5) );
  680. CHECK_EQUAL(REAL(5.5), joint->limotP.dParamFudgeFactor);
  681. #endif
  682. dJointSetPRParam(jId, dParamCFM2, REAL(9.0) );
  683. CHECK_EQUAL(REAL(9.0), joint->limotR.normal_cfm);
  684. dJointSetPRParam(jId, dParamStopERP2, REAL(11.0) );
  685. CHECK_EQUAL(REAL(11.0), joint->limotR.stop_erp);
  686. }
  687. TEST_FIXTURE(PRGetInfo1_Fixture_1, test_GetPRParam)
  688. {
  689. joint->limotP.histop = REAL(5.0);
  690. CHECK_EQUAL(joint->limotP.histop,
  691. dJointGetPRParam(jId, dParamHiStop) );
  692. joint->limotP.vel = REAL(7.0);
  693. CHECK_EQUAL(joint->limotP.vel,
  694. dJointGetPRParam(jId, dParamVel) );
  695. #ifdef dParamFudgeFactor1
  696. joint->limotP.dParamFudgeFactor = REAL(5.5);
  697. CHECK_EQUAL(joint->limotP.dParamFudgeFactor,
  698. dJointGetPRParam(jId, dParamFudgeFactor1) );
  699. #endif
  700. joint->limotR.normal_cfm = REAL(9.0);
  701. CHECK_EQUAL(joint->limotR.normal_cfm,
  702. dJointGetPRParam(jId, dParamCFM2) );
  703. joint->limotR.stop_erp = REAL(11.0);
  704. CHECK_EQUAL(joint->limotR.stop_erp,
  705. dJointGetPRParam(jId, dParamStopERP2) );
  706. }
  707. ////////////////////////////////////////////////////////////////////////////////
  708. // Fixture for testing the PositionRate
  709. //
  710. // Default Position
  711. // ^Z
  712. // |
  713. // |
  714. //
  715. // Body2 R Body1
  716. // +---------+ _ - +-----------+
  717. // | |--------(_)----|-----| | ----->Y
  718. // +---------+ - +-----------+
  719. //
  720. // N.B. X is comming out of the page
  721. ////////////////////////////////////////////////////////////////////////////////
  722. struct PRGetInfo1_Fixture_3
  723. {
  724. PRGetInfo1_Fixture_3()
  725. {
  726. wId = dWorldCreate();
  727. bId1 = dBodyCreate(wId);
  728. dBodySetPosition(bId1, 0, 1, 0);
  729. bId2 = dBodyCreate(wId);
  730. dBodySetPosition(bId2, 0, -1, 0);
  731. jId = dJointCreatePR(wId, 0);
  732. joint = (dxJointPR*)jId;
  733. dJointAttach(jId, bId1, bId2);
  734. dJointSetPRAnchor (jId, REAL(0.0), REAL(0.0), REAL(0.0));
  735. dBodySetLinearVel (bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  736. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  737. dBodySetLinearVel (bId2, REAL(0.0), REAL(0.0), REAL(0.0));
  738. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  739. }
  740. ~PRGetInfo1_Fixture_3()
  741. {
  742. dWorldDestroy(wId);
  743. }
  744. dJointID jId;
  745. dxJointPR* joint;
  746. dWorldID wId;
  747. dBodyID bId1;
  748. dBodyID bId2;
  749. dxJoint::Info1 info;
  750. };
  751. ////////////////////////////////////////////////////////////////////////////////
  752. // Position Body1 [0, 1, 0]
  753. // Position Body2 [0, -1, 0]
  754. // Axis of the prismatic [0, 1, 0]
  755. // Axis of the rotoide [1, 0, ]0
  756. //
  757. // Move at the same speed
  758. ////////////////////////////////////////////////////////////////////////////////
  759. TEST_FIXTURE(PRGetInfo1_Fixture_3, test_GetPRPositionRate_1)
  760. {
  761. // They move with the same linear speed
  762. // Angular speed == 0
  763. dBodySetLinearVel(bId1, REAL(0.0), REAL(3.33), REAL(0.0));
  764. dBodySetLinearVel(bId2, REAL(0.0), REAL(3.33), REAL(0.0));
  765. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  766. dBodySetLinearVel(bId1, REAL(1.11), REAL(3.33), REAL(0.0));
  767. dBodySetLinearVel(bId2, REAL(1.11), REAL(3.33), REAL(0.0));
  768. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  769. dBodySetLinearVel(bId1, REAL(1.11), REAL(3.33), REAL(2.22));
  770. dBodySetLinearVel(bId2, REAL(1.11), REAL(3.33), REAL(2.22));
  771. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  772. // Reset for the next set of test.
  773. dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  774. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  775. dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(0.0));
  776. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  777. // They move with the same angular speed
  778. // linear speed == 0
  779. dBodySetAngularVel(bId1, REAL(1.22), REAL(0.0), REAL(0.0));
  780. dBodySetAngularVel(bId2, REAL(1.22), REAL(0.0), REAL(0.0));
  781. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  782. dBodySetAngularVel(bId1, REAL(1.22), REAL(2.33), REAL(0.0));
  783. dBodySetAngularVel(bId2, REAL(1.22), REAL(2.33), REAL(0.0));
  784. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  785. dBodySetAngularVel(bId1, REAL(1.22), REAL(2.33), REAL(3.44));
  786. dBodySetAngularVel(bId2, REAL(1.22), REAL(2.33), REAL(3.44));
  787. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  788. }
  789. ////////////////////////////////////////////////////////////////////////////////
  790. // Position Body1 [0, 1, 0]
  791. // Position Body2 [0, -1, 0]
  792. // Axis of the prismatic [0, 1, 0]
  793. // Axis of the rotoide [1, 0, ]0
  794. //
  795. // Only the first body moves
  796. ////////////////////////////////////////////////////////////////////////////////
  797. TEST_FIXTURE(PRGetInfo1_Fixture_3, GetPRPositionRate_Bodies_in_line_B1_moves)
  798. {
  799. dBodySetLinearVel(bId1, REAL(3.33), REAL(0.0), REAL(0.0)); // This is impossible but ...
  800. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  801. dBodySetLinearVel(bId1, REAL(0.0), REAL(3.33), REAL(0.0));
  802. CHECK_EQUAL(REAL(3.33), dJointGetPRPositionRate (jId) );
  803. dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(3.33)); // This is impossible but ...
  804. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  805. // Only the first body as angular velocity
  806. dBodySetAngularVel(bId1, REAL(1.22), REAL(0.0), REAL(0.0));
  807. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  808. dBodySetAngularVel(bId1, REAL(0.0), REAL(2.33), REAL(0.0));
  809. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  810. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(5.55));
  811. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  812. }
  813. ////////////////////////////////////////////////////////////////////////////////
  814. // Position Body1 [0, 1, 0]
  815. // Position Body2 [0, -1, 0]
  816. // Axis of the prismatic [0, 1, 0]
  817. // Axis of the rotoide [1, 0, ]0
  818. //
  819. // Only the second body moves
  820. ////////////////////////////////////////////////////////////////////////////////
  821. TEST_FIXTURE(PRGetInfo1_Fixture_3, GetPRPositionRate_Bodies_in_line_B2_moves)
  822. {
  823. dBodySetLinearVel(bId2, REAL(3.33), REAL(0.0), REAL(0.0)); // This is impossible but ...
  824. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  825. // The length was at zero and this will give an negative length
  826. dBodySetLinearVel(bId2, REAL(0.0), REAL(3.33), REAL(0.0));
  827. CHECK_EQUAL(REAL(-3.33), dJointGetPRPositionRate (jId) );
  828. dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(3.33)); // This is impossible but ...
  829. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  830. // Only angular velocity
  831. dBodySetAngularVel(bId2, REAL(1.22), REAL(0.0), REAL(0.0));
  832. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  833. dBodySetAngularVel(bId2, REAL(0.0), REAL(2.33), REAL(0.0));
  834. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  835. dBodySetAngularVel(bId2, REAL(0.0), REAL(0.0), REAL(5.55));
  836. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  837. }
  838. ////////////////////////////////////////////////////////////////////////////////
  839. // Fixture for testing the PositionRate
  840. //
  841. // The second body is at 90deg w.r.t. the first body
  842. //
  843. //
  844. // Default Position
  845. // ^Z
  846. // |
  847. // |
  848. //
  849. // +---+
  850. // | |Body2
  851. // | |
  852. // | |
  853. // +---+
  854. // |
  855. // |
  856. // |
  857. // | Body1
  858. // R _ - +-----------+
  859. // (_)----|-----| | ----->Y
  860. // - +-----------+
  861. //
  862. // N.B. X is comming out of the page
  863. ////////////////////////////////////////////////////////////////////////////////
  864. struct PRGetInfo1_Fixture_4
  865. {
  866. PRGetInfo1_Fixture_4()
  867. {
  868. wId = dWorldCreate();
  869. bId1 = dBodyCreate(wId);
  870. dBodySetPosition(bId1, 0, 1, 0);
  871. bId2 = dBodyCreate(wId);
  872. dBodySetPosition(bId2, 0, 0, 1);
  873. dMatrix3 R;
  874. dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0);
  875. dBodySetRotation (bId2, R);
  876. jId = dJointCreatePR(wId, 0);
  877. joint = (dxJointPR*)jId;
  878. dJointAttach(jId, bId1, bId2);
  879. dJointSetPRAnchor (jId, REAL(0.0), REAL(0.0), REAL(0.0));
  880. dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  881. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  882. dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(0.0));
  883. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  884. }
  885. ~PRGetInfo1_Fixture_4()
  886. {
  887. dWorldDestroy(wId);
  888. }
  889. dJointID jId;
  890. dxJointPR* joint;
  891. dWorldID wId;
  892. dBodyID bId1;
  893. dBodyID bId2;
  894. dxJoint::Info1 info;
  895. };
  896. ////////////////////////////////////////////////////////////////////////////////
  897. // Position Body1 [0, 1, 0]
  898. // Position Body2 [0, 0, 1]
  899. // Axis of the prismatic [0, 1, 0]
  900. // Axis of the rotoide [1, 0, 0]
  901. //
  902. // Only the first body moves
  903. ////////////////////////////////////////////////////////////////////////////////
  904. TEST_FIXTURE(PRGetInfo1_Fixture_4, GetPRPositionRate_Bodies_at90deg_B1_moves)
  905. {
  906. dBodySetLinearVel(bId1, REAL(3.33), REAL(0.0), REAL(0.0)); // This is impossible but ...
  907. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  908. // The length was at zero and this will give an negative length
  909. dBodySetLinearVel(bId1, REAL(0.0), REAL(3.33), REAL(0.0));
  910. CHECK_EQUAL(REAL(3.33), dJointGetPRPositionRate (jId) );
  911. dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(3.33)); // This is impossible but ...
  912. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  913. // Only angular velocity
  914. dBodySetAngularVel(bId1, REAL(1.22), REAL(0.0), REAL(0.0));
  915. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  916. dBodySetAngularVel(bId1, REAL(0.0), REAL(2.33), REAL(0.0));
  917. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  918. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(5.55));
  919. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  920. }
  921. ////////////////////////////////////////////////////////////////////////////////
  922. // Position Body1 [0, 1, 0]
  923. // Position Body2 [0, 0, 1]
  924. // Axis of the prismatic [0, 1, 0]
  925. // Axis of the rotoide [1, 0, 0]
  926. //
  927. // Only the second body moves
  928. ////////////////////////////////////////////////////////////////////////////////
  929. TEST_FIXTURE(PRGetInfo1_Fixture_4, GetPRPositionRate_Bodies_at90deg_B2_moves)
  930. {
  931. dBodySetLinearVel(bId2, REAL(3.33), REAL(0.0), REAL(0.0)); // This is impossible but ...
  932. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  933. dBodySetLinearVel(bId2, REAL(0.0), REAL(3.33), REAL(0.0));
  934. CHECK_EQUAL(REAL(-3.33), dJointGetPRPositionRate (jId) );
  935. dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(3.33)); // This is impossible but ...
  936. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  937. // Only angular velocity
  938. dBodySetAngularVel(bId2, REAL(1.22), REAL(0.0), REAL(0.0));
  939. CHECK_EQUAL(REAL(-1.0*1.22), dJointGetPRPositionRate (jId) );
  940. dBodySetAngularVel(bId2, REAL(0.0), REAL(2.33), REAL(0.0));
  941. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  942. dBodySetAngularVel(bId2, REAL(0.0), REAL(0.0), REAL(5.55));
  943. CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) );
  944. }
  945. } // End of SUITE(JointPR)
  946. // // //
  947. // Testing the PU Joint
  948. //
  949. // //
  950. ////////////////////////////////////////////////////////////////////////////////
  951. // Default Position:
  952. // Position Body1 (3, 0, 0)
  953. // Position Body2 (1, 0, 0)
  954. // Angchor (2, 0, 0)
  955. // Axis1 (0, 1, 0)
  956. // Axis2 (0, 0, 1)
  957. // AxisP1 (1, 0, 0)
  958. //
  959. // Y ^ Axis2
  960. // ^ |
  961. // / | ^ Axis1
  962. // Z^ / | /
  963. // | / Body 2 | / Body 1
  964. // | / +---------+ | / +-----------+
  965. // | / / /| | / / /|
  966. // | / / / + _/ - / / +
  967. // | / / /-/--------(_)----|--- /-----------/-------> AxisP
  968. // | / +---------+ / - +-----------+ /
  969. // | / | |/ | |/
  970. // | / +---------+ +-----------+
  971. // |/
  972. // .-----------------------------------------> X
  973. // |----------------->
  974. // Anchor2 <--------------|
  975. // Anchor1
  976. //
  977. ////////////////////////////////////////////////////////////////////////////////
  978. SUITE(JointPU)
  979. {
  980. struct PUGetInfo1_Fixture_1
  981. {
  982. PUGetInfo1_Fixture_1()
  983. {
  984. wId = dWorldCreate();
  985. bId1 = dBodyCreate(wId);
  986. dBodySetPosition(bId1, 3, 0, 0);
  987. bId2 = dBodyCreate(wId);
  988. dBodySetPosition(bId2, 1, 0, 0);
  989. jId = dJointCreatePU(wId, 0);
  990. joint = (dxJointPU*)jId;
  991. dJointAttach(jId, bId1, bId2);
  992. dJointSetPUAnchor (jId, 2, 0, 0);
  993. }
  994. ~PUGetInfo1_Fixture_1()
  995. {
  996. dWorldDestroy(wId);
  997. }
  998. dJointID jId;
  999. dxJointPU* joint;
  1000. dWorldID wId;
  1001. dBodyID bId1;
  1002. dBodyID bId2;
  1003. dxJoint::Info1 info;
  1004. };
  1005. ////////////////////////////////////////////////////////////////////////////////
  1006. // Test when there is no limits.
  1007. // The 2 bodies stay aligned.
  1008. //
  1009. ////////////////////////////////////////////////////////////////////////////////
  1010. TEST_FIXTURE(PUGetInfo1_Fixture_1, test1_SetPUParam)
  1011. {
  1012. dJointSetPUParam(jId, dParamLoStop1, -M_PI);
  1013. dJointSetPUParam(jId, dParamHiStop1 , M_PI);
  1014. dJointSetPUParam(jId, dParamLoStop2, -M_PI);
  1015. dJointSetPUParam(jId, dParamHiStop2, M_PI);
  1016. dJointSetPUParam(jId, dParamLoStop3, -dInfinity);
  1017. dJointSetPUParam(jId, dParamHiStop3, dInfinity);
  1018. joint->getInfo1(&info);
  1019. CHECK_EQUAL(0, joint->limot1.limit);
  1020. CHECK_EQUAL(0, joint->limot2.limit);
  1021. CHECK_EQUAL(0, joint->limotP.limit);
  1022. CHECK_EQUAL(3, info.m);
  1023. }
  1024. ////////////////////////////////////////////////////////////////////////////////
  1025. // Test when there is limits for the prismatic at -10 and 10
  1026. // The Body 2 is moved -100 unit then at 100
  1027. //
  1028. // Default value for axisR1 = 1,0,0
  1029. // Default value for axisP1 = 0,1,0
  1030. ////////////////////////////////////////////////////////////////////////////////
  1031. TEST_FIXTURE(PUGetInfo1_Fixture_1, test1_GetPUParam)
  1032. {
  1033. dJointSetPUParam(jId, dParamLoStop3, -10);
  1034. dJointSetPUParam(jId, dParamHiStop3, 10);
  1035. dBodySetPosition(bId2, REAL(-100.0), REAL(0.0), REAL(0.0));
  1036. joint->getInfo1(&info);
  1037. CHECK_EQUAL(0, joint->limot1.limit);
  1038. CHECK_EQUAL(0, joint->limot2.limit);
  1039. CHECK_EQUAL(2, joint->limotP.limit);
  1040. CHECK_EQUAL(4, info.m);
  1041. dBodySetPosition(bId2, REAL(100.0), REAL(0.0), REAL(0.0));
  1042. joint->getInfo1(&info);
  1043. CHECK_EQUAL(0, joint->limot1.limit);
  1044. CHECK_EQUAL(0, joint->limot2.limit);
  1045. CHECK_EQUAL(1, joint->limotP.limit);
  1046. CHECK_EQUAL(4, info.m);
  1047. // Reset Position and test
  1048. dBodySetPosition(bId2, 1, 0, 0);
  1049. dMatrix3 R_final = { 1,0,0,0,
  1050. 0,1,0,0,
  1051. 0,0,1,0
  1052. };
  1053. dBodySetRotation (bId2, R_final);
  1054. joint->getInfo1(&info);
  1055. CHECK_EQUAL(0, joint->limot1.limit);
  1056. CHECK_EQUAL(0, joint->limot2.limit);
  1057. CHECK_EQUAL(0, joint->limotP.limit);
  1058. CHECK_EQUAL(3, info.m);
  1059. }
  1060. ////////////////////////////////////////////////////////////////////////////////
  1061. // Test when there is limits for the prismatic at -10 and 10
  1062. // and for Axis1 and Axis2 at -45deg and 45deg.
  1063. // The Body 2 is rotated by 90deg around Axis1
  1064. //
  1065. //
  1066. ////////////////////////////////////////////////////////////////////////////////
  1067. TEST_FIXTURE(PUGetInfo1_Fixture_1, test2_PUGetInfo1)
  1068. {
  1069. dJointSetPUParam(jId, dParamLoStop1, -M_PI/4.0);
  1070. dJointSetPUParam(jId, dParamHiStop1, M_PI/4.0);
  1071. dJointSetPUParam(jId, dParamLoStop2, -M_PI/4.0);
  1072. dJointSetPUParam(jId, dParamHiStop2, M_PI/4.0);
  1073. dJointSetPUParam(jId, dParamLoStop3, -10);
  1074. dJointSetPUParam(jId, dParamHiStop3, 10);
  1075. dMatrix3 R;
  1076. dBodySetPosition (bId2, 0, 0, 1);
  1077. dRFromAxisAndAngle (R, 0, 1, 0, M_PI/2.0);
  1078. dBodySetRotation (bId2, R);
  1079. joint->getInfo1(&info);
  1080. CHECK_EQUAL(1, joint->limot1.limit);
  1081. CHECK_EQUAL(0, joint->limot2.limit);
  1082. CHECK_EQUAL(0, joint->limotP.limit);
  1083. CHECK_EQUAL(4, info.m);
  1084. // Reset Position and test
  1085. dBodySetPosition(bId2, 1, 0, 0);
  1086. dMatrix3 R_final = { 1,0,0,0,
  1087. 0,1,0,0,
  1088. 0,0,1,0
  1089. };
  1090. dBodySetRotation (bId2, R_final);
  1091. joint->getInfo1(&info);
  1092. CHECK_EQUAL(0, joint->limot1.limit);
  1093. CHECK_EQUAL(0, joint->limot2.limit);
  1094. CHECK_EQUAL(0, joint->limotP.limit);
  1095. CHECK_EQUAL(3, info.m);
  1096. }
  1097. ////////////////////////////////////////////////////////////////////////////////
  1098. // Test when there is limits for the prismatic at -10 and 10
  1099. // and for Axis1 and Axis2 at -45deg and 45deg.
  1100. // The Body 2 is rotated by 90deg around Axis1 and
  1101. // Body1 is moved at X=100
  1102. //
  1103. //
  1104. ////////////////////////////////////////////////////////////////////////////////
  1105. TEST_FIXTURE(PUGetInfo1_Fixture_1, test3_PUGetInfo1)
  1106. {
  1107. dJointSetPUParam(jId, dParamLoStop1, -M_PI/4.0);
  1108. dJointSetPUParam(jId, dParamHiStop1, M_PI/4.0);
  1109. dJointSetPUParam(jId, dParamLoStop2, -M_PI/4.0);
  1110. dJointSetPUParam(jId, dParamHiStop2, M_PI/4.0);
  1111. dJointSetPUParam(jId, dParamLoStop3, -10);
  1112. dJointSetPUParam(jId, dParamHiStop3, 10);
  1113. dBodySetPosition (bId1, REAL(100.0), REAL(0.0), REAL(0.0));
  1114. dMatrix3 R;
  1115. dBodySetPosition (bId2, 0, 0, 1);
  1116. dRFromAxisAndAngle (R, 0, 1, 0, M_PI/2.0);
  1117. dBodySetRotation (bId2, R);
  1118. joint->getInfo1(&info);
  1119. CHECK_EQUAL(1, joint->limot1.limit);
  1120. CHECK_EQUAL(0, joint->limot2.limit);
  1121. CHECK_EQUAL(2, joint->limotP.limit);
  1122. CHECK_EQUAL(5, info.m);
  1123. // Reset Position and test
  1124. dBodySetPosition(bId1, 3, 0, 0);
  1125. dBodySetPosition(bId2, 1, 0, 0);
  1126. dMatrix3 R_final = { 1,0,0,0,
  1127. 0,1,0,0,
  1128. 0,0,1,0
  1129. };
  1130. dBodySetRotation (bId2, R_final);
  1131. joint->getInfo1(&info);
  1132. CHECK_EQUAL(0, joint->limot1.limit);
  1133. CHECK_EQUAL(0, joint->limot2.limit);
  1134. CHECK_EQUAL(0, joint->limotP.limit);
  1135. CHECK_EQUAL(3, info.m);
  1136. }
  1137. ////////////////////////////////////////////////////////////////////////////////
  1138. // Default Position:
  1139. // Position Body1 (3, 0, 0)
  1140. // Position Body2 (1, 0, 0)
  1141. // Angchor (2, 0, 0)
  1142. // Axis1 (0, 1, 0)
  1143. // Axis2 (0, 0, 1)
  1144. // AxisP1 (1, 0, 0)
  1145. //
  1146. // The motor on axis1 is now powered. (i.e. joint->limot1->fmax > 0
  1147. //
  1148. // Y ^ Axis2
  1149. // ^ |
  1150. // / | ^ Axis1
  1151. // Z^ / | /
  1152. // | / Body 2 | / Body 1
  1153. // | / +---------+ | / +-----------+
  1154. // | / / /| | / / /|
  1155. // | / / / + _/ - / / +
  1156. // | / / /-/--------(_)----|--- /-----------/-------> AxisP
  1157. // | / +---------+ / - +-----------+ /
  1158. // | / | |/ | |/
  1159. // | / +---------+ +-----------+
  1160. // |/
  1161. // .-----------------------------------------> X
  1162. // |----------------->
  1163. // Anchor2 <--------------|
  1164. // Anchor1
  1165. //
  1166. ////////////////////////////////////////////////////////////////////////////////
  1167. struct PUGetInfo1_Fixture_2
  1168. {
  1169. PUGetInfo1_Fixture_2()
  1170. {
  1171. wId = dWorldCreate();
  1172. bId1 = dBodyCreate(wId);
  1173. dBodySetPosition(bId1, 3, 0, 0);
  1174. bId2 = dBodyCreate(wId);
  1175. dBodySetPosition(bId2, 1, 0, 0);
  1176. jId = dJointCreatePU(wId, 0);
  1177. joint = (dxJointPU*)jId;
  1178. dJointAttach(jId, bId1, bId2);
  1179. dJointSetPUAnchor (jId, 2, 0, 0);
  1180. joint->limot1.fmax = 1;
  1181. }
  1182. ~PUGetInfo1_Fixture_2()
  1183. {
  1184. dWorldDestroy(wId);
  1185. }
  1186. dJointID jId;
  1187. dxJointPU* joint;
  1188. dWorldID wId;
  1189. dBodyID bId1;
  1190. dBodyID bId2;
  1191. dxJoint::Info1 info;
  1192. };
  1193. ////////////////////////////////////////////////////////////////////////////////
  1194. // Test when there is no limits.
  1195. // The 2 bodies stay aligned.
  1196. //
  1197. ////////////////////////////////////////////////////////////////////////////////
  1198. TEST_FIXTURE(PUGetInfo1_Fixture_2, test0_PUGetInfo1)
  1199. {
  1200. dJointSetPUParam(jId, dParamLoStop1, -M_PI);
  1201. dJointSetPUParam(jId, dParamHiStop1 , M_PI);
  1202. dJointSetPUParam(jId, dParamLoStop2, -M_PI);
  1203. dJointSetPUParam(jId, dParamHiStop2, M_PI);
  1204. dJointSetPUParam(jId, dParamLoStop3, -dInfinity);
  1205. dJointSetPUParam(jId, dParamHiStop3, dInfinity);
  1206. joint->getInfo1(&info);
  1207. CHECK_EQUAL(0, joint->limot1.limit);
  1208. CHECK_EQUAL(0, joint->limot2.limit);
  1209. CHECK_EQUAL(0, joint->limotP.limit);
  1210. CHECK_EQUAL(4, info.m);
  1211. }
  1212. ////////////////////////////////////////////////////////////////////////////////
  1213. // Test when there is limits for the prismatic at -10 and 10
  1214. // The Body 2 is moved -100 unit then at 100
  1215. //
  1216. // Default value for axisR1 = 1,0,0
  1217. // Default value for axisP1 = 0,1,0
  1218. ////////////////////////////////////////////////////////////////////////////////
  1219. TEST_FIXTURE(PUGetInfo1_Fixture_2, test1_PUGetInfo1)
  1220. {
  1221. dJointSetPUParam(jId, dParamLoStop3, -10);
  1222. dJointSetPUParam(jId, dParamHiStop3, 10);
  1223. dBodySetPosition(bId2, REAL(-100.0), REAL(0.0), REAL(0.0));
  1224. joint->getInfo1(&info);
  1225. CHECK_EQUAL(0, joint->limot1.limit);
  1226. CHECK_EQUAL(0, joint->limot2.limit);
  1227. CHECK_EQUAL(2, joint->limotP.limit);
  1228. CHECK_EQUAL(5, info.m);
  1229. dBodySetPosition(bId2, REAL(100.0), REAL(0.0), REAL(0.0));
  1230. joint->getInfo1(&info);
  1231. CHECK_EQUAL(0, joint->limot1.limit);
  1232. CHECK_EQUAL(0, joint->limot2.limit);
  1233. CHECK_EQUAL(1, joint->limotP.limit);
  1234. CHECK_EQUAL(5, info.m);
  1235. // Reset Position and test
  1236. dBodySetPosition(bId2, 1, 0, 0);
  1237. dMatrix3 R_final = { 1,0,0,0,
  1238. 0,1,0,0,
  1239. 0,0,1,0
  1240. };
  1241. dBodySetRotation (bId2, R_final);
  1242. joint->getInfo1(&info);
  1243. CHECK_EQUAL(0, joint->limot1.limit);
  1244. CHECK_EQUAL(0, joint->limot2.limit);
  1245. CHECK_EQUAL(0, joint->limotP.limit);
  1246. CHECK_EQUAL(4, info.m);
  1247. }
  1248. ////////////////////////////////////////////////////////////////////////////////
  1249. // Test when there is limits for the prismatic at -10 and 10
  1250. // and for Axis1 and Axis2 at -45deg and 45deg.
  1251. // The Body 2 is rotated by 90deg around Axis1
  1252. //
  1253. //
  1254. ////////////////////////////////////////////////////////////////////////////////
  1255. TEST_FIXTURE(PUGetInfo1_Fixture_2, test2_PUGetInfo1)
  1256. {
  1257. dJointSetPUParam(jId, dParamLoStop1, -M_PI/4.0);
  1258. dJointSetPUParam(jId, dParamHiStop1, M_PI/4.0);
  1259. dJointSetPUParam(jId, dParamLoStop2, -M_PI/4.0);
  1260. dJointSetPUParam(jId, dParamHiStop2, M_PI/4.0);
  1261. dJointSetPUParam(jId, dParamLoStop3, -10);
  1262. dJointSetPUParam(jId, dParamHiStop3, 10);
  1263. dMatrix3 R;
  1264. dBodySetPosition (bId2, 0, 0, 1);
  1265. dRFromAxisAndAngle (R, 0, 1, 0, M_PI/2.0);
  1266. dBodySetRotation (bId2, R);
  1267. joint->getInfo1(&info);
  1268. CHECK_EQUAL(1, joint->limot1.limit);
  1269. CHECK_EQUAL(0, joint->limot2.limit);
  1270. CHECK_EQUAL(0, joint->limotP.limit);
  1271. CHECK_EQUAL(4, info.m);
  1272. // Reset Position and test
  1273. dBodySetPosition(bId2, 1, 0, 0);
  1274. dMatrix3 R_final = { 1,0,0,0,
  1275. 0,1,0,0,
  1276. 0,0,1,0
  1277. };
  1278. dBodySetRotation (bId2, R_final);
  1279. joint->getInfo1(&info);
  1280. CHECK_EQUAL(0, joint->limot1.limit);
  1281. CHECK_EQUAL(0, joint->limot2.limit);
  1282. CHECK_EQUAL(0, joint->limotP.limit);
  1283. CHECK_EQUAL(4, info.m);
  1284. }
  1285. ////////////////////////////////////////////////////////////////////////////////
  1286. // Test when there is limits for the prismatic at -10 and 10
  1287. // and for Axis1 and Axis2 at -45deg and 45deg.
  1288. // The Body 2 is rotated by 90deg around Axis1 and
  1289. // Body1 is moved at X=100
  1290. //
  1291. //
  1292. ////////////////////////////////////////////////////////////////////////////////
  1293. TEST_FIXTURE(PUGetInfo1_Fixture_2, test3_PUGetInfo1)
  1294. {
  1295. dJointSetPUParam(jId, dParamLoStop1, -M_PI/4.0);
  1296. dJointSetPUParam(jId, dParamHiStop1, M_PI/4.0);
  1297. dJointSetPUParam(jId, dParamLoStop2, -M_PI/4.0);
  1298. dJointSetPUParam(jId, dParamHiStop2, M_PI/4.0);
  1299. dJointSetPUParam(jId, dParamLoStop3, -10);
  1300. dJointSetPUParam(jId, dParamHiStop3, 10);
  1301. dBodySetPosition (bId1, REAL(100.0), REAL(0.0), REAL(0.0));
  1302. dMatrix3 R;
  1303. dBodySetPosition (bId2, 0, 0, 1);
  1304. dRFromAxisAndAngle (R, 0, 1, 0, M_PI/2.0);
  1305. dBodySetRotation (bId2, R);
  1306. joint->getInfo1(&info);
  1307. CHECK_EQUAL(1, joint->limot1.limit);
  1308. CHECK_EQUAL(0, joint->limot2.limit);
  1309. CHECK_EQUAL(2, joint->limotP.limit);
  1310. CHECK_EQUAL(5, info.m);
  1311. // Reset Position and test
  1312. dBodySetPosition(bId1, 3, 0, 0);
  1313. dBodySetPosition(bId2, 1, 0, 0);
  1314. dMatrix3 R_final = { 1,0,0,0,
  1315. 0,1,0,0,
  1316. 0,0,1,0
  1317. };
  1318. dBodySetRotation (bId2, R_final);
  1319. joint->getInfo1(&info);
  1320. CHECK_EQUAL(0, joint->limot1.limit);
  1321. CHECK_EQUAL(0, joint->limot2.limit);
  1322. CHECK_EQUAL(0, joint->limotP.limit);
  1323. CHECK_EQUAL(4, info.m);
  1324. }
  1325. TEST_FIXTURE(PUGetInfo1_Fixture_2, test_SetPUParam)
  1326. {
  1327. dJointSetPUParam(jId, dParamHiStop, REAL(5.0) );
  1328. CHECK_EQUAL(REAL(5.0), joint->limot1.histop);
  1329. dJointSetPUParam(jId, dParamVel, REAL(7.0) );
  1330. CHECK_EQUAL(REAL(7.0), joint->limot1.vel);
  1331. #ifdef dParamFudgeFactor1
  1332. dJointSetPUParam(jId, dParamFudgeFactor1, REAL(5.5) );
  1333. CHECK_EQUAL(REAL(5.5), joint->limot1.dParamFudgeFactor);
  1334. #endif
  1335. dJointSetPUParam(jId, dParamCFM2, REAL(9.0) );
  1336. CHECK_EQUAL(REAL(9.0), joint->limot2.normal_cfm);
  1337. dJointSetPUParam(jId, dParamStopERP2, REAL(11.0) );
  1338. CHECK_EQUAL(REAL(11.0), joint->limot2.stop_erp);
  1339. dJointSetPUParam(jId, dParamBounce3, REAL(13.0) );
  1340. CHECK_EQUAL(REAL(13.0), joint->limotP.bounce);
  1341. }
  1342. TEST_FIXTURE(PUGetInfo1_Fixture_1, test_GetPUParam)
  1343. {
  1344. joint->limotP.histop = REAL(5.0);
  1345. CHECK_EQUAL(joint->limot1.histop,
  1346. dJointGetPUParam(jId, dParamHiStop) );
  1347. joint->limotP.vel = REAL(7.0);
  1348. CHECK_EQUAL(joint->limot1.vel,
  1349. dJointGetPUParam(jId, dParamVel) );
  1350. #ifdef dParamFudgeFactor1
  1351. joint->limotP.dParamFudgeFactor = REAL(5.5);
  1352. CHECK_EQUAL(joint->limot1.dParamFudgeFactor,
  1353. dJointGetPUParam(jId, dParamFudgeFactor1) );
  1354. #endif
  1355. joint->limot2.normal_cfm = REAL(9.0);
  1356. CHECK_EQUAL(joint->limot2.normal_cfm,
  1357. dJointGetPUParam(jId, dParamCFM2) );
  1358. joint->limot2.stop_erp = REAL(11.0);
  1359. CHECK_EQUAL(joint->limot2.stop_erp,
  1360. dJointGetPUParam(jId, dParamStopERP2) );
  1361. joint->limotP.bounce = REAL(13.0);
  1362. CHECK_EQUAL(joint->limotP.bounce,
  1363. dJointGetPUParam(jId, dParamBounce3) );
  1364. }
  1365. ////////////////////////////////////////////////////////////////////////////////
  1366. // Texture for testing the PositionRate
  1367. //
  1368. // Default Position:
  1369. // Position Body1 (3, 0, 0)
  1370. // Position Body2 (1, 0, 0)
  1371. // Angchor (2, 0, 0)
  1372. // Axis1 (0, 1, 0)
  1373. // Axis2 (0, 0, 1)
  1374. // AxisP1 (1, 0, 0)
  1375. //
  1376. // Default velocity:
  1377. // Body 1 lvel=( 0, 0, 0) avel=( 0, 0, 0)
  1378. // Body 2 lvel=( 0, 0, 0) avel=( 0, 0, 0)
  1379. //
  1380. //
  1381. // Y ^ Axis2
  1382. // ^ |
  1383. // / | ^ Axis1
  1384. // Z^ / | /
  1385. // | / Body 2 | / Body 1
  1386. // | / +---------+ | / +-----------+
  1387. // | / / /| | / / /|
  1388. // | / / / + _/ - / / +
  1389. // | / / /-/--------(_)----|--- /-----------/-------> AxisP
  1390. // | / +---------+ / - +-----------+ /
  1391. // | / | |/ | |/
  1392. // | / +---------+ +-----------+
  1393. // |/
  1394. // .-----------------------------------------> X
  1395. // |----------------->
  1396. // Anchor2 <--------------|
  1397. // Anchor1
  1398. //
  1399. ////////////////////////////////////////////////////////////////////////////////
  1400. struct PUGetInfo1_Fixture_3
  1401. {
  1402. PUGetInfo1_Fixture_3()
  1403. {
  1404. wId = dWorldCreate();
  1405. bId1 = dBodyCreate(wId);
  1406. dBodySetPosition(bId1, 3, 0, 0);
  1407. bId2 = dBodyCreate(wId);
  1408. dBodySetPosition(bId2, 1, 0, 0);
  1409. jId = dJointCreatePU(wId, 0);
  1410. joint = (dxJointPU*)jId;
  1411. dJointAttach(jId, bId1, bId2);
  1412. dJointSetPUAnchor (jId, 2, 0, 0);
  1413. dBodySetLinearVel (bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  1414. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  1415. dBodySetLinearVel (bId2, REAL(0.0), REAL(0.0), REAL(0.0));
  1416. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  1417. }
  1418. ~PUGetInfo1_Fixture_3()
  1419. {
  1420. dWorldDestroy(wId);
  1421. }
  1422. dJointID jId;
  1423. dxJointPU* joint;
  1424. dWorldID wId;
  1425. dBodyID bId1;
  1426. dBodyID bId2;
  1427. dxJoint::Info1 info;
  1428. };
  1429. ////////////////////////////////////////////////////////////////////////////////
  1430. // Position Body1 [3, 0, 0]
  1431. // Position Body2 [1, 0, 0]
  1432. // Axis of the prismatic [1, 0, 0]
  1433. // Axis1 [0, 1, 0]
  1434. // Axis2 [0, 0, 1]
  1435. //
  1436. // Move at the same speed
  1437. ////////////////////////////////////////////////////////////////////////////////
  1438. TEST_FIXTURE(PUGetInfo1_Fixture_3, test1_GetPUPositionRate)
  1439. {
  1440. // They move with the same linear speed
  1441. // Angular speed == 0
  1442. dBodySetLinearVel(bId1, REAL(0.0), REAL(3.33), REAL(0.0));
  1443. dBodySetLinearVel(bId2, REAL(0.0), REAL(3.33), REAL(0.0));
  1444. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1445. dBodySetLinearVel(bId1, REAL(1.11), REAL(3.33), REAL(0.0));
  1446. dBodySetLinearVel(bId2, REAL(1.11), REAL(3.33), REAL(0.0));
  1447. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1448. dBodySetLinearVel(bId1, REAL(1.11), REAL(3.33), REAL(2.22));
  1449. dBodySetLinearVel(bId2, REAL(1.11), REAL(3.33), REAL(2.22));
  1450. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1451. // Reset for the next set of test.
  1452. dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  1453. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  1454. dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(0.0));
  1455. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  1456. // They move with the same angular speed
  1457. // linear speed == 0
  1458. dBodySetAngularVel(bId1, REAL(1.22), REAL(0.0), REAL(0.0));
  1459. dBodySetAngularVel(bId2, REAL(1.22), REAL(0.0), REAL(0.0));
  1460. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1461. dBodySetAngularVel(bId1, REAL(1.22), REAL(2.33), REAL(0.0));
  1462. dBodySetAngularVel(bId2, REAL(1.22), REAL(2.33), REAL(0.0));
  1463. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1464. dBodySetAngularVel(bId1, REAL(1.22), REAL(2.33), REAL(3.44));
  1465. dBodySetAngularVel(bId2, REAL(1.22), REAL(2.33), REAL(3.44));
  1466. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1467. }
  1468. ////////////////////////////////////////////////////////////////////////////////
  1469. // Position Body1 [3, 0, 0]
  1470. // Position Body2 [1, 0, 0]
  1471. // Axis of the prismatic [1, 0, 0]
  1472. // Axis1 [0, 1, 0]
  1473. // Axis2 [0, 0, 1]
  1474. //
  1475. // Only the first body moves
  1476. ////////////////////////////////////////////////////////////////////////////////
  1477. TEST_FIXTURE(PUGetInfo1_Fixture_3, GetPUPositionRate_Bodies_in_line_B1_moves)
  1478. {
  1479. dBodySetLinearVel(bId1, REAL(3.33), REAL(0.0), REAL(0.0)); // This is impossible but ...
  1480. CHECK_EQUAL(REAL(3.33), dJointGetPUPositionRate (jId) );
  1481. dBodySetLinearVel(bId1, REAL(0.0), REAL(3.33), REAL(0.0));
  1482. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1483. dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(3.33)); // This is impossible but ...
  1484. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1485. // Only the first body as angular velocity
  1486. dBodySetAngularVel(bId1, REAL(1.22), REAL(0.0), REAL(0.0));
  1487. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1488. dBodySetAngularVel(bId1, REAL(0.0), REAL(2.33), REAL(0.0));
  1489. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1490. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(5.55));
  1491. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1492. }
  1493. ////////////////////////////////////////////////////////////////////////////////
  1494. // Position Body1 [3, 0, 0]
  1495. // Position Body2 [1, 0, 0]
  1496. // Axis of the prismatic [1, 0, 0]
  1497. // Axis1 [0, 1, 0]
  1498. // Axis2 [0, 0, 1]
  1499. //
  1500. // Only the second body moves
  1501. ////////////////////////////////////////////////////////////////////////////////
  1502. TEST_FIXTURE(PUGetInfo1_Fixture_3, GetPUPositionRate_Bodies_in_line_B2_moves)
  1503. {
  1504. // The length was at zero and this will give an negative length
  1505. dBodySetLinearVel(bId2, REAL(3.33), REAL(0.0), REAL(0.0));
  1506. CHECK_EQUAL(REAL(-3.33), dJointGetPUPositionRate (jId) );
  1507. dBodySetLinearVel(bId2, REAL(0.0), REAL(3.33), REAL(0.0)); // This is impossible but ...
  1508. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1509. dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(3.33)); // This is impossible but ...
  1510. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1511. // Only angular velocity
  1512. dBodySetAngularVel(bId2, REAL(1.22), REAL(0.0), REAL(0.0));
  1513. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1514. dBodySetAngularVel(bId2, REAL(0.0), REAL(2.33), REAL(0.0));
  1515. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1516. dBodySetAngularVel(bId2, REAL(0.0), REAL(0.0), REAL(5.55));
  1517. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1518. }
  1519. ////////////////////////////////////////////////////////////////////////////////
  1520. // Fixture for testing the PositionRate
  1521. //
  1522. // Default Position:
  1523. // Position Body1 (3, 0, 0)
  1524. // Position Body2 (0, 0, 1)
  1525. // Angchor (2, 0, 0)
  1526. // Axis1 (0, 1, 0)
  1527. // Axis2 (1, 0, 0)
  1528. // AxisP (1, 0, 0)
  1529. //
  1530. // The second body is at 90deg w.r.t. the first body
  1531. //
  1532. //
  1533. // Default Position
  1534. // ^Z
  1535. // |
  1536. // |
  1537. //
  1538. // +---+
  1539. // | |Body2
  1540. // | |
  1541. // | |
  1542. // +---+
  1543. // | ^ Axis1
  1544. // | /
  1545. // | /
  1546. // | / Body1
  1547. // R _ - +-----------+
  1548. // (_)----|-----| | ----->X AxisP, Axis2
  1549. // - +-----------+
  1550. //
  1551. // N.B. Y is going into the page
  1552. ////////////////////////////////////////////////////////////////////////////////
  1553. struct PUGetInfo1_Fixture_4
  1554. {
  1555. PUGetInfo1_Fixture_4()
  1556. {
  1557. wId = dWorldCreate();
  1558. bId1 = dBodyCreate(wId);
  1559. dBodySetPosition(bId1, 3, 0, 0);
  1560. bId2 = dBodyCreate(wId);
  1561. dBodySetPosition(bId2, 0, 0, 1);
  1562. dMatrix3 R;
  1563. dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0);
  1564. dBodySetRotation (bId2, R);
  1565. jId = dJointCreatePU(wId, 0);
  1566. joint = (dxJointPU*)jId;
  1567. dJointAttach(jId, bId1, bId2);
  1568. dJointSetPUAnchor (jId, 2, 0, 0);
  1569. dJointSetPUAxis1 (jId, 0, 1, 0);
  1570. dJointSetPUAxis2 (jId, 1, 0, 0);
  1571. dJointSetPUAxisP (jId, 1, 0, 0);
  1572. dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  1573. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  1574. dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(0.0));
  1575. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  1576. }
  1577. ~PUGetInfo1_Fixture_4()
  1578. {
  1579. dWorldDestroy(wId);
  1580. }
  1581. dJointID jId;
  1582. dxJointPU* joint;
  1583. dWorldID wId;
  1584. dBodyID bId1;
  1585. dBodyID bId2;
  1586. dxJoint::Info1 info;
  1587. };
  1588. ////////////////////////////////////////////////////////////////////////////////
  1589. // Position Body1 (3, 0, 0)
  1590. // Position Body2 (1, 0, 0)
  1591. // Angchor (2, 0, 0)
  1592. // Axis1 (0, 1, 0)
  1593. // Axis2 (0, 0, 1)
  1594. // AxisP1 (1, 0, 0)
  1595. //
  1596. // Only the first body moves
  1597. ////////////////////////////////////////////////////////////////////////////////
  1598. TEST_FIXTURE(PUGetInfo1_Fixture_4, GetPUPositionRate_Bodies_at90deg_B1_moves)
  1599. {
  1600. dBodySetLinearVel(bId1, REAL(3.33), REAL(0.0), REAL(0.0)); // This is impossible but ...
  1601. CHECK_EQUAL(REAL(3.33), dJointGetPUPositionRate (jId) );
  1602. dBodySetLinearVel(bId1, REAL(0.0), REAL(3.33), REAL(0.0));
  1603. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1604. dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(3.33)); // This is impossible but ...
  1605. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1606. // Only angular velocity
  1607. dBodySetAngularVel(bId1, REAL(1.22), REAL(0.0), REAL(0.0));
  1608. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1609. dBodySetAngularVel(bId1, REAL(0.0), REAL(2.33), REAL(0.0));
  1610. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1611. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(5.55));
  1612. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1613. }
  1614. ////////////////////////////////////////////////////////////////////////////////
  1615. // Position Body1 (3, 0, 0)
  1616. // Position Body2 (1, 0, 0)
  1617. // Angchor (2, 0, 0)
  1618. // Axis1 (0, 1, 0)
  1619. // Axis2 (0, 0, 1)
  1620. // AxisP1 (1, 0, 0)
  1621. //
  1622. // Only the second body moves
  1623. ////////////////////////////////////////////////////////////////////////////////
  1624. TEST_FIXTURE(PUGetInfo1_Fixture_4, GetPUPositionRate_Bodies_at90deg_B2_moves)
  1625. {
  1626. // The length was at zero and this will give an negative length
  1627. dBodySetLinearVel(bId2, REAL(3.33), REAL(0.0), REAL(0.0));
  1628. CHECK_EQUAL(REAL(-3.33), dJointGetPUPositionRate (jId) );
  1629. dBodySetLinearVel(bId2, REAL(0.0), REAL(3.33), REAL(0.0)); // This is impossible but ...
  1630. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1631. dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(3.33)); // This is impossible but ...
  1632. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1633. // Only angular velocity
  1634. dBodySetAngularVel(bId2, REAL(1.22), REAL(0.0), REAL(0.0));
  1635. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1636. dBodySetAngularVel(bId2, REAL(0.0), REAL(2.33), REAL(0.0));
  1637. CHECK_EQUAL(REAL(-1.0*2.330), dJointGetPUPositionRate (jId) );
  1638. dBodySetAngularVel(bId2, REAL(0.0), REAL(0.0), REAL(5.55));
  1639. CHECK_EQUAL(REAL(0.0), dJointGetPUPositionRate (jId) );
  1640. }
  1641. } // End of SUITE(JointPU)
  1642. // =============================================================================
  1643. // =============================================================================
  1644. //
  1645. // Testing the Piston Joint
  1646. //
  1647. // =============================================================================
  1648. // =============================================================================
  1649. ////////////////////////////////////////////////////////////////////////////////
  1650. // Default Position:
  1651. // Position Body1 (1, 0, 0)
  1652. // Position Body2 (3, 0, 0)
  1653. // Angchor (2, 0, 0)
  1654. // AxisR (0, 1, 0)
  1655. // Axis2 (0, 0, 1)
  1656. // AxisP1 (1, 0, 0)
  1657. //
  1658. /// <PRE>
  1659. ///^Z |- Anchor point
  1660. /// | Body_1 | Body_2
  1661. /// | +---------------+ V +------------------+
  1662. /// | / /| / /|
  1663. /// | / / + |-- ______ / / +
  1664. /// .- / x /./........x.......(_____()..../ x /.......> axis
  1665. /// +---------------+ / |-- +------------------+ / X
  1666. /// | |/ | |/
  1667. /// +---------------+ +------------------+
  1668. /// | |
  1669. /// | |
  1670. /// |------------------> <----------------------------|
  1671. /// anchor1 anchor2
  1672. ///
  1673. ///
  1674. /// Axis Y is going into the page
  1675. ////////////////////////////////////////////////////////////////////////////////
  1676. SUITE(JointPiston)
  1677. {
  1678. struct PistonGetInfo1_Fixture_1
  1679. {
  1680. PistonGetInfo1_Fixture_1()
  1681. {
  1682. wId = dWorldCreate();
  1683. bId1 = dBodyCreate(wId);
  1684. dBodySetPosition(bId1, 1, 0, 0);
  1685. bId2 = dBodyCreate(wId);
  1686. dBodySetPosition(bId2, 3, 0, 0);
  1687. jId = dJointCreatePiston(wId, 0);
  1688. joint = (dxJointPiston*)jId;
  1689. dJointAttach(jId, bId1, bId2);
  1690. dJointSetPistonAnchor (jId, 2, 0, 0);
  1691. }
  1692. ~PistonGetInfo1_Fixture_1()
  1693. {
  1694. dWorldDestroy(wId);
  1695. }
  1696. dJointID jId;
  1697. dxJointPiston* joint;
  1698. dWorldID wId;
  1699. dBodyID bId1;
  1700. dBodyID bId2;
  1701. dxJoint::Info1 info;
  1702. };
  1703. ////////////////////////////////////////////////////////////////////////////////
  1704. // Test when there is no limits.
  1705. // The 2 bodies stay aligned.
  1706. //
  1707. ////////////////////////////////////////////////////////////////////////////////
  1708. TEST_FIXTURE(PistonGetInfo1_Fixture_1, test1_SetPistonParam)
  1709. {
  1710. dJointSetPistonParam(jId, dParamLoStop1, -dInfinity);
  1711. dJointSetPistonParam(jId, dParamHiStop1, dInfinity);
  1712. dJointSetPistonParam(jId, dParamLoStop2, -M_PI);
  1713. dJointSetPistonParam(jId, dParamHiStop2 , M_PI);
  1714. joint->getInfo1(&info);
  1715. CHECK_EQUAL(0, joint->limotP.limit);
  1716. CHECK_EQUAL(0, joint->limotR.limit);
  1717. CHECK_EQUAL(4, info.m);
  1718. }
  1719. ////////////////////////////////////////////////////////////////////////////////
  1720. // Test when there is limits for the prismatic at -10 and 10
  1721. // The Body 2 is moved -100 unit then at 100
  1722. //
  1723. // Default value for axisR1 = 1,0,0
  1724. // Default value for axisP1 = 0,1,0
  1725. ////////////////////////////////////////////////////////////////////////////////
  1726. TEST_FIXTURE(PistonGetInfo1_Fixture_1, test1_GetPistonParam)
  1727. {
  1728. dJointSetPistonParam(jId, dParamLoStop1, -10);
  1729. dJointSetPistonParam(jId, dParamHiStop1, 10);
  1730. dBodySetPosition(bId2, REAL(-100.0), REAL(0.0), REAL(0.0));
  1731. joint->getInfo1(&info);
  1732. CHECK_EQUAL(2, joint->limotP.limit);
  1733. CHECK_EQUAL(0, joint->limotR.limit);
  1734. CHECK_EQUAL(5, info.m);
  1735. dBodySetPosition(bId2, REAL(100.0), REAL(0.0), REAL(0.0));
  1736. joint->getInfo1(&info);
  1737. CHECK_EQUAL(0, joint->limotR.limit);
  1738. CHECK_EQUAL(1, joint->limotP.limit);
  1739. CHECK_EQUAL(5, info.m);
  1740. // Reset Position and test
  1741. dBodySetPosition(bId2, 1, 0, 0);
  1742. dMatrix3 R_final = { 1,0,0,0,
  1743. 0,1,0,0,
  1744. 0,0,1,0
  1745. };
  1746. dBodySetRotation (bId2, R_final);
  1747. joint->getInfo1(&info);
  1748. CHECK_EQUAL(0, joint->limotR.limit);
  1749. CHECK_EQUAL(0, joint->limotP.limit);
  1750. CHECK_EQUAL(4, info.m);
  1751. }
  1752. ////////////////////////////////////////////////////////////////////////////////
  1753. // Test when there is limits for the prismatic at -10 and 10
  1754. // and the rotoide at -45deg and 45deg.
  1755. // The Body 2 is rotated by 90deg around the axis
  1756. //
  1757. //
  1758. ////////////////////////////////////////////////////////////////////////////////
  1759. TEST_FIXTURE(PistonGetInfo1_Fixture_1, test2_PistonGetInfo1)
  1760. {
  1761. dJointSetPistonParam(jId, dParamLoStop1, -10);
  1762. dJointSetPistonParam(jId, dParamHiStop1, 10);
  1763. dJointSetPistonParam(jId, dParamLoStop2, -M_PI/4.0);
  1764. dJointSetPistonParam(jId, dParamHiStop2, M_PI/4.0);
  1765. dMatrix3 R;
  1766. dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0);
  1767. dBodySetRotation (bId2, R);
  1768. joint->getInfo1(&info);
  1769. CHECK_EQUAL(1, joint->limotR.limit);
  1770. CHECK_EQUAL(0, joint->limotP.limit);
  1771. CHECK_EQUAL(5, info.m);
  1772. // Reset Position and test
  1773. dMatrix3 R_final = { 1,0,0,0,
  1774. 0,1,0,0,
  1775. 0,0,1,0
  1776. };
  1777. dBodySetRotation (bId2, R_final);
  1778. joint->getInfo1(&info);
  1779. CHECK_EQUAL(0, joint->limotR.limit);
  1780. CHECK_EQUAL(0, joint->limotP.limit);
  1781. CHECK_EQUAL(4, info.m);
  1782. }
  1783. ////////////////////////////////////////////////////////////////////////////////
  1784. // Test when there is limits for the prismatic at -10 and 10
  1785. // and for rotoide at -45deg and 45deg.
  1786. // The Body 2 is rotated by 90deg around the axis
  1787. // Body1 is moved at X=100
  1788. //
  1789. //
  1790. ////////////////////////////////////////////////////////////////////////////////
  1791. TEST_FIXTURE(PistonGetInfo1_Fixture_1, test3_PistonGetInfo1)
  1792. {
  1793. dJointSetPistonParam(jId, dParamLoStop1, -10);
  1794. dJointSetPistonParam(jId, dParamHiStop1, 10);
  1795. dJointSetPistonParam(jId, dParamLoStop2, -M_PI/4.0);
  1796. dJointSetPistonParam(jId, dParamHiStop2, M_PI/4.0);
  1797. dBodySetPosition (bId1, REAL(100.0), REAL(0.0), REAL(0.0));
  1798. dMatrix3 R;
  1799. dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0);
  1800. dBodySetRotation (bId2, R);
  1801. joint->getInfo1(&info);
  1802. CHECK_EQUAL(2, joint->limotP.limit);
  1803. CHECK_EQUAL(1, joint->limotR.limit);
  1804. CHECK_EQUAL(6, info.m);
  1805. // Reset Position and test
  1806. dBodySetPosition(bId1, 1, 0, 0);
  1807. dMatrix3 R_final = { 1,0,0,0,
  1808. 0,1,0,0,
  1809. 0,0,1,0
  1810. };
  1811. dBodySetRotation (bId2, R_final);
  1812. joint->getInfo1(&info);
  1813. CHECK_EQUAL(0, joint->limotP.limit);
  1814. CHECK_EQUAL(0, joint->limotR.limit);
  1815. CHECK_EQUAL(4, info.m);
  1816. }
  1817. ////////////////////////////////////////////////////////////////////////////////
  1818. // Default Position:
  1819. // Position Body1 (1, 0, 0)
  1820. // Position Body2 (3, 0, 0)
  1821. // Angchor (2, 0, 0)
  1822. // AxisR (0, 1, 0)
  1823. // Axis2 (0, 0, 1)
  1824. // AxisP1 (1, 0, 0)
  1825. //
  1826. // The motor on axis1 is now powered. (i.e. joint->limot1->fmax > 0
  1827. //
  1828. /// <PRE>
  1829. ///^Z |- Anchor point
  1830. /// | Body_1 | Body_2
  1831. /// | +---------------+ V +------------------+
  1832. /// | / /| / /|
  1833. /// | / / + |-- ______ / / +
  1834. /// .- / x /./........x.......(_____()..../ x /.......> axis
  1835. /// +---------------+ / |-- +------------------+ / X
  1836. /// | |/ | |/
  1837. /// +---------------+ +------------------+
  1838. /// | |
  1839. /// | |
  1840. /// |------------------> <----------------------------|
  1841. /// anchor1 anchor2
  1842. ///
  1843. ///
  1844. /// Axis Y is going into the page
  1845. ////////////////////////////////////////////////////////////////////////////////
  1846. struct PistonGetInfo1_Fixture_2
  1847. {
  1848. PistonGetInfo1_Fixture_2()
  1849. {
  1850. wId = dWorldCreate();
  1851. bId1 = dBodyCreate(wId);
  1852. dBodySetPosition(bId1, 1, 0, 0);
  1853. bId2 = dBodyCreate(wId);
  1854. dBodySetPosition(bId2, 3, 0, 0);
  1855. jId = dJointCreatePiston(wId, 0);
  1856. joint = (dxJointPiston*)jId;
  1857. dJointAttach(jId, bId1, bId2);
  1858. dJointSetPistonAnchor (jId, 2, 0, 0);
  1859. joint->limotP.fmax = 1;
  1860. }
  1861. ~PistonGetInfo1_Fixture_2()
  1862. {
  1863. dWorldDestroy(wId);
  1864. }
  1865. dJointID jId;
  1866. dxJointPiston* joint;
  1867. dWorldID wId;
  1868. dBodyID bId1;
  1869. dBodyID bId2;
  1870. dxJoint::Info1 info;
  1871. };
  1872. ////////////////////////////////////////////////////////////////////////////////
  1873. // Test when there is no limits.
  1874. // The 2 bodies stay aligned.
  1875. //
  1876. ////////////////////////////////////////////////////////////////////////////////
  1877. TEST_FIXTURE(PistonGetInfo1_Fixture_2, test0_PistonGetInfo1)
  1878. {
  1879. dJointSetPistonParam(jId, dParamLoStop1, -dInfinity);
  1880. dJointSetPistonParam(jId, dParamHiStop1, dInfinity);
  1881. dJointSetPistonParam(jId, dParamLoStop2, -M_PI);
  1882. dJointSetPistonParam(jId, dParamHiStop2, M_PI);
  1883. joint->getInfo1(&info);
  1884. CHECK_EQUAL(0, joint->limotP.limit);
  1885. CHECK_EQUAL(0, joint->limotR.limit);
  1886. CHECK_EQUAL(5, info.m);
  1887. }
  1888. ////////////////////////////////////////////////////////////////////////////////
  1889. // Test when there is limits for the prismatic at -10 and 10
  1890. // The Body 2 is moved -100 unit then at 100
  1891. //
  1892. // Default value for axis = 1,0,0
  1893. ////////////////////////////////////////////////////////////////////////////////
  1894. TEST_FIXTURE(PistonGetInfo1_Fixture_2, test1_PistonGetInfo1)
  1895. {
  1896. dJointSetPistonParam(jId, dParamLoStop1, -10);
  1897. dJointSetPistonParam(jId, dParamHiStop1, 10);
  1898. dBodySetPosition(bId2, REAL(-100.0), REAL(0.0), REAL(0.0));
  1899. joint->getInfo1(&info);
  1900. CHECK_EQUAL(2, joint->limotP.limit);
  1901. CHECK_EQUAL(0, joint->limotR.limit);
  1902. CHECK_EQUAL(5, info.m);
  1903. dBodySetPosition(bId2, REAL(100.0), REAL(0.0), REAL(0.0));
  1904. joint->getInfo1(&info);
  1905. CHECK_EQUAL(1, joint->limotP.limit);
  1906. CHECK_EQUAL(0, joint->limotR.limit);
  1907. CHECK_EQUAL(5, info.m);
  1908. // Reset Position and test
  1909. dBodySetPosition(bId2, 3, 0, 0);
  1910. dMatrix3 R_final = { 1,0,0,0,
  1911. 0,1,0,0,
  1912. 0,0,1,0
  1913. };
  1914. dBodySetRotation (bId2, R_final);
  1915. joint->getInfo1(&info);
  1916. CHECK_EQUAL(0, joint->limotP.limit);
  1917. CHECK_EQUAL(0, joint->limotR.limit);
  1918. CHECK_EQUAL(5, info.m);
  1919. }
  1920. ////////////////////////////////////////////////////////////////////////////////
  1921. // Test when there is limits for the prismatic at -10 and 10
  1922. // and for the rotoide at -45deg and 45deg.
  1923. // The Body 2 is rotated by 90deg around the axis
  1924. //
  1925. //
  1926. ////////////////////////////////////////////////////////////////////////////////
  1927. TEST_FIXTURE(PistonGetInfo1_Fixture_2, test2_PistonGetInfo1)
  1928. {
  1929. dJointSetPistonParam(jId, dParamLoStop1, -10);
  1930. dJointSetPistonParam(jId, dParamHiStop1, 10);
  1931. dJointSetPistonParam(jId, dParamLoStop2, -M_PI/4.0);
  1932. dJointSetPistonParam(jId, dParamHiStop2, M_PI/4.0);
  1933. dMatrix3 R;
  1934. dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0);
  1935. dBodySetRotation (bId2, R);
  1936. joint->getInfo1(&info);
  1937. CHECK_EQUAL(0, joint->limotP.limit);
  1938. CHECK_EQUAL(1, joint->limotR.limit);
  1939. CHECK_EQUAL(6, info.m);
  1940. // Reset Position and test
  1941. dMatrix3 R_final = { 1,0,0,0,
  1942. 0,1,0,0,
  1943. 0,0,1,0
  1944. };
  1945. dBodySetRotation (bId2, R_final);
  1946. joint->getInfo1(&info);
  1947. CHECK_EQUAL(0, joint->limotP.limit);
  1948. CHECK_EQUAL(0, joint->limotR.limit);
  1949. CHECK_EQUAL(5, info.m);
  1950. }
  1951. ////////////////////////////////////////////////////////////////////////////////
  1952. // Test when there is limits for the prismatic at -10 and 10
  1953. // and for the rotoide axuis at -45deg and 45deg.
  1954. // The Body 2 is rotated by 90deg around the axis and
  1955. // Body1 is moved at X=100
  1956. //
  1957. //
  1958. ////////////////////////////////////////////////////////////////////////////////
  1959. TEST_FIXTURE(PistonGetInfo1_Fixture_2, test3_PistonGetInfo1)
  1960. {
  1961. dJointSetPistonParam(jId, dParamLoStop1, -10);
  1962. dJointSetPistonParam(jId, dParamHiStop1, 10);
  1963. dJointSetPistonParam(jId, dParamLoStop2, -M_PI/4.0);
  1964. dJointSetPistonParam(jId, dParamHiStop2, M_PI/4.0);
  1965. dBodySetPosition (bId1, REAL(100.0), REAL(0.0), REAL(0.0));
  1966. dMatrix3 R;
  1967. dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0);
  1968. dBodySetRotation (bId2, R);
  1969. joint->getInfo1(&info);
  1970. CHECK_EQUAL(2, joint->limotP.limit);
  1971. CHECK_EQUAL(1, joint->limotR.limit);
  1972. CHECK_EQUAL(6, info.m);
  1973. // Reset Position and test
  1974. dBodySetPosition(bId1, 1, 0, 0);
  1975. dBodySetPosition(bId2, 3, 0, 0);
  1976. dMatrix3 R_final = { 1,0,0,0,
  1977. 0,1,0,0,
  1978. 0,0,1,0
  1979. };
  1980. dBodySetRotation (bId2, R_final);
  1981. joint->getInfo1(&info);
  1982. CHECK_EQUAL(0, joint->limotP.limit);
  1983. CHECK_EQUAL(0, joint->limotR.limit);
  1984. CHECK_EQUAL(5, info.m);
  1985. }
  1986. TEST_FIXTURE(PistonGetInfo1_Fixture_2, test_SetPistonParam)
  1987. {
  1988. dJointSetPistonParam(jId, dParamHiStop, REAL(5.0) );
  1989. CHECK_EQUAL(REAL(5.0), joint->limotP.histop);
  1990. dJointSetPistonParam(jId, dParamVel, REAL(7.0) );
  1991. CHECK_EQUAL(REAL(7.0), joint->limotP.vel);
  1992. #ifdef dParamFudgeFactor1
  1993. dJointSetPistonParam(jId, dParamFudgeFactor1, REAL(5.5) );
  1994. CHECK_EQUAL(REAL(5.5), joint->limotP.dParamFudgeFactor);
  1995. #endif
  1996. dJointSetPistonParam(jId, dParamCFM2, REAL(9.0) );
  1997. CHECK_EQUAL(REAL(9.0), joint->limotR.normal_cfm);
  1998. dJointSetPistonParam(jId, dParamStopERP2, REAL(11.0) );
  1999. CHECK_EQUAL(REAL(11.0), joint->limotR.stop_erp);
  2000. }
  2001. TEST_FIXTURE(PistonGetInfo1_Fixture_1, test_GetPistonParam)
  2002. {
  2003. joint->limotP.histop = REAL(5.0);
  2004. CHECK_EQUAL(joint->limotP.histop,
  2005. dJointGetPistonParam(jId, dParamHiStop) );
  2006. joint->limotP.vel = REAL(7.0);
  2007. CHECK_EQUAL(joint->limotP.vel,
  2008. dJointGetPistonParam(jId, dParamVel) );
  2009. #ifdef dParamFudgeFactor1
  2010. joint->limotP.dParamFudgeFactor = REAL(5.5);
  2011. CHECK_EQUAL(joint->limotP.dParamFudgeFactor,
  2012. dJointGetPistonParam(jId, dParamFudgeFactor1) );
  2013. #endif
  2014. joint->limotR.normal_cfm = REAL(9.0);
  2015. CHECK_EQUAL(joint->limotR.normal_cfm,
  2016. dJointGetPistonParam(jId, dParamCFM2) );
  2017. joint->limotR.stop_erp = REAL(11.0);
  2018. CHECK_EQUAL(joint->limotR.stop_erp,
  2019. dJointGetPistonParam(jId, dParamStopERP2) );
  2020. }
  2021. ////////////////////////////////////////////////////////////////////////////////
  2022. // Texture for testing the PositionRate
  2023. //
  2024. // Default Position:
  2025. // Position Body1 (3, 0, 0)
  2026. // Position Body2 (1, 0, 0)
  2027. // Angchor (2, 0, 0)
  2028. // Axis1 (0, 1, 0)
  2029. // Axis2 (0, 0, 1)
  2030. // AxisP1 (1, 0, 0)
  2031. //
  2032. // Default velocity:
  2033. // Body 1 lvel=( 0, 0, 0) avel=( 0, 0, 0)
  2034. // Body 2 lvel=( 0, 0, 0) avel=( 0, 0, 0)
  2035. //
  2036. //
  2037. // Y ^ Axis2
  2038. // ^ |
  2039. // / | ^ Axis1
  2040. // Z^ / | /
  2041. // | / Body 2 | / Body 1
  2042. // | / +---------+ | / +-----------+
  2043. // | / / /| | / / /|
  2044. // | / / / + _/ - / / +
  2045. // | / / /-/--------(_)----|--- /-----------/-------> AxisP
  2046. // | / +---------+ / - +-----------+ /
  2047. // | / | |/ | |/
  2048. // | / +---------+ +-----------+
  2049. // |/
  2050. // .-----------------------------------------> X
  2051. // |----------------->
  2052. // Anchor2 <--------------|
  2053. // Anchor1
  2054. //
  2055. ////////////////////////////////////////////////////////////////////////////////
  2056. struct PistonGetInfo1_Fixture_3
  2057. {
  2058. PistonGetInfo1_Fixture_3()
  2059. {
  2060. wId = dWorldCreate();
  2061. bId1 = dBodyCreate(wId);
  2062. dBodySetPosition(bId1, 3, 0, 0);
  2063. bId2 = dBodyCreate(wId);
  2064. dBodySetPosition(bId2, 1, 0, 0);
  2065. jId = dJointCreatePiston(wId, 0);
  2066. joint = (dxJointPiston*)jId;
  2067. dJointAttach(jId, bId1, bId2);
  2068. dJointSetPistonAnchor (jId, 2, 0, 0);
  2069. dBodySetLinearVel (bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  2070. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  2071. dBodySetLinearVel (bId2, REAL(0.0), REAL(0.0), REAL(0.0));
  2072. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  2073. }
  2074. ~PistonGetInfo1_Fixture_3()
  2075. {
  2076. dWorldDestroy(wId);
  2077. }
  2078. dJointID jId;
  2079. dxJointPiston* joint;
  2080. dWorldID wId;
  2081. dBodyID bId1;
  2082. dBodyID bId2;
  2083. dxJoint::Info1 info;
  2084. };
  2085. ////////////////////////////////////////////////////////////////////////////////
  2086. // Position Body1 [3, 0, 0]
  2087. // Position Body2 [1, 0, 0]
  2088. // Axis of the prismatic [1, 0, 0]
  2089. // Axis1 [0, 1, 0]
  2090. // Axis2 [0, 0, 1]
  2091. //
  2092. // Move at the same speed
  2093. ////////////////////////////////////////////////////////////////////////////////
  2094. TEST_FIXTURE(PistonGetInfo1_Fixture_3, test1_GetPistonPositionRate)
  2095. {
  2096. // They move with the same linear speed
  2097. // Angular speed == 0
  2098. dBodySetLinearVel(bId1, 0, REAL(3.33), 0);
  2099. dBodySetLinearVel(bId2, 0, REAL(3.33), 0);
  2100. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2101. dBodySetLinearVel(bId1, REAL(1.11), REAL(3.33), 0);
  2102. dBodySetLinearVel(bId2, REAL(1.11), REAL(3.33), 0);
  2103. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2104. dBodySetLinearVel(bId1, REAL(1.11), REAL(3.33), REAL(2.22));
  2105. dBodySetLinearVel(bId2, REAL(1.11), REAL(3.33), REAL(2.22));
  2106. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2107. // Reset for the next set of test.
  2108. dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  2109. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  2110. dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(0.0));
  2111. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  2112. // They move with the same angular speed
  2113. // linear speed == 0
  2114. dBodySetAngularVel(bId1, REAL(1.22), 0.0, 0.0);
  2115. dBodySetAngularVel(bId2, REAL(1.22), 0.0, 0.0);
  2116. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2117. dBodySetAngularVel(bId1, REAL(1.22), REAL(2.33), 0.0);
  2118. dBodySetAngularVel(bId2, REAL(1.22), REAL(2.33), 0.0);
  2119. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2120. dBodySetAngularVel(bId1, REAL(1.22), REAL(2.33), REAL(3.44));
  2121. dBodySetAngularVel(bId2, REAL(1.22), REAL(2.33), REAL(3.44));
  2122. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2123. }
  2124. ////////////////////////////////////////////////////////////////////////////////
  2125. // Position Body1 [3, 0, 0]
  2126. // Position Body2 [1, 0, 0]
  2127. // Axis of the prismatic [1, 0, 0]
  2128. // Axis1 [0, 1, 0]
  2129. // Axis2 [0, 0, 1]
  2130. //
  2131. // Only the first body moves
  2132. ////////////////////////////////////////////////////////////////////////////////
  2133. TEST_FIXTURE(PistonGetInfo1_Fixture_3, GetPistonPositionRate_Bodies_in_line_B1_moves)
  2134. {
  2135. dBodySetLinearVel(bId1, REAL(3.33), 0.0, 0.0); // This is impossible but ...
  2136. CHECK_EQUAL(REAL(3.33), dJointGetPistonPositionRate (jId) );
  2137. dBodySetLinearVel(bId1, 0, REAL(3.33), 0);
  2138. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2139. dBodySetLinearVel(bId1, 0, 0, REAL(3.33)); // This is impossible but ...
  2140. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2141. // Only the first body as angular velocity
  2142. dBodySetAngularVel(bId1, REAL(1.22), 0.0, 0.0);
  2143. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2144. dBodySetAngularVel(bId1, 0.0, REAL(2.33), 0.0);
  2145. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2146. dBodySetAngularVel(bId1, 0.0, 0.0, REAL(5.55));
  2147. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2148. }
  2149. ////////////////////////////////////////////////////////////////////////////////
  2150. // Position Body1 [3, 0, 0]
  2151. // Position Body2 [1, 0, 0]
  2152. // Axis of the prismatic [1, 0, 0]
  2153. // Axis1 [0, 1, 0]
  2154. // Axis2 [0, 0, 1]
  2155. //
  2156. // Only the second body moves
  2157. ////////////////////////////////////////////////////////////////////////////////
  2158. TEST_FIXTURE(PistonGetInfo1_Fixture_3, GetPistonPositionRate_Bodies_in_line_B2_moves)
  2159. {
  2160. // The length was at zero and this will give an negative length
  2161. dBodySetLinearVel(bId2, REAL(3.33), 0.0, 0.0);
  2162. CHECK_EQUAL(REAL(-3.33), dJointGetPistonPositionRate (jId) );
  2163. dBodySetLinearVel(bId2, 0, REAL(3.33), 0); // This is impossible but ...
  2164. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2165. dBodySetLinearVel(bId2, 0, 0, REAL(3.33)); // This is impossible but ...
  2166. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2167. // Only angular velocity
  2168. dBodySetAngularVel(bId2, REAL(1.22), 0.0, 0.0);
  2169. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2170. dBodySetAngularVel(bId2, 0.0, REAL(2.33), 0.0);
  2171. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2172. dBodySetAngularVel(bId2, 0.0, 0.0, REAL(5.55));
  2173. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2174. }
  2175. ////////////////////////////////////////////////////////////////////////////////
  2176. // Fixture for testing the PositionRate
  2177. //
  2178. // Default Position:
  2179. // Position Body1 (3, 0, 0)
  2180. // Position Body2 (0, 0, 1)
  2181. // Angchor (2, 0, 0)
  2182. // Axis1 (0, 1, 0)
  2183. // Axis2 (1, 0, 0)
  2184. // AxisP (1, 0, 0)
  2185. //
  2186. // The second body is at 90deg w.r.t. the first body
  2187. // From
  2188. //
  2189. // Y ^ Axis2
  2190. // ^ |
  2191. // / | ^ Axis1
  2192. // Z^ / | /
  2193. // | / Body 2 | / Body 1
  2194. // | / +---------+ | / +-----------+
  2195. // | / / /| | / / /|
  2196. // | / / / + _/ - / / +
  2197. // | / / /-/--------(_)----|--- /-----------/-------> AxisP
  2198. // | / +---------+ / - +-----------+ /
  2199. // | / | |/ | |/
  2200. // | / +---------+ +-----------+
  2201. // |/
  2202. // .-----------------------------------------> X
  2203. // |----------------->
  2204. // Anchor2 <--------------|
  2205. // Anchor1
  2206. // To
  2207. //
  2208. // Y ^ Axis2
  2209. // ^ |
  2210. // / Body 2 | ^ Axis1
  2211. // Z^ +----------+ | /
  2212. // | // /| | / Body 1
  2213. // | /+----------+ | | / +-----------+
  2214. // | / | | | | / / /|
  2215. // | / | | | _/ - / / +
  2216. // | / | |-|------(_)----|--- /-----------/-------> AxisP
  2217. // | / | | | - +-----------+ /
  2218. // | / | | | | |/
  2219. // | / | | + +-----------+
  2220. // |/ | |/
  2221. // .--------+----------+--------------------> X
  2222. // |---------------->
  2223. // Anchor2 <--------------|
  2224. // Anchor1
  2225. // Default Position
  2226. //
  2227. // N.B. Y is going into the page
  2228. ////////////////////////////////////////////////////////////////////////////////
  2229. struct PistonGetInfo1_Fixture_4
  2230. {
  2231. PistonGetInfo1_Fixture_4()
  2232. {
  2233. wId = dWorldCreate();
  2234. bId1 = dBodyCreate(wId);
  2235. dBodySetPosition(bId1, 3, 0, 0);
  2236. bId2 = dBodyCreate(wId);
  2237. dBodySetPosition(bId2, 0, 0, 1);
  2238. dMatrix3 R;
  2239. dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0);
  2240. dBodySetRotation (bId2, R);
  2241. jId = dJointCreatePiston(wId, 0);
  2242. joint = (dxJointPiston*)jId;
  2243. dJointAttach(jId, bId1, bId2);
  2244. dJointSetPistonAnchor (jId, 2, 0, 0);
  2245. dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  2246. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  2247. dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(0.0));
  2248. dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0));
  2249. }
  2250. ~PistonGetInfo1_Fixture_4()
  2251. {
  2252. dWorldDestroy(wId);
  2253. }
  2254. dJointID jId;
  2255. dxJointPiston* joint;
  2256. dWorldID wId;
  2257. dBodyID bId1;
  2258. dBodyID bId2;
  2259. dxJoint::Info1 info;
  2260. };
  2261. ////////////////////////////////////////////////////////////////////////////////
  2262. // Position Body1 (3, 0, 0)
  2263. // Position Body2 (1, 0, 0)
  2264. // Angchor (2, 0, 0)
  2265. // Axis1 (0, 1, 0)
  2266. // Axis2 (0, 0, 1)
  2267. // AxisP1 (1, 0, 0)
  2268. //
  2269. // Only the first body moves
  2270. ////////////////////////////////////////////////////////////////////////////////
  2271. TEST_FIXTURE(PistonGetInfo1_Fixture_4, GetPistonPositionRate_Bodies_at90deg_B1_moves)
  2272. {
  2273. dBodySetLinearVel(bId1, REAL(3.33), 0.0, 0.0); // This is impossible but ...
  2274. CHECK_EQUAL(REAL(3.33), dJointGetPistonPositionRate (jId) );
  2275. dBodySetLinearVel(bId1, 0, REAL(3.33), 0);
  2276. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2277. dBodySetLinearVel(bId1, 0, 0, REAL(3.33)); // This is impossible but ...
  2278. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2279. // Only angular velocity
  2280. dBodySetAngularVel(bId1, REAL(1.22), 0.0, 0.0);
  2281. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2282. dBodySetAngularVel(bId1, 0.0, REAL(2.33), 0.0);
  2283. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2284. dBodySetAngularVel(bId1, 0.0, 0.0, REAL(5.55));
  2285. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2286. }
  2287. ////////////////////////////////////////////////////////////////////////////////
  2288. // Position Body1 (3, 0, 0)
  2289. // Position Body2 (1, 0, 0)
  2290. // Angchor (2, 0, 0)
  2291. // Axis1 (0, 1, 0)
  2292. // Axis2 (0, 0, 1)
  2293. // AxisP1 (1, 0, 0)
  2294. //
  2295. // Only the second body moves
  2296. ////////////////////////////////////////////////////////////////////////////////
  2297. TEST_FIXTURE(PistonGetInfo1_Fixture_4, GetPistonPositionRate_Bodies_at90deg_B2_moves)
  2298. {
  2299. // The length was at zero and this will give an negative length
  2300. dBodySetLinearVel(bId2, REAL(3.33), 0.0, 0.0);
  2301. CHECK_EQUAL(REAL(-3.33), dJointGetPistonPositionRate (jId) );
  2302. dBodySetLinearVel(bId2, 0, REAL(3.33), 0); // This is impossible but ...
  2303. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2304. dBodySetLinearVel(bId2, 0, 0, REAL(3.33)); // This is impossible but ...
  2305. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2306. // Only angular velocity
  2307. dBodySetAngularVel(bId2, REAL(1.22), 0.0, 0.0);
  2308. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2309. dBodySetAngularVel(bId2, 0.0, REAL(2.33), 0.0);
  2310. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2311. dBodySetAngularVel(bId2, 0.0, 0.0, REAL(5.55));
  2312. CHECK_EQUAL(REAL(0.0), dJointGetPistonPositionRate (jId) );
  2313. }
  2314. struct Fixture_Simple_Hinge
  2315. {
  2316. Fixture_Simple_Hinge ()
  2317. {
  2318. wId = dWorldCreate();
  2319. bId1 = dBodyCreate(wId);
  2320. dBodySetPosition(bId1, 0, -1, 0);
  2321. bId2 = dBodyCreate(wId);
  2322. dBodySetPosition(bId2, 0, 1, 0);
  2323. jId = dJointCreateHinge(wId, 0);
  2324. dJointAttach(jId, bId1, bId2);
  2325. }
  2326. ~Fixture_Simple_Hinge()
  2327. {
  2328. dWorldDestroy(wId);
  2329. }
  2330. dJointID jId;
  2331. dWorldID wId;
  2332. dBodyID bId1;
  2333. dBodyID bId2;
  2334. };
  2335. // Test that it is possible to have joint without a body
  2336. TEST_FIXTURE(Fixture_Simple_Hinge, test_dJointAttach)
  2337. {
  2338. bool only_body1_OK = true;
  2339. try {
  2340. dJointAttach(jId, bId1, 0);
  2341. dWorldStep (wId, 1);
  2342. }
  2343. catch (...) {
  2344. only_body1_OK = false;
  2345. }
  2346. CHECK_EQUAL(true, only_body1_OK);
  2347. bool only_body2_OK = true;
  2348. try {
  2349. dJointAttach(jId, 0, bId2);
  2350. dWorldStep (wId, 1);
  2351. }
  2352. catch (...) {
  2353. only_body2_OK = false;
  2354. }
  2355. CHECK_EQUAL(true, only_body2_OK);
  2356. bool no_body_OK = true;
  2357. try {
  2358. dJointAttach(jId, 0, 0);
  2359. dWorldStep (wId, 1);
  2360. }
  2361. catch (...) {
  2362. no_body_OK = false;
  2363. }
  2364. CHECK_EQUAL(true, no_body_OK);
  2365. }
  2366. } // End of SUITE(JointPiston)