joint.cpp 97 KB

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