diff options
author | dan miller | 2007-10-19 05:24:38 +0000 |
---|---|---|
committer | dan miller | 2007-10-19 05:24:38 +0000 |
commit | f205de7847da7ae1c10212d82e7042d0100b4ce0 (patch) | |
tree | 9acc9608a6880502aaeda43af52c33e278e95b9c /libraries/ode-0.9/ode/src/joint.h | |
parent | trying to fix my screwup part deux (diff) | |
download | opensim-SC_OLD-f205de7847da7ae1c10212d82e7042d0100b4ce0.zip opensim-SC_OLD-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.gz opensim-SC_OLD-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.bz2 opensim-SC_OLD-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.xz |
from the start... checking in ode-0.9
Diffstat (limited to 'libraries/ode-0.9/ode/src/joint.h')
-rw-r--r-- | libraries/ode-0.9/ode/src/joint.h | 346 |
1 files changed, 346 insertions, 0 deletions
diff --git a/libraries/ode-0.9/ode/src/joint.h b/libraries/ode-0.9/ode/src/joint.h new file mode 100644 index 0000000..27c013e --- /dev/null +++ b/libraries/ode-0.9/ode/src/joint.h | |||
@@ -0,0 +1,346 @@ | |||
1 | /************************************************************************* | ||
2 | * * | ||
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. * | ||
4 | * All rights reserved. Email: russ@q12.org 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 | |||
23 | #ifndef _ODE_JOINT_H_ | ||
24 | #define _ODE_JOINT_H_ | ||
25 | |||
26 | |||
27 | #include "objects.h" | ||
28 | #include <ode/contact.h> | ||
29 | #include "obstack.h" | ||
30 | |||
31 | |||
32 | // joint flags | ||
33 | enum { | ||
34 | // if this flag is set, the joint was allocated in a joint group | ||
35 | dJOINT_INGROUP = 1, | ||
36 | |||
37 | // if this flag is set, the joint was attached with arguments (0,body). | ||
38 | // our convention is to treat all attaches as (body,0), i.e. so node[0].body | ||
39 | // is always nonzero, so this flag records the fact that the arguments were | ||
40 | // swapped. | ||
41 | dJOINT_REVERSE = 2, | ||
42 | |||
43 | // if this flag is set, the joint can not have just one body attached to it, | ||
44 | // it must have either zero or two bodies attached. | ||
45 | dJOINT_TWOBODIES = 4 | ||
46 | }; | ||
47 | |||
48 | |||
49 | // there are two of these nodes in the joint, one for each connection to a | ||
50 | // body. these are node of a linked list kept by each body of it's connecting | ||
51 | // joints. but note that the body pointer in each node points to the body that | ||
52 | // makes use of the *other* node, not this node. this trick makes it a bit | ||
53 | // easier to traverse the body/joint graph. | ||
54 | |||
55 | struct dxJointNode { | ||
56 | dxJoint *joint; // pointer to enclosing dxJoint object | ||
57 | dxBody *body; // *other* body this joint is connected to | ||
58 | dxJointNode *next; // next node in body's list of connected joints | ||
59 | }; | ||
60 | |||
61 | |||
62 | struct dxJoint : public dObject { | ||
63 | // naming convention: the "first" body this is connected to is node[0].body, | ||
64 | // and the "second" body is node[1].body. if this joint is only connected | ||
65 | // to one body then the second body is 0. | ||
66 | |||
67 | // info returned by getInfo1 function. the constraint dimension is m (<=6). | ||
68 | // i.e. that is the total number of rows in the jacobian. `nub' is the | ||
69 | // number of unbounded variables (which have lo,hi = -/+ infinity). | ||
70 | |||
71 | struct Info1 { | ||
72 | int m,nub; | ||
73 | }; | ||
74 | |||
75 | // info returned by getInfo2 function | ||
76 | |||
77 | struct Info2 { | ||
78 | // integrator parameters: frames per second (1/stepsize), default error | ||
79 | // reduction parameter (0..1). | ||
80 | dReal fps,erp; | ||
81 | |||
82 | // for the first and second body, pointers to two (linear and angular) | ||
83 | // n*3 jacobian sub matrices, stored by rows. these matrices will have | ||
84 | // been initialized to 0 on entry. if the second body is zero then the | ||
85 | // J2xx pointers may be 0. | ||
86 | dReal *J1l,*J1a,*J2l,*J2a; | ||
87 | |||
88 | // elements to jump from one row to the next in J's | ||
89 | int rowskip; | ||
90 | |||
91 | // right hand sides of the equation J*v = c + cfm * lambda. cfm is the | ||
92 | // "constraint force mixing" vector. c is set to zero on entry, cfm is | ||
93 | // set to a constant value (typically very small or zero) value on entry. | ||
94 | dReal *c,*cfm; | ||
95 | |||
96 | // lo and hi limits for variables (set to -/+ infinity on entry). | ||
97 | dReal *lo,*hi; | ||
98 | |||
99 | // findex vector for variables. see the LCP solver interface for a | ||
100 | // description of what this does. this is set to -1 on entry. | ||
101 | // note that the returned indexes are relative to the first index of | ||
102 | // the constraint. | ||
103 | int *findex; | ||
104 | }; | ||
105 | |||
106 | // virtual function table: size of the joint structure, function pointers. | ||
107 | // we do it this way instead of using C++ virtual functions because | ||
108 | // sometimes we need to allocate joints ourself within a memory pool. | ||
109 | |||
110 | typedef void init_fn (dxJoint *joint); | ||
111 | typedef void getInfo1_fn (dxJoint *joint, Info1 *info); | ||
112 | typedef void getInfo2_fn (dxJoint *joint, Info2 *info); | ||
113 | struct Vtable { | ||
114 | int size; | ||
115 | init_fn *init; | ||
116 | getInfo1_fn *getInfo1; | ||
117 | getInfo2_fn *getInfo2; | ||
118 | int typenum; // a dJointTypeXXX type number | ||
119 | }; | ||
120 | |||
121 | Vtable *vtable; // virtual function table | ||
122 | int flags; // dJOINT_xxx flags | ||
123 | dxJointNode node[2]; // connections to bodies. node[1].body can be 0 | ||
124 | dJointFeedback *feedback; // optional feedback structure | ||
125 | dReal lambda[6]; // lambda generated by last step | ||
126 | }; | ||
127 | |||
128 | |||
129 | // joint group. NOTE: any joints in the group that have their world destroyed | ||
130 | // will have their world pointer set to 0. | ||
131 | |||
132 | struct dxJointGroup : public dBase { | ||
133 | int num; // number of joints on the stack | ||
134 | dObStack stack; // a stack of (possibly differently sized) dxJoint | ||
135 | }; // objects. | ||
136 | |||
137 | |||
138 | // common limit and motor information for a single joint axis of movement | ||
139 | struct dxJointLimitMotor { | ||
140 | dReal vel,fmax; // powered joint: velocity, max force | ||
141 | dReal lostop,histop; // joint limits, relative to initial position | ||
142 | dReal fudge_factor; // when powering away from joint limits | ||
143 | dReal normal_cfm; // cfm to use when not at a stop | ||
144 | dReal stop_erp,stop_cfm; // erp and cfm for when at joint limit | ||
145 | dReal bounce; // restitution factor | ||
146 | // variables used between getInfo1() and getInfo2() | ||
147 | int limit; // 0=free, 1=at lo limit, 2=at hi limit | ||
148 | dReal limit_err; // if at limit, amount over limit | ||
149 | |||
150 | void init (dxWorld *); | ||
151 | void set (int num, dReal value); | ||
152 | dReal get (int num); | ||
153 | int testRotationalLimit (dReal angle); | ||
154 | int addLimot (dxJoint *joint, dxJoint::Info2 *info, int row, | ||
155 | dVector3 ax1, int rotational); | ||
156 | }; | ||
157 | |||
158 | |||
159 | // ball and socket | ||
160 | |||
161 | struct dxJointBall : public dxJoint { | ||
162 | dVector3 anchor1; // anchor w.r.t first body | ||
163 | dVector3 anchor2; // anchor w.r.t second body | ||
164 | dReal erp; // error reduction | ||
165 | dReal cfm; // constraint force mix in | ||
166 | void set (int num, dReal value); | ||
167 | dReal get (int num); | ||
168 | }; | ||
169 | extern struct dxJoint::Vtable __dball_vtable; | ||
170 | |||
171 | |||
172 | // hinge | ||
173 | |||
174 | struct dxJointHinge : public dxJoint { | ||
175 | dVector3 anchor1; // anchor w.r.t first body | ||
176 | dVector3 anchor2; // anchor w.r.t second body | ||
177 | dVector3 axis1; // axis w.r.t first body | ||
178 | dVector3 axis2; // axis w.r.t second body | ||
179 | dQuaternion qrel; // initial relative rotation body1 -> body2 | ||
180 | dxJointLimitMotor limot; // limit and motor information | ||
181 | }; | ||
182 | extern struct dxJoint::Vtable __dhinge_vtable; | ||
183 | |||
184 | |||
185 | // universal | ||
186 | |||
187 | struct dxJointUniversal : public dxJoint { | ||
188 | dVector3 anchor1; // anchor w.r.t first body | ||
189 | dVector3 anchor2; // anchor w.r.t second body | ||
190 | dVector3 axis1; // axis w.r.t first body | ||
191 | dVector3 axis2; // axis w.r.t second body | ||
192 | dQuaternion qrel1; // initial relative rotation body1 -> virtual cross piece | ||
193 | dQuaternion qrel2; // initial relative rotation virtual cross piece -> body2 | ||
194 | dxJointLimitMotor limot1; // limit and motor information for axis1 | ||
195 | dxJointLimitMotor limot2; // limit and motor information for axis2 | ||
196 | }; | ||
197 | extern struct dxJoint::Vtable __duniversal_vtable; | ||
198 | |||
199 | |||
200 | /** | ||
201 | * The axisP must be perpendicular to axis2 | ||
202 | * <PRE> | ||
203 | * +-------------+ | ||
204 | * | x | | ||
205 | * +------------\+ | ||
206 | * Prismatic articulation .. .. | ||
207 | * | .. .. | ||
208 | * \/ .. .. | ||
209 | * +--------------+ --| __.. .. anchor2 | ||
210 | * | x | .....|.......(__) .. | ||
211 | * +--------------+ --| ^ < | ||
212 | * |----------------------->| | ||
213 | * Offset |--- Rotoide articulation | ||
214 | * </PRE> | ||
215 | */ | ||
216 | struct dxJointPR : public dxJoint { | ||
217 | |||
218 | dVector3 anchor2; ///< @brief Position of the rotoide articulation | ||
219 | ///< w.r.t second body. | ||
220 | ///< @note Position of body 2 in world frame + | ||
221 | ///< anchor2 in world frame give the position | ||
222 | ///< of the rotoide articulation | ||
223 | dVector3 axisR1; ///< axis of the rotoide articulation w.r.t first body. | ||
224 | ///< @note This is considered as axis1 from the parameter | ||
225 | ///< view. | ||
226 | dVector3 axisR2; ///< axis of the rotoide articulation w.r.t second body. | ||
227 | ///< @note This is considered also as axis1 from the | ||
228 | ///< parameter view | ||
229 | dVector3 axisP1; ///< axis for the prismatic articulation w.r.t first body. | ||
230 | ///< @note This is considered as axis2 in from the parameter | ||
231 | ///< view | ||
232 | dQuaternion qrel; ///< initial relative rotation body1 -> body2. | ||
233 | dVector3 offset; ///< @brief vector between the body1 and the rotoide | ||
234 | ///< articulation. | ||
235 | ///< | ||
236 | ///< Going from the first to the second in the frame | ||
237 | ///< of body1. | ||
238 | ///< That should be aligned with body1 center along axisP | ||
239 | ///< This is calculated whe the axis are set. | ||
240 | dxJointLimitMotor limotR; ///< limit and motor information for the rotoide articulation. | ||
241 | dxJointLimitMotor limotP; ///< limit and motor information for the prismatic articulation. | ||
242 | }; | ||
243 | extern struct dxJoint::Vtable __dPR_vtable; | ||
244 | |||
245 | |||
246 | |||
247 | // slider. if body2 is 0 then qrel is the absolute rotation of body1 and | ||
248 | // offset is the position of body1 center along axis1. | ||
249 | |||
250 | struct dxJointSlider : public dxJoint { | ||
251 | dVector3 axis1; // axis w.r.t first body | ||
252 | dQuaternion qrel; // initial relative rotation body1 -> body2 | ||
253 | dVector3 offset; // point relative to body2 that should be | ||
254 | // aligned with body1 center along axis1 | ||
255 | dxJointLimitMotor limot; // limit and motor information | ||
256 | }; | ||
257 | extern struct dxJoint::Vtable __dslider_vtable; | ||
258 | |||
259 | |||
260 | // contact | ||
261 | |||
262 | struct dxJointContact : public dxJoint { | ||
263 | int the_m; // number of rows computed by getInfo1 | ||
264 | dContact contact; | ||
265 | }; | ||
266 | extern struct dxJoint::Vtable __dcontact_vtable; | ||
267 | |||
268 | |||
269 | // hinge 2 | ||
270 | |||
271 | struct dxJointHinge2 : public dxJoint { | ||
272 | dVector3 anchor1; // anchor w.r.t first body | ||
273 | dVector3 anchor2; // anchor w.r.t second body | ||
274 | dVector3 axis1; // axis 1 w.r.t first body | ||
275 | dVector3 axis2; // axis 2 w.r.t second body | ||
276 | dReal c0,s0; // cos,sin of desired angle between axis 1,2 | ||
277 | dVector3 v1,v2; // angle ref vectors embedded in first body | ||
278 | dxJointLimitMotor limot1; // limit+motor info for axis 1 | ||
279 | dxJointLimitMotor limot2; // limit+motor info for axis 2 | ||
280 | dReal susp_erp,susp_cfm; // suspension parameters (erp,cfm) | ||
281 | }; | ||
282 | extern struct dxJoint::Vtable __dhinge2_vtable; | ||
283 | |||
284 | |||
285 | // angular motor | ||
286 | |||
287 | struct dxJointAMotor : public dxJoint { | ||
288 | int num; // number of axes (0..3) | ||
289 | int mode; // a dAMotorXXX constant | ||
290 | int rel[3]; // what the axes are relative to (global,b1,b2) | ||
291 | dVector3 axis[3]; // three axes | ||
292 | dxJointLimitMotor limot[3]; // limit+motor info for axes | ||
293 | dReal angle[3]; // user-supplied angles for axes | ||
294 | // these vectors are used for calculating euler angles | ||
295 | dVector3 reference1; // original axis[2], relative to body 1 | ||
296 | dVector3 reference2; // original axis[0], relative to body 2 | ||
297 | }; | ||
298 | extern struct dxJoint::Vtable __damotor_vtable; | ||
299 | |||
300 | |||
301 | struct dxJointLMotor : public dxJoint { | ||
302 | int num; | ||
303 | int rel[3]; | ||
304 | dVector3 axis[3]; | ||
305 | dxJointLimitMotor limot[3]; | ||
306 | }; | ||
307 | |||
308 | extern struct dxJoint::Vtable __dlmotor_vtable; | ||
309 | |||
310 | |||
311 | // 2d joint, constrains to z == 0 | ||
312 | |||
313 | struct dxJointPlane2D : public dxJoint | ||
314 | { | ||
315 | int row_motor_x; | ||
316 | int row_motor_y; | ||
317 | int row_motor_angle; | ||
318 | dxJointLimitMotor motor_x; | ||
319 | dxJointLimitMotor motor_y; | ||
320 | dxJointLimitMotor motor_angle; | ||
321 | }; | ||
322 | |||
323 | extern struct dxJoint::Vtable __dplane2d_vtable; | ||
324 | |||
325 | |||
326 | // fixed | ||
327 | |||
328 | struct dxJointFixed : public dxJoint { | ||
329 | dQuaternion qrel; // initial relative rotation body1 -> body2 | ||
330 | dVector3 offset; // relative offset between the bodies | ||
331 | dReal erp; // error reduction parameter | ||
332 | dReal cfm; // constraint force mix-in | ||
333 | void set (int num, dReal value); | ||
334 | dReal get (int num); | ||
335 | }; | ||
336 | extern struct dxJoint::Vtable __dfixed_vtable; | ||
337 | |||
338 | |||
339 | // null joint, for testing only | ||
340 | |||
341 | struct dxJointNull : public dxJoint { | ||
342 | }; | ||
343 | extern struct dxJoint::Vtable __dnull_vtable; | ||
344 | |||
345 | |||
346 | #endif | ||