-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
98 lines (84 loc) · 3.3 KB
/
index.html
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
---
title: Coach.js Pendulum example
---
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Coach.js Example</title>
<script src="static/coach.js"></script>
<style>
#simTime {
position: absolute;
bottom: 5px;
left: 10px;
background-color: white;
opacity: 0.7;
}
</style>
</head>
<body>
<div id='simTime'>Simulation Time (% real time): <div id='simRate' style="display: inline-block">0</div></div>
<script>
var world = new coach.World({
"dt": 0.0001,
"cameraOptions": {
"type": "perspective",
"position": [2, 2, 2],
"target": [0,1,0],
},
});
var pendulum = new coach.Character();
var ground = new coach.entities.Box([5,1,5], { mass: 0, color: [100,100,100], id: 'ground' });
var pivot = new coach.entities.Box([0.1,0.1,0.1], {mass: 0, color: [255,0,0]});
var link1 = new coach.entities.Box([0.5, 0.1, 0.1], {mass: 1, color: [0,255,0]});
var link2 = new coach.entities.Box([0.5, 0.1, 0.1], {mass: 1, color: [0,0,255]});
var link3 = new coach.entities.Box([0.5, 0.1, 0.1], {mass: 1, color: [0,255,255]});
ground.position = [0.,-0.5,0];
pivot.position = [0,2,0];
link1.position = [0.25,2,0];
link2.position = [0.75,2,0];
link3.position = [1.25,2,0];
world.addEntity(ground);
// Example of adding something to the world, then later
// adding it to a character
world.addEntity(link2);
world.addEntity(link3);
pendulum.addEntity(pivot);
pendulum.addEntity(link1);
pendulum.addEntity(link2);
pendulum.addEntity(link3);
var j0 = new coach.joints.Ball(pivot, link1, [0,2,0], {
"torqueScale": [0.1,1,1.0],
});
var j1 = new coach.joints.Ball(link1, link2, [0.5,2,0], {
"torqueScale": [0.1,1,1.0],
});
var j2 = new coach.joints.Ball(link2, link3, [1,2,0], {
"torqueScale": [0.1,1,1.0],
});
pendulum.addJoint(j0);
pendulum.addJoint(j1);
pendulum.addJoint(j2);
world.addCharacter(pendulum);
var pdc = new coach.controllers.PDController3D(j1, {"X": 0, "Y": 0, "Z": 1.57}, {
"kp": 200,
"kd": 20
});
var pdc2 = new coach.controllers.PDController3D(j2, {"X": 0, "Y": 1.57, "Z": 0}, {
"kp": 200,
"kd": 20
});
var controller = function(dt) {
var T = pdc.evaluate(dt);
j1.addTorque(T);
var T2 = pdc2.evaluate(dt);
j2.addTorque(T2);
};
var renderCallback = function(camera, rate) {
coach.lib.$('#simRate').text((rate).toFixed(1));
}
world.go({renderCallback: renderCallback, simulationCallback: controller })
</script>
</body>
</html>