-
Notifications
You must be signed in to change notification settings - Fork 19
/
3jsbot_rrt_connect.js
117 lines (81 loc) · 3.01 KB
/
3jsbot_rrt_connect.js
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
//////////////////////////////////////////////////
///// RRT MOTION PLANNER
//////////////////////////////////////////////////
// CS148:
// implement RRT-Connect by Kuffner and LaValle (2000)
// paper link: http://msl.cs.uiuc.edu/~lavalle/papers/KufLav00.pdf
// compute motion plan and output into robot_path array
// elements of robot_path are vertices based on tree structure in tree_init()
// motion planner assumes collision checking by robot_collision_test()
/*
CS148: reference code has functions for:
tree_add_vertex
tree_add_edge
random_config
new_config
nearest_neighbor
rrt_extend
rrt_connect
find_path
path_dfs
*/
function robot_rrt_planner_init() {
// form configuration from base location and joint angles
q_start_config = [
robot.origin.xyz[0],
robot.origin.xyz[1],
robot.origin.xyz[2],
robot.origin.rpy[0],
robot.origin.rpy[1],
robot.origin.rpy[2]
];
q_names = {}; // store mapping between joint names and q DOFs
for (x in robot.joints) {
q_names[x] = q_start_config.length;
q_start_config = q_start_config.concat(robot.joints[x].angle);
}
// set goal configuration as the zero configuration
var i;
q_goal_config = new Array(q_start_config.length);
for (i=0;i<q_goal_config.length;i++) q_goal_config[i] = 0;
// CS148: add necessary RRT initialization here
// make sure the rrt iterations are not running faster than animation update
cur_time = Date.now();
console.log("planner initialized");
}
function robot_rrt_planner_iterate() {
rrt_alg = 1; // 0: basic rrt (OPTIONAL), 1: rrt_connect (REQUIRED)
if (rrt_iterate && (Date.now()-cur_time > 10)) {
cur_time = Date.now();
// CS148: implement RRT iteration here
}
// return path not currently found
return false;
}
function tree_init(q) {
// create tree object
var tree = {};
// initialize with vertex for given configuration
tree.vertices = [];
tree.vertices[0] = {};
tree.vertices[0].vertex = q;
tree.vertices[0].edges = [];
// create rendering geometry for base location of vertex configuration
add_config_origin_indicator_geom(tree.vertices[0]);
// maintain index of newest vertex added to tree
tree.newest = 0;
return tree;
}
function add_config_origin_indicator_geom(vertex) {
// create a threejs rendering geometry for the base location of a configuration
// assumes base origin location for configuration is first 3 elements
// assumes vertex is from tree and includes vertex field with configuration
temp_geom = new THREE.CubeGeometry(0.1,0.1,0.1);
temp_material = new THREE.MeshLambertMaterial( { color: 0xffff00, transparent: true, opacity: 0.7 } );
temp_mesh = new THREE.Mesh(temp_geom, temp_material);
temp_mesh.position.x = vertex.vertex[0];
temp_mesh.position.y = vertex.vertex[1];
temp_mesh.position.z = vertex.vertex[2];
scene.add(temp_mesh);
vertex.geom = temp_mesh;
}