dartpy 0.1.0.post107__cp310-cp310-manylinux_2_28_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dartpy might be problematic. Click here for more details.
- dartpy-0.1.0.post107.dist-info/LICENSE +31 -0
- dartpy-0.1.0.post107.dist-info/METADATA +47 -0
- dartpy-0.1.0.post107.dist-info/RECORD +66 -0
- dartpy-0.1.0.post107.dist-info/WHEEL +5 -0
- dartpy-0.1.0.post107.dist-info/top_level.txt +2 -0
- dartpy.cpython-310-x86_64-linux-gnu.so +0 -0
- dartpy.libs/libGLU-ff1477cc.so.1.3.1 +0 -0
- dartpy.libs/libOpenThreads-0250ab5c.so.3.3.1 +0 -0
- dartpy.libs/libXi-9178a6bd.so.6.1.0 +0 -0
- dartpy.libs/libXxf86vm-8446c95f.so.1.0.0 +0 -0
- dartpy.libs/libassimp-79671a85.so.5.2.4 +0 -0
- dartpy.libs/libccd-f7023733.so.2.0 +0 -0
- dartpy.libs/libconsole_bridge-757d7af3.so.1.0 +0 -0
- dartpy.libs/libfcl-fafce69a.so.0.7.0 +0 -0
- dartpy.libs/libglut-0c8fd390.so.3.10.0 +0 -0
- dartpy.libs/liboctomap-0c5b15c6.so.1.9.6 +0 -0
- dartpy.libs/liboctomath-31ce0045.so.1.9.6 +0 -0
- dartpy.libs/libosg-b45f9cbc.so.3.7.0 +0 -0
- dartpy.libs/libosgDB-209e5143.so.3.7.0 +0 -0
- dartpy.libs/libosgGA-260d5c6e.so.3.7.0 +0 -0
- dartpy.libs/libosgManipulator-05bcdf02.so.3.7.0 +0 -0
- dartpy.libs/libosgShadow-9971a879.so.3.7.0 +0 -0
- dartpy.libs/libosgText-16341674.so.3.7.0 +0 -0
- dartpy.libs/libosgUtil-e5d05863.so.3.7.0 +0 -0
- dartpy.libs/libosgViewer-7dd0f485.so.3.7.0 +0 -0
- dartpy.libs/libtinyxml-296537c6.so +0 -0
- dartpy.libs/liburdfdom_model-6cad1cb6.so.3.0 +0 -0
- dartpy.libs/liburdfdom_model_state-36524f5e.so.3.0 +0 -0
- dartpy.libs/liburdfdom_sensor-ad2c126c.so.3.0 +0 -0
- dartpy.libs/liburdfdom_world-538ea8a8.so.3.0 +0 -0
- tests/__init__.py +0 -0
- tests/integration/__init__.py +0 -0
- tests/integration/test_joint_force_torque.py +305 -0
- tests/unit/__init__.py +0 -0
- tests/unit/collision/__init__.py +0 -0
- tests/unit/collision/test_collision.py +249 -0
- tests/unit/common/__init__.py +0 -0
- tests/unit/common/test_logging.py +20 -0
- tests/unit/common/test_stopwatch.py +50 -0
- tests/unit/common/test_string.py +42 -0
- tests/unit/common/test_uri.py +20 -0
- tests/unit/constraint/__init__.py +0 -0
- tests/unit/constraint/test_constraint.py +42 -0
- tests/unit/dynamics/__init__.py +0 -0
- tests/unit/dynamics/test_aspect.py +15 -0
- tests/unit/dynamics/test_body_node.py +65 -0
- tests/unit/dynamics/test_inertia.py +76 -0
- tests/unit/dynamics/test_inverse_kinematics.py +98 -0
- tests/unit/dynamics/test_joint.py +149 -0
- tests/unit/dynamics/test_meta_skeleton.py +41 -0
- tests/unit/dynamics/test_simple_frame.py +54 -0
- tests/unit/dynamics/test_skeleton.py +23 -0
- tests/unit/math/__init__.py +0 -0
- tests/unit/math/test_random.py +40 -0
- tests/unit/optimizer/__init__.py +0 -0
- tests/unit/optimizer/test_optimizer.py +93 -0
- tests/unit/simulation/__init__.py +0 -0
- tests/unit/simulation/test_world.py +45 -0
- tests/unit/utils/__init__.py +0 -0
- tests/unit/utils/test_dart_loader.py +72 -0
- tests/unit/utils/test_mjcf_parser.py +19 -0
- tests/unit/utils/test_sdf_parser.py +21 -0
- tests/unit/utils/test_skel_parser.py +22 -0
- tests/unit/v7/__init__.py +0 -0
- tests/unit/v7/test_import.py +11 -0
- tests/util.py +18 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
import dartpy as dart
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def kinematics_tester(joint):
|
|
9
|
+
num_tests = 2
|
|
10
|
+
|
|
11
|
+
joint.setTransformFromChildBodyNode(dart.math.expMap(np.random.rand(6)))
|
|
12
|
+
joint.setTransformFromParentBodyNode(dart.math.expMap(np.random.rand(6)))
|
|
13
|
+
|
|
14
|
+
dof = joint.getNumDofs()
|
|
15
|
+
|
|
16
|
+
q = np.zeros(dof)
|
|
17
|
+
dq = np.zeros(dof)
|
|
18
|
+
|
|
19
|
+
for _ in range(num_tests):
|
|
20
|
+
q_delta = 1e-5
|
|
21
|
+
|
|
22
|
+
for i in range(dof):
|
|
23
|
+
q[i] = dart.math.Random.uniform(-math.pi, math.pi)
|
|
24
|
+
dq[i] = dart.math.Random.uniform(-math.pi, math.pi)
|
|
25
|
+
|
|
26
|
+
joint.setPositions(q)
|
|
27
|
+
joint.setVelocities(dq)
|
|
28
|
+
|
|
29
|
+
if dof == 0:
|
|
30
|
+
return
|
|
31
|
+
|
|
32
|
+
T = joint.getRelativeTransform()
|
|
33
|
+
J = joint.getRelativeJacobian(q)
|
|
34
|
+
dJ = joint.getRelativeJacobianTimeDeriv()
|
|
35
|
+
|
|
36
|
+
# Verify transform
|
|
37
|
+
assert dart.math.verifyTransform(T)
|
|
38
|
+
|
|
39
|
+
# Test analytic Jacobian and numerical Jacobian
|
|
40
|
+
numericJ = np.zeros((6, dof))
|
|
41
|
+
for i in range(dof):
|
|
42
|
+
q_a = q.copy()
|
|
43
|
+
joint.setPositions(q_a)
|
|
44
|
+
T_a = joint.getRelativeTransform()
|
|
45
|
+
|
|
46
|
+
q_b = q.copy()
|
|
47
|
+
q_b[i] += q_delta
|
|
48
|
+
joint.setPositions(q_b)
|
|
49
|
+
T_b = joint.getRelativeTransform()
|
|
50
|
+
|
|
51
|
+
Tinv_a = T_a.inverse()
|
|
52
|
+
|
|
53
|
+
dTdq = (T_b.matrix() - T_a.matrix()) / q_delta
|
|
54
|
+
|
|
55
|
+
Ji_4x4matrix = np.matmul(Tinv_a.matrix(), dTdq)
|
|
56
|
+
Ji = np.zeros(6)
|
|
57
|
+
Ji[0] = Ji_4x4matrix[2, 1]
|
|
58
|
+
Ji[1] = Ji_4x4matrix[0, 2]
|
|
59
|
+
Ji[2] = Ji_4x4matrix[1, 0]
|
|
60
|
+
Ji[3] = Ji_4x4matrix[0, 3]
|
|
61
|
+
Ji[4] = Ji_4x4matrix[1, 3]
|
|
62
|
+
Ji[5] = Ji_4x4matrix[2, 3]
|
|
63
|
+
numericJ[:, i] = Ji
|
|
64
|
+
|
|
65
|
+
assert np.allclose(J, numericJ, atol=1e-5)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_kinematics():
|
|
69
|
+
skel = dart.dynamics.Skeleton()
|
|
70
|
+
joint, _ = skel.createWeldJointAndBodyNodePair()
|
|
71
|
+
kinematics_tester(joint)
|
|
72
|
+
|
|
73
|
+
skel = dart.dynamics.Skeleton()
|
|
74
|
+
joint, _ = skel.createRevoluteJointAndBodyNodePair()
|
|
75
|
+
kinematics_tester(joint)
|
|
76
|
+
|
|
77
|
+
skel = dart.dynamics.Skeleton()
|
|
78
|
+
joint, _ = skel.createPrismaticJointAndBodyNodePair()
|
|
79
|
+
kinematics_tester(joint)
|
|
80
|
+
|
|
81
|
+
skel = dart.dynamics.Skeleton()
|
|
82
|
+
joint, _ = skel.createScrewJointAndBodyNodePair()
|
|
83
|
+
kinematics_tester(joint)
|
|
84
|
+
|
|
85
|
+
skel = dart.dynamics.Skeleton()
|
|
86
|
+
joint, _ = skel.createUniversalJointAndBodyNodePair()
|
|
87
|
+
kinematics_tester(joint)
|
|
88
|
+
|
|
89
|
+
skel = dart.dynamics.Skeleton()
|
|
90
|
+
joint, _ = skel.createTranslationalJoint2DAndBodyNodePair()
|
|
91
|
+
kinematics_tester(joint)
|
|
92
|
+
|
|
93
|
+
skel = dart.dynamics.Skeleton()
|
|
94
|
+
joint, _ = skel.createEulerJointAndBodyNodePair()
|
|
95
|
+
kinematics_tester(joint)
|
|
96
|
+
|
|
97
|
+
skel = dart.dynamics.Skeleton()
|
|
98
|
+
joint, _ = skel.createTranslationalJointAndBodyNodePair()
|
|
99
|
+
kinematics_tester(joint)
|
|
100
|
+
|
|
101
|
+
skel = dart.dynamics.Skeleton()
|
|
102
|
+
joint, _ = skel.createPlanarJointAndBodyNodePair()
|
|
103
|
+
kinematics_tester(joint)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_access_to_parent_child_transforms():
|
|
107
|
+
skel = dart.dynamics.Skeleton()
|
|
108
|
+
joint, _ = skel.createRevoluteJointAndBodyNodePair()
|
|
109
|
+
|
|
110
|
+
parentToJointTf = dart.math.Isometry3.Identity()
|
|
111
|
+
parentToJointTf.set_translation(np.random.rand(3, 1))
|
|
112
|
+
childToJointTf = dart.math.Isometry3.Identity()
|
|
113
|
+
childToJointTf.set_translation(np.random.rand(3, 1))
|
|
114
|
+
|
|
115
|
+
joint.setTransformFromParentBodyNode(parentToJointTf)
|
|
116
|
+
joint.setTransformFromChildBodyNode(childToJointTf)
|
|
117
|
+
|
|
118
|
+
storedParentTf = joint.getTransformFromParentBodyNode()
|
|
119
|
+
storedChildTf = joint.getTransformFromChildBodyNode()
|
|
120
|
+
|
|
121
|
+
assert np.allclose(parentToJointTf.matrix(), storedParentTf.matrix())
|
|
122
|
+
assert np.allclose(childToJointTf.matrix(), storedChildTf.matrix())
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def test_BallJoint_positions_conversion():
|
|
126
|
+
assert np.allclose(
|
|
127
|
+
dart.dynamics.BallJoint.convertToPositions(np.eye(3)), np.zeros((1, 3))
|
|
128
|
+
)
|
|
129
|
+
assert np.allclose(
|
|
130
|
+
dart.dynamics.BallJoint.convertToPositions(
|
|
131
|
+
np.array([[0, 1, 0], [-1, 0, 0], [0, 0, 1]])
|
|
132
|
+
),
|
|
133
|
+
np.array([0, 0, -np.pi / 2]),
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
for i in range(30):
|
|
137
|
+
ballJointPos = np.random.uniform(-np.pi / 2, np.pi / 2, 3)
|
|
138
|
+
assert np.allclose(
|
|
139
|
+
dart.dynamics.BallJoint.convertToRotation(
|
|
140
|
+
dart.dynamics.BallJoint.convertToPositions(
|
|
141
|
+
dart.dynamics.BallJoint.convertToRotation(ballJointPos)
|
|
142
|
+
)
|
|
143
|
+
),
|
|
144
|
+
dart.dynamics.BallJoint.convertToRotation(ballJointPos),
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
if __name__ == "__main__":
|
|
149
|
+
pytest.main()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import platform
|
|
2
|
+
|
|
3
|
+
import dartpy as dart
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
# TODO(JS): Move this to integration category once created
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_basic():
|
|
10
|
+
urdfParser = dart.utils.DartLoader()
|
|
11
|
+
kr5 = urdfParser.parseSkeleton("dart://sample/urdf/KR5/KR5 sixx R650.urdf")
|
|
12
|
+
assert kr5 is not None
|
|
13
|
+
|
|
14
|
+
shoulder = kr5.getBodyNode("shoulder")
|
|
15
|
+
assert shoulder is not None
|
|
16
|
+
|
|
17
|
+
elbow = kr5.getBodyNode("elbow")
|
|
18
|
+
assert elbow is not None
|
|
19
|
+
|
|
20
|
+
chain1 = dart.dynamics.Chain(shoulder, elbow, False, "midchain")
|
|
21
|
+
assert chain1 is not None
|
|
22
|
+
assert chain1.getNumBodyNodes() is 2
|
|
23
|
+
|
|
24
|
+
chain2 = dart.dynamics.Chain(shoulder, elbow, True, "midchain")
|
|
25
|
+
assert chain2 is not None
|
|
26
|
+
assert chain2.getNumBodyNodes() is 3
|
|
27
|
+
|
|
28
|
+
assert len(kr5.getPositions()) is not 0
|
|
29
|
+
assert kr5.getNumJoints() is not 0
|
|
30
|
+
assert kr5.getRootJoint() is not None
|
|
31
|
+
assert len(kr5.getRootJoint().getPositions()) is 0
|
|
32
|
+
|
|
33
|
+
rootBody = kr5.getBodyNode(0)
|
|
34
|
+
assert rootBody is not None
|
|
35
|
+
|
|
36
|
+
rootJoint = kr5.getJoint(0)
|
|
37
|
+
assert rootJoint is not None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
pytest.main()
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import platform
|
|
2
|
+
|
|
3
|
+
import dartpy as dart
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_basic():
|
|
9
|
+
world_frame = dart.dynamics.Frame.World()
|
|
10
|
+
assert world_frame.isWorld()
|
|
11
|
+
|
|
12
|
+
frame1 = dart.dynamics.SimpleFrame()
|
|
13
|
+
assert not frame1.isWorld()
|
|
14
|
+
assert not frame1.isShapeNode()
|
|
15
|
+
assert frame1.isShapeFrame()
|
|
16
|
+
|
|
17
|
+
assert frame1.getTransform().translation()[0] == pytest.approx(0)
|
|
18
|
+
assert frame1.getTransform().translation()[1] == pytest.approx(0)
|
|
19
|
+
assert frame1.getTransform().translation()[2] == pytest.approx(0)
|
|
20
|
+
|
|
21
|
+
frame1.setTranslation([1, 2, 3])
|
|
22
|
+
assert frame1.getTransform().translation()[0] == pytest.approx(1)
|
|
23
|
+
assert frame1.getTransform().translation()[1] == pytest.approx(2)
|
|
24
|
+
assert frame1.getTransform().translation()[2] == pytest.approx(3)
|
|
25
|
+
|
|
26
|
+
assert frame1.getParentFrame().isWorld()
|
|
27
|
+
assert frame1.descendsFrom(None)
|
|
28
|
+
assert frame1.descendsFrom(world_frame)
|
|
29
|
+
assert frame1.descendsFrom(frame1)
|
|
30
|
+
|
|
31
|
+
frame2 = frame1.spawnChildSimpleFrame()
|
|
32
|
+
assert not frame2.isWorld()
|
|
33
|
+
assert frame2.descendsFrom(None)
|
|
34
|
+
assert frame2.descendsFrom(world_frame)
|
|
35
|
+
assert frame2.descendsFrom(frame1)
|
|
36
|
+
assert frame2.descendsFrom(frame2)
|
|
37
|
+
|
|
38
|
+
assert frame2.getTransform().translation()[0] == pytest.approx(1)
|
|
39
|
+
assert frame2.getTransform().translation()[1] == pytest.approx(2)
|
|
40
|
+
assert frame2.getTransform().translation()[2] == pytest.approx(3)
|
|
41
|
+
|
|
42
|
+
frame2.setRelativeTranslation([1, 2, 3])
|
|
43
|
+
assert frame2.getTransform().translation()[0] == pytest.approx(2)
|
|
44
|
+
assert frame2.getTransform().translation()[1] == pytest.approx(4)
|
|
45
|
+
assert frame2.getTransform().translation()[2] == pytest.approx(6)
|
|
46
|
+
|
|
47
|
+
frame2.setTranslation([1, 2, 3])
|
|
48
|
+
assert frame2.getTransform().translation()[0] == pytest.approx(1)
|
|
49
|
+
assert frame2.getTransform().translation()[1] == pytest.approx(2)
|
|
50
|
+
assert frame2.getTransform().translation()[2] == pytest.approx(3)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if __name__ == "__main__":
|
|
54
|
+
pytest.main()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import platform
|
|
2
|
+
|
|
3
|
+
import dartpy as dart
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_basic():
|
|
9
|
+
skel = dart.dynamics.Skeleton()
|
|
10
|
+
|
|
11
|
+
joint_prop = dart.dynamics.FreeJointProperties()
|
|
12
|
+
joint_prop.mName = "joint0"
|
|
13
|
+
assert joint_prop.mName == "joint0"
|
|
14
|
+
|
|
15
|
+
[joint1, body1] = skel.createFreeJointAndBodyNodePair(None, joint_prop)
|
|
16
|
+
assert joint1.getType() == "FreeJoint"
|
|
17
|
+
assert joint1.getName() == "joint0"
|
|
18
|
+
|
|
19
|
+
assert skel.getBodyNodes()[0].getName() == body1.getName()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if __name__ == "__main__":
|
|
23
|
+
pytest.main()
|
|
File without changes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import platform
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from dartpy.math import Random
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_create():
|
|
8
|
+
rand = Random()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_seed():
|
|
12
|
+
rand = Random()
|
|
13
|
+
|
|
14
|
+
N = 10
|
|
15
|
+
|
|
16
|
+
min = -10
|
|
17
|
+
max = 10
|
|
18
|
+
|
|
19
|
+
first = []
|
|
20
|
+
second = []
|
|
21
|
+
third = []
|
|
22
|
+
|
|
23
|
+
tol = 1e-6
|
|
24
|
+
|
|
25
|
+
for i in range(N):
|
|
26
|
+
Random.setSeed(i)
|
|
27
|
+
first.append(Random.uniform(min, max))
|
|
28
|
+
second.append(Random.uniform(min, max))
|
|
29
|
+
third.append(Random.uniform(min, max))
|
|
30
|
+
|
|
31
|
+
for i in range(N):
|
|
32
|
+
Random.setSeed(i)
|
|
33
|
+
assert Random.getSeed() is i
|
|
34
|
+
assert Random.uniform(min, max) == pytest.approx(first[i], tol)
|
|
35
|
+
assert Random.uniform(min, max) == pytest.approx(second[i], tol)
|
|
36
|
+
assert Random.uniform(min, max) == pytest.approx(third[i], tol)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
pytest.main()
|
|
File without changes
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
import dartpy as dart
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# Problem reference: http://ab-initio.mit.edu/wiki/index.php/NLopt_Tutorial
|
|
8
|
+
class SampleObjFunc(dart.optimizer.Function):
|
|
9
|
+
def eval(self, x):
|
|
10
|
+
return math.sqrt(x[1])
|
|
11
|
+
|
|
12
|
+
def evalGradient(self, x, grad):
|
|
13
|
+
grad[0] = 0
|
|
14
|
+
grad[1] = 0.5 / (math.sqrt(x[1]) + 0.000001)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class SampleConstFunc(dart.optimizer.Function):
|
|
18
|
+
def __init__(self, a, b):
|
|
19
|
+
super(SampleConstFunc, self).__init__()
|
|
20
|
+
self.a = a
|
|
21
|
+
self.b = b
|
|
22
|
+
|
|
23
|
+
def eval(self, x):
|
|
24
|
+
return (self.a * x[0] + self.b) * (self.a * x[0] + self.b) * (
|
|
25
|
+
self.a * x[0] + self.b
|
|
26
|
+
) - x[1]
|
|
27
|
+
|
|
28
|
+
def evalGradient(self, x, grad):
|
|
29
|
+
grad[0] = 3 * self.a * (self.a * x[0] + self.b) * (self.a * x[0] + self.b)
|
|
30
|
+
grad[1] = -1.0
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_gradient_descent_solver():
|
|
34
|
+
prob = dart.optimizer.Problem(2)
|
|
35
|
+
assert prob.getDimension() is 2
|
|
36
|
+
|
|
37
|
+
prob.setLowerBounds([-1e100, 0])
|
|
38
|
+
prob.setInitialGuess([1.234, 5.678])
|
|
39
|
+
|
|
40
|
+
assert prob.getInitialGuess()[0] == pytest.approx(1.234)
|
|
41
|
+
|
|
42
|
+
obj = SampleObjFunc()
|
|
43
|
+
prob.setObjective(obj)
|
|
44
|
+
|
|
45
|
+
solver = dart.optimizer.GradientDescentSolver(prob)
|
|
46
|
+
success = solver.solve()
|
|
47
|
+
assert success is True
|
|
48
|
+
|
|
49
|
+
min_f = prob.getOptimumValue()
|
|
50
|
+
opt_x = prob.getOptimalSolution()
|
|
51
|
+
|
|
52
|
+
assert min_f == pytest.approx(0, 1e-6)
|
|
53
|
+
assert len(opt_x) == prob.getDimension()
|
|
54
|
+
assert opt_x[0] == pytest.approx(1.234, 0.0)
|
|
55
|
+
assert opt_x[1] == pytest.approx(0, solver.getTolerance())
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_nlopt_solver():
|
|
59
|
+
if not hasattr(dart.optimizer, "NloptSolver"):
|
|
60
|
+
return
|
|
61
|
+
|
|
62
|
+
prob = dart.optimizer.Problem(2)
|
|
63
|
+
assert prob.getDimension() is 2
|
|
64
|
+
|
|
65
|
+
prob.setLowerBounds([-1e100, 0])
|
|
66
|
+
prob.setInitialGuess([1.234, 5.678])
|
|
67
|
+
|
|
68
|
+
assert prob.getInitialGuess()[0] == pytest.approx(1.234)
|
|
69
|
+
|
|
70
|
+
obj = SampleObjFunc()
|
|
71
|
+
prob.setObjective(obj)
|
|
72
|
+
|
|
73
|
+
const1 = SampleConstFunc(2, 0)
|
|
74
|
+
const2 = SampleConstFunc(-1, 1)
|
|
75
|
+
prob.addIneqConstraint(const1)
|
|
76
|
+
prob.addIneqConstraint(const2)
|
|
77
|
+
|
|
78
|
+
solver = dart.optimizer.NloptSolver(prob)
|
|
79
|
+
solver.setAlgorithm(dart.optimizer.NloptSolver.Algorithm.LD_MMA)
|
|
80
|
+
success = solver.solve()
|
|
81
|
+
assert success is True
|
|
82
|
+
|
|
83
|
+
min_f = prob.getOptimumValue()
|
|
84
|
+
opt_x = prob.getOptimalSolution()
|
|
85
|
+
|
|
86
|
+
assert min_f == pytest.approx(0.544330847, 1e-5)
|
|
87
|
+
assert len(opt_x) == prob.getDimension()
|
|
88
|
+
assert opt_x[0] == pytest.approx(0.333334, 1e-5)
|
|
89
|
+
assert opt_x[1] == pytest.approx(0.296296, 1e-5)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
if __name__ == "__main__":
|
|
93
|
+
pytest.main()
|
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import platform
|
|
2
|
+
|
|
3
|
+
import dartpy as dart
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_empty_world():
|
|
8
|
+
world = dart.simulation.World("my world")
|
|
9
|
+
assert world.getNumSkeletons() is 0
|
|
10
|
+
assert world.getNumSimpleFrames() is 0
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_collision_detector_change():
|
|
14
|
+
world = dart.simulation.World("world")
|
|
15
|
+
solver = world.getConstraintSolver()
|
|
16
|
+
assert solver is not None
|
|
17
|
+
|
|
18
|
+
assert (
|
|
19
|
+
solver.getCollisionDetector().getType()
|
|
20
|
+
== dart.collision.FCLCollisionDetector().getStaticType()
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
solver.setCollisionDetector(dart.collision.DARTCollisionDetector())
|
|
24
|
+
assert (
|
|
25
|
+
solver.getCollisionDetector().getType()
|
|
26
|
+
== dart.collision.DARTCollisionDetector().getStaticType()
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
if hasattr(dart.collision, "BulletCollisionDetector"):
|
|
30
|
+
solver.setCollisionDetector(dart.collision.BulletCollisionDetector())
|
|
31
|
+
assert (
|
|
32
|
+
solver.getCollisionDetector().getType()
|
|
33
|
+
== dart.collision.BulletCollisionDetector().getStaticType()
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
if hasattr(dart.collision, "OdeCollisionDetector"):
|
|
37
|
+
solver.setCollisionDetector(dart.collision.OdeCollisionDetector())
|
|
38
|
+
assert (
|
|
39
|
+
solver.getCollisionDetector().getType()
|
|
40
|
+
== dart.collision.OdeCollisionDetector().getStaticType()
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
pytest.main()
|
|
File without changes
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import platform
|
|
3
|
+
|
|
4
|
+
import dartpy
|
|
5
|
+
import pytest
|
|
6
|
+
from dartpy.utils import DartLoader
|
|
7
|
+
from tests.util import get_asset_path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_parse_skeleton_non_existing_path_returns_null():
|
|
11
|
+
assert os.path.isfile(get_asset_path("skel/cubes.skel")) is True
|
|
12
|
+
loader = DartLoader()
|
|
13
|
+
assert loader.parseSkeleton(get_asset_path("skel/test/does_not_exist.urdf")) is None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_parse_skeleton_invalid_urdf_returns_null():
|
|
17
|
+
loader = DartLoader()
|
|
18
|
+
assert loader.parseSkeleton(get_asset_path("urdf/invalid.urdf")) is None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_parse_skeleton_missing_mesh_returns_null():
|
|
22
|
+
loader = DartLoader()
|
|
23
|
+
assert loader.parseSkeleton(get_asset_path("urdf/missing_mesh.urdf")) is None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_parse_skeleton_invalid_mesh_returns_null():
|
|
27
|
+
loader = DartLoader()
|
|
28
|
+
assert loader.parseSkeleton(get_asset_path("urdf/invalid_mesh.urdf")) is None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_parse_skeleton_missing_package_returns_null():
|
|
32
|
+
loader = DartLoader()
|
|
33
|
+
assert loader.parseSkeleton(get_asset_path("urdf/missing_package.urdf")) is None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_parse_skeleton_loads_primitive_geometry():
|
|
37
|
+
loader = DartLoader()
|
|
38
|
+
assert (
|
|
39
|
+
loader.parseSkeleton(get_asset_path("urdf/test/primitive_geometry.urdf"))
|
|
40
|
+
is not None
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# Failing with following errors:
|
|
45
|
+
# TypeError: No to_python (by-value) converter found for C++ type: std::shared_ptr<dart::simulation::World>
|
|
46
|
+
#
|
|
47
|
+
# def test_parse_world():
|
|
48
|
+
# loader = DartLoader()
|
|
49
|
+
# assert loader.parseWorld(get_asset_path('urdf/testWorld.urdf')) is not None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_parse_joint_properties():
|
|
53
|
+
loader = DartLoader()
|
|
54
|
+
robot = loader.parseSkeleton(get_asset_path("urdf/test/joint_properties.urdf"))
|
|
55
|
+
assert robot is not None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# joint1 = robot.getJoint(1)
|
|
59
|
+
# assert joint1 is not None
|
|
60
|
+
# assert joint1.getDampingCoefficient(0) == pytest.approx(1.2, 1e-12)
|
|
61
|
+
# assert joint1.getCoulombFriction(0) == pytest.approx(2.3, 1e-12)
|
|
62
|
+
|
|
63
|
+
# joint2 = robot.getJoint(2)
|
|
64
|
+
# assert joint2 is not None
|
|
65
|
+
# assert joint2.getPositionLowerLimit(0) == -float("inf")
|
|
66
|
+
# assert joint2.getPositionUpperLimit(0) == float("inf")
|
|
67
|
+
# if not platform.linux_distribution()[1] == '14.04':
|
|
68
|
+
# assert joint2.isCyclic(0)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
pytest.main()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import platform
|
|
3
|
+
|
|
4
|
+
import dartpy as dart
|
|
5
|
+
import pytest
|
|
6
|
+
from tests.util import get_asset_path
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_parse_fetch():
|
|
10
|
+
assert (
|
|
11
|
+
dart.utils.MjcfParser.readWorld(
|
|
12
|
+
"dart://sample/mjcf/openai/robotics/fetch/pick_and_place.xml"
|
|
13
|
+
)
|
|
14
|
+
is not None
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__":
|
|
19
|
+
pytest.main()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) 2011-2024, The DART development contributors
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# The list of contributors can be found at:
|
|
5
|
+
# https://github.com/dartsim/dart/blob/main/LICENSE
|
|
6
|
+
#
|
|
7
|
+
# This file is provided under the "BSD-style" License
|
|
8
|
+
|
|
9
|
+
import dartpy as dart
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_read_world():
|
|
14
|
+
assert (
|
|
15
|
+
dart.utils.SdfParser.readWorld("dart://sample/sdf/double_pendulum.world")
|
|
16
|
+
is not None
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if __name__ == "__main__":
|
|
21
|
+
pytest.main()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Copyright (c) 2011-2024, The DART development contributors
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# The list of contributors can be found at:
|
|
5
|
+
# https://github.com/dartsim/dart/blob/main/LICENSE
|
|
6
|
+
#
|
|
7
|
+
# This file is provided under the "BSD-style" License
|
|
8
|
+
|
|
9
|
+
import dartpy as dart
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_read_world():
|
|
14
|
+
assert dart.utils.SkelParser.readWorld("dart://sample/skel/cubes.skel") is not None
|
|
15
|
+
assert (
|
|
16
|
+
dart.utils.SkelParser.readWorld("dart://sample/skel/cubes.skel", None)
|
|
17
|
+
is not None
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
if __name__ == "__main__":
|
|
22
|
+
pytest.main()
|
|
File without changes
|
tests/util.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
import os
|
|
3
|
+
import os.path
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_path_to_this_file():
|
|
7
|
+
return inspect.getfile(inspect.currentframe())
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_asset_path(rel_path, check_existing=False):
|
|
11
|
+
if rel_path.startswith("/"):
|
|
12
|
+
full_path = rel_path
|
|
13
|
+
else:
|
|
14
|
+
full_path = os.path.join(os.path.dirname(__file__), "../../data/", rel_path)
|
|
15
|
+
if check_existing and not os.path.exists(full_path):
|
|
16
|
+
raise IOError("File %s does not exist" % full_path)
|
|
17
|
+
|
|
18
|
+
return full_path
|