-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathode.pyx
More file actions
4508 lines (3446 loc) · 131 KB
/
ode.pyx
File metadata and controls
4508 lines (3446 loc) · 131 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
######################################################################
# Python Open Dynamics Engine Wrapper
# Copyright (C) 2004 PyODE developers (see file AUTHORS)
# All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of EITHER:
# (1) The GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at
# your option) any later version. The text of the GNU Lesser
# General Public License is included with this library in the
# file LICENSE.
# (2) The BSD-style license that is included with this library in
# the file LICENSE-BSD.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
# LICENSE and LICENSE-BSD for more details.
######################################################################
from ode cimport *
paramLoStop = 0
paramHiStop = 1
paramVel = 2
paramLoVel = 3
paramHiVel = 4
paramFMax = 5
paramFudgeFactor = 6
paramBounce = 7
paramCFM = 8
paramStopERP = 9
paramStopCFM = 10
paramSuspensionERP = 11
paramSuspensionCFM = 12
paramERP = 13
ParamLoStop = 0
ParamHiStop = 1
ParamVel = 2
ParamLoVel = 3
ParamHiVel = 4
ParamFMax = 5
ParamFudgeFactor = 6
ParamBounce = 7
ParamCFM = 8
ParamStopERP = 9
ParamStopCFM = 10
ParamSuspensionERP = 11
ParamSuspensionCFM = 12
ParamERP = 13
ParamLoStop2 = 256 + 0
ParamHiStop2 = 256 + 1
ParamVel2 = 256 + 2
ParamLoVel2 = 256 + 3
ParamHiVel2 = 256 + 4
ParamFMax2 = 256 + 5
ParamFudgeFactor2 = 256 + 6
ParamBounce2 = 256 + 7
ParamCFM2 = 256 + 8
ParamStopERP2 = 256 + 9
ParamStopCFM2 = 256 + 10
ParamSuspensionERP2 = 256 + 11
ParamSuspensionCFM2 = 256 + 12
ParamERP2 = 256 + 13
ParamLoStop3 = 512 + 0
ParamHiStop3 = 512 + 1
ParamVel3 = 512 + 2
ParamLoVel3 = 512 + 3
ParamHiVel3 = 512 + 4
ParamFMax3 = 512 + 5
ParamFudgeFactor3 = 512 + 6
ParamBounce3 = 512 + 7
ParamCFM3 = 512 + 8
ParamStopERP3 = 512 + 9
ParamStopCFM3 = 512 + 10
ParamSuspensionERP3 = 512 + 11
ParamSuspensionCFM3 = 512 + 12
ParamERP3 = 512 + 13
ParamGroup = 256
ContactMu2 = 0x001
ContactAxisDep = 0x001
ContactFDir1 = 0x002
ContactBounce = 0x004
ContactSoftERP = 0x008
ContactSoftCFM = 0x010
ContactMotion1 = 0x020
ContactMotion2 = 0x040
ContactMotionN = 0x080
ContactSlip1 = 0x100
ContactSlip2 = 0x200
ContactRolling = 0x400
ContactApprox0 = 0x0000
ContactApprox1_1 = 0x1000
ContactApprox1_2 = 0x2000
ContactApprox1_N = 0x4000
ContactApprox1 = 0x7000
AMotorUser = dAMotorUser
AMotorEuler = dAMotorEuler
Infinity = dInfinity
import weakref
_geom_c2py_lut = weakref.WeakValueDictionary()
cdef class Mass:
"""Mass parameters of a rigid body.
This class stores mass parameters of a rigid body which can be
accessed through the following attributes:
- mass: The total mass of the body (float)
- c: The center of gravity position in body frame (3-tuple of floats)
- I: The 3x3 inertia tensor in body frame (3-tuple of 3-tuples)
This class wraps the dMass structure from the C API.
@ivar mass: The total mass of the body
@ivar c: The center of gravity position in body frame (cx, cy, cz)
@ivar I: The 3x3 inertia tensor in body frame ((I11, I12, I13), (I12, I22, I23), (I13, I23, I33))
@type mass: float
@type c: 3-tuple of floats
@type I: 3-tuple of 3-tuples of floats
"""
cdef dMass _mass
def __cinit__(self):
dMassSetZero(&self._mass)
def setZero(self):
"""setZero()
Set all the mass parameters to zero."""
dMassSetZero(&self._mass)
def setParameters(self, mass, cgx, cgy, cgz, I11, I22, I33, I12, I13, I23):
"""setParameters(mass, cgx, cgy, cgz, I11, I22, I33, I12, I13, I23)
Set the mass parameters to the given values.
@param mass: Total mass of the body.
@param cgx: Center of gravity position in the body frame (x component).
@param cgy: Center of gravity position in the body frame (y component).
@param cgz: Center of gravity position in the body frame (z component).
@param I11: Inertia tensor
@param I22: Inertia tensor
@param I33: Inertia tensor
@param I12: Inertia tensor
@param I13: Inertia tensor
@param I23: Inertia tensor
@type mass: float
@type cgx: float
@type cgy: float
@type cgz: float
@type I11: float
@type I22: float
@type I33: float
@type I12: float
@type I13: float
@type I23: float
"""
dMassSetParameters(&self._mass, mass, cgx, cgy, cgz,
I11, I22, I33, I12, I13, I23)
def setSphere(self, density, radius):
"""setSphere(density, radius)
Set the mass parameters to represent a sphere of the given radius
and density, with the center of mass at (0,0,0) relative to the body.
@param density: The density of the sphere
@param radius: The radius of the sphere
@type density: float
@type radius: float
"""
dMassSetSphere(&self._mass, density, radius)
def setSphereTotal(self, total_mass, radius):
"""setSphereTotal(total_mass, radius)
Set the mass parameters to represent a sphere of the given radius
and mass, with the center of mass at (0,0,0) relative to the body.
@param total_mass: The total mass of the sphere
@param radius: The radius of the sphere
@type total_mass: float
@type radius: float
"""
dMassSetSphereTotal(&self._mass, total_mass, radius)
def setCapsule(self, density, direction, radius, length):
"""setCapsule(density, direction, radius, length)
Set the mass parameters to represent a capsule of the given parameters
and density, with the center of mass at (0,0,0) relative to the body.
The radius of the cylinder (and the spherical cap) is radius. The length
of the cylinder (not counting the spherical cap) is length. The
cylinder's long axis is oriented along the body's x, y or z axis
according to the value of direction (1=x, 2=y, 3=z). The first function
accepts the density of the object, the second accepts its total mass.
@param density: The density of the capsule
@param direction: The direction of the capsule's cylinder (1=x axis, 2=y axis, 3=z axis)
@param radius: The radius of the capsule's cylinder
@param length: The length of the capsule's cylinder (without the caps)
@type density: float
@type direction: int
@type radius: float
@type length: float
"""
dMassSetCapsule(&self._mass, density, direction, radius, length)
def setCapsuleTotal(self, total_mass, direction, radius, length):
"""setCapsuleTotal(total_mass, direction, radius, length)
Set the mass parameters to represent a capsule of the given parameters
and mass, with the center of mass at (0,0,0) relative to the body. The
radius of the cylinder (and the spherical cap) is radius. The length of
the cylinder (not counting the spherical cap) is length. The cylinder's
long axis is oriented along the body's x, y or z axis according to the
value of direction (1=x, 2=y, 3=z). The first function accepts the
density of the object, the second accepts its total mass.
@param total_mass: The total mass of the capsule
@param direction: The direction of the capsule's cylinder (1=x axis, 2=y axis, 3=z axis)
@param radius: The radius of the capsule's cylinder
@param length: The length of the capsule's cylinder (without the caps)
@type total_mass: float
@type direction: int
@type radius: float
@type length: float
"""
dMassSetCapsuleTotal(&self._mass, total_mass, direction,
radius, length)
def setCylinder(self, density, direction, r, h):
"""setCylinder(density, direction, r, h)
Set the mass parameters to represent a flat-ended cylinder of
the given parameters and density, with the center of mass at
(0,0,0) relative to the body. The radius of the cylinder is r.
The length of the cylinder is h. The cylinder's long axis is
oriented along the body's x, y or z axis according to the value
of direction (1=x, 2=y, 3=z).
@param density: The density of the cylinder
@param direction: The direction of the cylinder (1=x axis, 2=y axis, 3=z axis)
@param r: The radius of the cylinder
@param h: The length of the cylinder
@type density: float
@type direction: int
@type r: float
@type h: float
"""
dMassSetCylinder(&self._mass, density, direction, r, h)
def setCylinderTotal(self, total_mass, direction, r, h):
"""setCylinderTotal(total_mass, direction, r, h)
Set the mass parameters to represent a flat-ended cylinder of
the given parameters and mass, with the center of mass at
(0,0,0) relative to the body. The radius of the cylinder is r.
The length of the cylinder is h. The cylinder's long axis is
oriented along the body's x, y or z axis according to the value
of direction (1=x, 2=y, 3=z).
@param total_mass: The total mass of the cylinder
@param direction: The direction of the cylinder (1=x axis, 2=y axis, 3=z axis)
@param r: The radius of the cylinder
@param h: The length of the cylinder
@type total_mass: float
@type direction: int
@type r: float
@type h: float
"""
dMassSetCylinderTotal(&self._mass, total_mass, direction, r, h)
def setBox(self, density, lx, ly, lz):
"""setBox(density, lx, ly, lz)
Set the mass parameters to represent a box of the given
dimensions and density, with the center of mass at (0,0,0)
relative to the body. The side lengths of the box along the x,
y and z axes are lx, ly and lz.
@param density: The density of the box
@param lx: The length along the x axis
@param ly: The length along the y axis
@param lz: The length along the z axis
@type density: float
@type lx: float
@type ly: float
@type lz: float
"""
dMassSetBox(&self._mass, density, lx, ly, lz)
def setBoxTotal(self, total_mass, lx, ly, lz):
"""setBoxTotal(total_mass, lx, ly, lz)
Set the mass parameters to represent a box of the given
dimensions and mass, with the center of mass at (0,0,0)
relative to the body. The side lengths of the box along the x,
y and z axes are lx, ly and lz.
@param total_mass: The total mass of the box
@param lx: The length along the x axis
@param ly: The length along the y axis
@param lz: The length along the z axis
@type total_mass: float
@type lx: float
@type ly: float
@type lz: float
"""
dMassSetBoxTotal(&self._mass, total_mass, lx, ly, lz)
def adjust(self, newmass):
"""adjust(newmass)
Adjust the total mass. Given mass parameters for some object,
adjust them so the total mass is now newmass. This is useful
when using the setXyz() methods to set the mass parameters for
certain objects - they take the object density, not the total
mass.
@param newmass: The new total mass
@type newmass: float
"""
dMassAdjust(&self._mass, newmass)
def translate(self, t):
"""translate(t)
Adjust mass parameters. Given mass parameters for some object,
adjust them to represent the object displaced by (x,y,z)
relative to the body frame.
@param t: Translation vector (x, y, z)
@type t: 3-tuple of floats
"""
dMassTranslate(&self._mass, t[0], t[1], t[2])
# def rotate(self, R):
# """
# Given mass parameters for some object, adjust them to
# represent the object rotated by R relative to the body frame.
# """
# pass
def add(self, Mass b):
"""add(b)
Add the mass b to the mass object. Masses can also be added using
the + operator.
@param b: The mass to add to this mass
@type b: Mass
"""
dMassAdd(&self._mass, &b._mass)
def __getattr__(self, name):
if name == "mass":
return self._mass.mass
elif name == "c":
return self._mass.c[0], self._mass.c[1], self._mass.c[2]
elif name == "I":
return ((self._mass.I[0], self._mass.I[1], self._mass.I[2]),
(self._mass.I[4], self._mass.I[5], self._mass.I[6]),
(self._mass.I[8], self._mass.I[9], self._mass.I[10]))
else:
raise AttributeError("Mass object has no attribute '%s'" % name)
def __setattr__(self, name, value):
if name == "mass":
self.adjust(value)
elif name == "c":
raise AttributeError("Use the setParameter() method to change c")
elif name == "I":
raise AttributeError("Use the setParameter() method to change I")
else:
raise AttributeError("Mass object has no attribute '%s" % name)
def __add__(self, Mass b):
self.add(b)
return self
def __str__(self):
m = str(self._mass.mass)
sc0 = str(self._mass.c[0])
sc1 = str(self._mass.c[1])
sc2 = str(self._mass.c[2])
I11 = str(self._mass.I[0])
I22 = str(self._mass.I[5])
I33 = str(self._mass.I[10])
I12 = str(self._mass.I[1])
I13 = str(self._mass.I[2])
I23 = str(self._mass.I[6])
return ("Mass=%s\n"
"Cg=(%s, %s, %s)\n"
"I11=%s I22=%s I33=%s\n"
"I12=%s I13=%s I23=%s" %
(m, sc0, sc1, sc2, I11, I22, I33, I12, I13, I23))
# return ("Mass=%s / "
# "Cg=(%s, %s, %s) / "
# "I11=%s I22=%s I33=%s "
# "I12=%s I13=%s I23=%s" %
# (m, sc0, sc1, sc2, I11, I22, I33, I12, I13, I23))
cdef class Contact:
"""This class represents a contact between two bodies in one point.
A Contact object stores all the input parameters for a ContactJoint.
This class wraps the ODE dContact structure which has 3 components::
struct dContact {
dSurfaceParameters surface;
dContactGeom geom;
dVector3 fdir1;
};
This wrapper class provides methods to get and set the items of those
structures.
"""
cdef dContact _contact
def __cinit__(self):
self._contact.surface.mode = ContactBounce
self._contact.surface.mu = dInfinity
self._contact.surface.bounce = 0.1
# getMode
def getMode(self):
"""getMode() -> flags
Return the contact flags.
"""
return self._contact.surface.mode
# setMode
def setMode(self, flags):
"""setMode(flags)
Set the contact flags. The argument m is a combination of the
ContactXyz flags (ContactMu2, ContactBounce, ...).
@param flags: Contact flags
@type flags: int
"""
self._contact.surface.mode = flags
# getMu
def getMu(self):
"""getMu() -> float
Return the Coulomb friction coefficient.
"""
return self._contact.surface.mu
# setMu
def setMu(self, mu):
"""setMu(mu)
Set the Coulomb friction coefficient.
@param mu: Coulomb friction coefficient (0..Infinity)
@type mu: float
"""
self._contact.surface.mu = mu
# getMu2
def getMu2(self):
"""getMu2() -> float
Return the optional Coulomb friction coefficient for direction 2.
"""
return self._contact.surface.mu2
# setMu2
def setMu2(self, mu):
"""setMu2(mu)
Set the optional Coulomb friction coefficient for direction 2.
@param mu: Coulomb friction coefficient (0..Infinity)
@type mu: float
"""
self._contact.surface.mu2 = mu
# getBounce
def getBounce(self):
"""getBounce() -> float
Return the restitution parameter.
"""
return self._contact.surface.bounce
# setBounce
def setBounce(self, b):
"""setBounce(b)
@param b: Restitution parameter (0..1)
@type b: float
"""
self._contact.surface.bounce = b
# getBounceVel
def getBounceVel(self):
"""getBounceVel() -> float
Return the minimum incoming velocity necessary for bounce.
"""
return self._contact.surface.bounce_vel
# setBounceVel
def setBounceVel(self, bv):
"""setBounceVel(bv)
Set the minimum incoming velocity necessary for bounce. Incoming
velocities below this will effectively have a bounce parameter of 0.
@param bv: Velocity
@type bv: float
"""
self._contact.surface.bounce_vel = bv
# getSoftERP
def getSoftERP(self):
"""getSoftERP() -> float
Return the contact normal "softness" parameter.
"""
return self._contact.surface.soft_erp
# setSoftERP
def setSoftERP(self, erp):
"""setSoftERP(erp)
Set the contact normal "softness" parameter.
@param erp: Softness parameter
@type erp: float
"""
self._contact.surface.soft_erp = erp
# getSoftCFM
def getSoftCFM(self):
"""getSoftCFM() -> float
Return the contact normal "softness" parameter.
"""
return self._contact.surface.soft_cfm
# setSoftCFM
def setSoftCFM(self, cfm):
"""setSoftCFM(cfm)
Set the contact normal "softness" parameter.
@param cfm: Softness parameter
@type cfm: float
"""
self._contact.surface.soft_cfm = cfm
# getMotion1
def getMotion1(self):
"""getMotion1() -> float
Get the surface velocity in friction direction 1.
"""
return self._contact.surface.motion1
# setMotion1
def setMotion1(self, m):
"""setMotion1(m)
Set the surface velocity in friction direction 1.
@param m: Surface velocity
@type m: float
"""
self._contact.surface.motion1 = m
# getMotion2
def getMotion2(self):
"""getMotion2() -> float
Get the surface velocity in friction direction 2.
"""
return self._contact.surface.motion2
# setMotion2
def setMotion2(self, m):
"""setMotion2(m)
Set the surface velocity in friction direction 2.
@param m: Surface velocity
@type m: float
"""
self._contact.surface.motion2 = m
# getSlip1
def getSlip1(self):
"""getSlip1() -> float
Get the coefficient of force-dependent-slip (FDS) for friction
direction 1.
"""
return self._contact.surface.slip1
# setSlip1
def setSlip1(self, s):
"""setSlip1(s)
Set the coefficient of force-dependent-slip (FDS) for friction
direction 1.
@param s: FDS coefficient
@type s: float
"""
self._contact.surface.slip1 = s
# getSlip2
def getSlip2(self):
"""getSlip2() -> float
Get the coefficient of force-dependent-slip (FDS) for friction
direction 2.
"""
return self._contact.surface.slip2
# setSlip2
def setSlip2(self, s):
"""setSlip2(s)
Set the coefficient of force-dependent-slip (FDS) for friction
direction 1.
@param s: FDS coefficient
@type s: float
"""
self._contact.surface.slip2 = s
# getFDir1
def getFDir1(self):
"""getFDir1() -> (x, y, z)
Get the "first friction direction" vector that defines a direction
along which frictional force is applied.
"""
return (self._contact.fdir1[0],
self._contact.fdir1[1],
self._contact.fdir1[2])
# setFDir1
def setFDir1(self, fdir):
"""setFDir1(fdir)
Set the "first friction direction" vector that defines a direction
along which frictional force is applied. It must be of unit length
and perpendicular to the contact normal (so it is typically
tangential to the contact surface).
@param fdir: Friction direction
@type fdir: 3-sequence of floats
"""
self._contact.fdir1[0] = fdir[0]
self._contact.fdir1[1] = fdir[1]
self._contact.fdir1[2] = fdir[2]
# getContactGeomParams
def getContactGeomParams(self):
"""getContactGeomParams() -> (pos, normal, depth, geom1, geom2)
Get the ContactGeom structure of the contact.
The return value is a tuple (pos, normal, depth, geom1, geom2)
where pos and normal are 3-tuples of floats and depth is a single
float. geom1 and geom2 are the Geom objects of the geoms in contact.
"""
cdef size_t id1, id2
pos = (self._contact.geom.pos[0],
self._contact.geom.pos[1],
self._contact.geom.pos[2])
normal = (self._contact.geom.normal[0],
self._contact.geom.normal[1],
self._contact.geom.normal[2])
depth = self._contact.geom.depth
id1 = <size_t>self._contact.geom.g1
id2 = <size_t>self._contact.geom.g2
g1 = _geom_c2py_lut[id1]
g2 = _geom_c2py_lut[id2]
return pos, normal, depth, g1, g2
# setContactGeomParams
def setContactGeomParams(self, pos, normal, depth, g1=None, g2=None):
"""setContactGeomParams(pos, normal, depth, geom1=None, geom2=None)
Set the ContactGeom structure of the contact.
@param pos: Contact position, in global coordinates
@type pos: 3-sequence of floats
@param normal: Unit length normal vector
@type normal: 3-sequence of floats
@param depth: Depth to which the two bodies inter-penetrate
@type depth: float
@param geom1: Geometry object 1 that collided
@type geom1: Geom
@param geom2: Geometry object 2 that collided
@type geom2: Geom
"""
cdef size_t id
self._contact.geom.pos[0] = pos[0]
self._contact.geom.pos[1] = pos[1]
self._contact.geom.pos[2] = pos[2]
self._contact.geom.normal[0] = normal[0]
self._contact.geom.normal[1] = normal[1]
self._contact.geom.normal[2] = normal[2]
self._contact.geom.depth = depth
if g1 != None:
id = g1._id()
self._contact.geom.g1 = <dGeomID>id
else:
self._contact.geom.g1 = <dGeomID>0
if g2 != None:
id = g2._id()
self._contact.geom.g2 = <dGeomID>id
else:
self._contact.geom.g2 = <dGeomID>0
# World
cdef class World:
"""Dynamics world.
The world object is a container for rigid bodies and joints.
Constructor::
World()
"""
cdef dWorldID wid
def __cinit__(self):
self.wid = dWorldCreate()
def __dealloc__(self):
if self.wid != NULL:
dWorldDestroy(self.wid)
# setGravity
def setGravity(self, gravity):
"""setGravity(gravity)
Set the world's global gravity vector.
@param gravity: Gravity vector
@type gravity: 3-sequence of floats
"""
dWorldSetGravity(self.wid, gravity[0], gravity[1], gravity[2])
# getGravity
def getGravity(self):
"""getGravity() -> 3-tuple
Return the world's global gravity vector as a 3-tuple of floats.
"""
cdef dVector3 g
dWorldGetGravity(self.wid, g)
return g[0], g[1], g[2]
# setERP
def setERP(self, erp):
"""setERP(erp)
Set the global ERP value, that controls how much error
correction is performed in each time step. Typical values are
in the range 0.1-0.8. The default is 0.2.
@param erp: Global ERP value
@type erp: float
"""
dWorldSetERP(self.wid, erp)
# getERP
def getERP(self):
"""getERP() -> float
Get the global ERP value, that controls how much error
correction is performed in each time step. Typical values are
in the range 0.1-0.8. The default is 0.2.
"""
return dWorldGetERP(self.wid)
# setCFM
def setCFM(self, cfm):
"""setCFM(cfm)
Set the global CFM (constraint force mixing) value. Typical
values are in the range 10E-9 - 1. The default is 10E-5 if
single precision is being used, or 10E-10 if double precision
is being used.
@param cfm: Constraint force mixing value
@type cfm: float
"""
dWorldSetCFM(self.wid, cfm)
# getCFM
def getCFM(self):
"""getCFM() -> float
Get the global CFM (constraint force mixing) value. Typical
values are in the range 10E-9 - 1. The default is 10E-5 if
single precision is being used, or 10E-10 if double precision
is being used.
"""
return dWorldGetCFM(self.wid)
# step
def step(self, stepsize):
"""step(stepsize)
Step the world. This uses a "big matrix" method that takes
time on the order of O(m3) and memory on the order of O(m2), where m
is the total number of constraint rows.
For large systems this will use a lot of memory and can be
very slow, but this is currently the most accurate method.
@param stepsize: Time step
@type stepsize: float
"""
dWorldStep(self.wid, stepsize)
# quickStep
def quickStep(self, stepsize):
"""quickStep(stepsize)
Step the world. This uses an iterative method that takes time
on the order of O(m*N) and memory on the order of O(m), where m is
the total number of constraint rows and N is the number of
iterations.
For large systems this is a lot faster than dWorldStep, but it
is less accurate.
@param stepsize: Time step
@type stepsize: float
"""
dWorldQuickStep(self.wid, stepsize)
# setQuickStepNumIterations
def setQuickStepNumIterations(self, num):
"""setQuickStepNumIterations(num)
Set the number of iterations that the QuickStep method
performs per step. More iterations will give a more accurate
solution, but will take longer to compute. The default is 20
iterations.
@param num: Number of iterations
@type num: int
"""
dWorldSetQuickStepNumIterations(self.wid, num)
# getQuickStepNumIterations
def getQuickStepNumIterations(self):
"""getQuickStepNumIterations() -> int
Get the number of iterations that the QuickStep method
performs per step. More iterations will give a more accurate
solution, but will take longer to compute. The default is 20
iterations.
"""
return dWorldGetQuickStepNumIterations(self.wid)
# setQuickStepNumIterations
def setContactMaxCorrectingVel(self, vel):
"""setContactMaxCorrectingVel(vel)
Set the maximum correcting velocity that contacts are allowed
to generate. The default value is infinity (i.e. no
limit). Reducing this value can help prevent "popping" of
deeply embedded objects.
@param vel: Maximum correcting velocity
@type vel: float
"""
dWorldSetContactMaxCorrectingVel(self.wid, vel)
# getQuickStepNumIterations
def getContactMaxCorrectingVel(self):
"""getContactMaxCorrectingVel() -> float
Get the maximum correcting velocity that contacts are allowed
to generate. The default value is infinity (i.e. no
limit). Reducing this value can help prevent "popping" of
deeply embedded objects.
"""
return dWorldGetContactMaxCorrectingVel(self.wid)
# setContactSurfaceLayer
def setContactSurfaceLayer(self, depth):
"""setContactSurfaceLayer(depth)
Set the depth of the surface layer around all geometry
objects. Contacts are allowed to sink into the surface layer
up to the given depth before coming to rest. The default value
is zero. Increasing this to some small value (e.g. 0.001) can
help prevent jittering problems due to contacts being
repeatedly made and broken.
@param depth: Surface layer depth
@type depth: float
"""
dWorldSetContactSurfaceLayer(self.wid, depth)
# getContactSurfaceLayer
def getContactSurfaceLayer(self):
"""getContactSurfaceLayer()
Get the depth of the surface layer around all geometry
objects. Contacts are allowed to sink into the surface layer
up to the given depth before coming to rest. The default value
is zero. Increasing this to some small value (e.g. 0.001) can
help prevent jittering problems due to contacts being
repeatedly made and broken.
"""
return dWorldGetContactSurfaceLayer(self.wid)
# setAutoDisableFlag
def setAutoDisableFlag(self, flag):
"""setAutoDisableFlag(flag)
Set the default auto-disable flag for newly created bodies.
@param flag: True = Do auto disable
@type flag: bool
"""
dWorldSetAutoDisableFlag(self.wid, flag)
# getAutoDisableFlag
def getAutoDisableFlag(self):
"""getAutoDisableFlag() -> bool
Get the default auto-disable flag for newly created bodies.
"""
return dWorldGetAutoDisableFlag(self.wid)
# setAutoDisableLinearThreshold
def setAutoDisableLinearThreshold(self, threshold):
"""setAutoDisableLinearThreshold(threshold)
Set the default auto-disable linear threshold for newly created
bodies.
@param threshold: Linear threshold
@type threshold: float
"""
dWorldSetAutoDisableLinearThreshold(self.wid, threshold)
# getAutoDisableLinearThreshold
def getAutoDisableLinearThreshold(self):
"""getAutoDisableLinearThreshold() -> float
Get the default auto-disable linear threshold for newly created
bodies.
"""
return dWorldGetAutoDisableLinearThreshold(self.wid)
# setAutoDisableAngularThreshold
def setAutoDisableAngularThreshold(self, threshold):
"""setAutoDisableAngularThreshold(threshold)
Set the default auto-disable angular threshold for newly created
bodies.