joint.cpp 93 KB

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