joint.cpp 97 KB

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