Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 631 lines (506 sloc) 13.062 kb
329525f Rick Waldron Add removal delimiters to eg template. Update examples
authored
1 <!--remove-start-->
908d07d Rick Waldron Adds new ED/Biped program
authored
2 # Ed
3
4 Run with:
5 ```bash
6 node eg/ed.js
7 ```
329525f Rick Waldron Add removal delimiters to eg template. Update examples
authored
8 <!--remove-end-->
908d07d Rick Waldron Adds new ED/Biped program
authored
9
10 ```javascript
11 var five = require("johnny-five"),
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
12 compulsive = require("compulsive");
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
13
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
14 var ED,
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
15 priv = new WeakMap();
908d07d Rick Waldron Adds new ED/Biped program
authored
16
17
18 /**
19 * ED
20 *
21 * Enforcement Droid Series
22 *
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
23 * http://www.lynxmotion.com/images/jpg/bratjr00.jpg
24 * http://www.lynxmotion.com/images/html/build112.htm
25 * Hardware:
26 - 1 x Alum. Channel - 3" Single Pack (ASB-503)
27 - 2 x Multi-Purpose Servo Bracket Two Pack (ASB-04)
28 - 1 x "L" Connector Bracket Two Pack (ASB-06)
29 - 1 x "C" Servo Bracket w/ Ball Bearings Two Pack (ASB-09)
30 - 1 x Robot Feet Pair (ARF-01)
31 - 1 x SES Electronics Carrier (EC-02)
32 - 1 x SSC-32 Servo Controller (SSC-32)
33 - 4 x HS-422 (57oz.in.) Standard Servo (S422)
34 *
908d07d Rick Waldron Adds new ED/Biped program
authored
35 * @param {Object} opts Optional properties object
36 */
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
37
38 function ED(opts) {
908d07d Rick Waldron Adds new ED/Biped program
authored
39
40 opts = opts || {};
41
42 // Standard servos center at 90°
43 this.center = opts.center || 90;
44
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
45 // Initiale movement is forward
908d07d Rick Waldron Adds new ED/Biped program
authored
46 this.direction = "fwd";
47
48 // Accessor for reading the current servo position will
49 // be defined and assigned to this.degrees object.
50 this.degrees = {};
51
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
52 // holds a reference to the current repeating/looping sequence
53 this.sequence = null;
bd26733 Rick Waldron Re-render all allowed example programs. Fixes gh-65
authored
54
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
55 // Table of times (avg) to complete tasks
56 this.times = {
57 step: 0,
58 attn: 0
59 };
60
908d07d Rick Waldron Adds new ED/Biped program
authored
61 // Minor normalization of incoming properties
62 opts.right = opts.right || {};
63 opts.left = opts.left || {};
64
65 // Initialize the right and left cooperative servos
66 // TODO: Support pre-initialized servo instances
67 this.servos = {
68 right: {
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
69 hip: opts.right.hip && new five.Servo(opts.right.hip),
70 foot: opts.right.foot && new five.Servo(opts.right.foot)
908d07d Rick Waldron Adds new ED/Biped program
authored
71 },
72 left: {
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
73 hip: opts.left.hip && new five.Servo(opts.left.hip),
74 foot: opts.left.foot && new five.Servo(opts.left.foot)
908d07d Rick Waldron Adds new ED/Biped program
authored
75 }
76 };
77
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
78 // Create shortcut properties
79 this.right = this.servos.right;
80 this.left = this.servos.left;
908d07d Rick Waldron Adds new ED/Biped program
authored
81
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
82 // Create accessor descriptors:
83 //
84 // .left { .foot, .hip }
85 // .right { .foot, .hip }
86 //
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
87 ["right", "left"].forEach(function(key) {
908d07d Rick Waldron Adds new ED/Biped program
authored
88
89 var descriptor = {};
90
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
91 ["foot", "hip"].forEach(function(part) {
92 descriptor[part] = {
908d07d Rick Waldron Adds new ED/Biped program
authored
93 get: function() {
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
94 var history = this.servos[key][part].history,
95 last = history[history.length - 1];
908d07d Rick Waldron Adds new ED/Biped program
authored
96
97 return last && last.degrees || 90;
98 }.bind(this)
99 };
100 }, this);
101
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
102 this.degrees[key] = {};
908d07d Rick Waldron Adds new ED/Biped program
authored
103
104 // And finally, create properties with the generated descriptor
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
105 Object.defineProperties(this.degrees[key], descriptor);
106 }, this);
908d07d Rick Waldron Adds new ED/Biped program
authored
107
108
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
109 Object.defineProperty(this, "isCentered", {
908d07d Rick Waldron Adds new ED/Biped program
authored
110 get: function() {
111 var right, left;
112
113 right = this.degrees.right;
114 left = this.degrees.left;
115
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
116 if ((right.foot === 90 && right.hip === 90) &&
117 (left.foot === 90 && left.foot === 90)) {
908d07d Rick Waldron Adds new ED/Biped program
authored
118 return true;
119 }
120 return false;
121 }
122 });
123
124 // Store a recallable history of movement
125 // TODO: Include in savable history
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
126 this.history = [{
127 timestamp: Date.now(),
128 side: "right",
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
129 right: {
130 hip: 0,
131 foot: 0
132 },
133 left: {
134 hip: 0,
135 foot: 0
136 }
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
137 }];
908d07d Rick Waldron Adds new ED/Biped program
authored
138
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
139 // Create an entry in the private data store.
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
140 priv.set(this, {
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
141 // `isWalking` is used in:
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
142 // ED.prototype.(attn|stop)
143 // ED.prototype.(forward|fwd;reverse|rev)
144 isWalking: false,
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
145
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
146 // Allowed to hit the dance floor.
147 canDance: true
148 });
908d07d Rick Waldron Adds new ED/Biped program
authored
149 }
150
151 /**
152 * attn Stop and stand still
153 * @return {Object} this
154 */
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
155 //ED.prototype.attn = ED.prototype.stop = function() {
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
156 ED.prototype.attn = function(options) {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
157 options = options || {};
158
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
159 if (!options.isWalking) {
908d07d Rick Waldron Adds new ED/Biped program
authored
160
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
161 if (this.sequence) {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
162 this.sequence.stop();
163 this.sequence = null;
164 }
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
165
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
166 priv.set(this, {
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
167 isWalking: false
168 });
169 }
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
170
171 this.move({
172 type: "attn",
173 right: {
174 hip: 90,
175 foot: 90
176 },
177 left: {
178 hip: 90,
179 foot: 90
180 }
181 });
908d07d Rick Waldron Adds new ED/Biped program
authored
182 };
183
184 /**
185 * step Take a step
186 *
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
187 * @param {String} instruct Give the step function a specific instruction,
188 * one of: (fwd, rev, left, right)
189 *
908d07d Rick Waldron Adds new ED/Biped program
authored
190 */
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
191 ED.prototype.step = function(direct) {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
192 var isLeft, isFwd, opposing, direction, state;
908d07d Rick Waldron Adds new ED/Biped program
authored
193
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
194 state = priv.get(this);
195
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
196 if (/fwd|rev/.test(direct)) {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
197 direction = direct;
198 direct = undefined;
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
199 } else {
908d07d Rick Waldron Adds new ED/Biped program
authored
200 direction = "fwd";
201 }
202
203 // Derive which side to step on; based on last step or explicit step
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
204 this.side = direct || (this.side !== "right" ? "right" : "left");
908d07d Rick Waldron Adds new ED/Biped program
authored
205
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
206 // Update the value of the current direction
908d07d Rick Waldron Adds new ED/Biped program
authored
207 this.direction = direction;
208
209 // Determine if the bot is moving fwd
210 // Used in phase 3 to conditionally control the servo degrees
211 isFwd = this.direction === "fwd";
212
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
213 // Determine if this is the left foot
214 // Used in phase 3 to conditionally control the servo degrees
215 isLeft = this.side === "left";
216
908d07d Rick Waldron Adds new ED/Biped program
authored
217 // Opposing leg side, used in prestep and phase 2;
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
218 // opposing = isLeft ? "right" : "left";
908d07d Rick Waldron Adds new ED/Biped program
authored
219
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
220 // Begin stepping movements.
221 //
908d07d Rick Waldron Adds new ED/Biped program
authored
222 this.queue([
223
224 // Phase 1
225 {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
226 wait: 500,
908d07d Rick Waldron Adds new ED/Biped program
authored
227 task: function() {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
228 var stepping, opposing, instruct;
908d07d Rick Waldron Adds new ED/Biped program
authored
229
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
230 stepping = isLeft ? "left" : "right";
231 opposing = isLeft ? "right" : "left";
908d07d Rick Waldron Adds new ED/Biped program
authored
232
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
233 instruct = {};
908d07d Rick Waldron Adds new ED/Biped program
authored
234
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
235 // Lift the currently stepping foot, while
236 // leaning on the currently opposing foot.
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
237 instruct[stepping] = {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
238 foot: isLeft ? 40 : 140
239 };
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
240 instruct[opposing] = {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
241 foot: isLeft ? 70 : 110
242 };
908d07d Rick Waldron Adds new ED/Biped program
authored
243
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
244 // Swing currently stepping hips
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
245 this.move(instruct);
908d07d Rick Waldron Adds new ED/Biped program
authored
246 }.bind(this)
247 },
248
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
249 // Phase 2
908d07d Rick Waldron Adds new ED/Biped program
authored
250 {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
251 wait: 500,
908d07d Rick Waldron Adds new ED/Biped program
authored
252 task: function() {
bd26733 Rick Waldron Re-render all allowed example programs. Fixes gh-65
authored
253 var degrees = isLeft ?
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
254 (isFwd ? 120 : 60) :
255 (isFwd ? 60 : 120);
908d07d Rick Waldron Adds new ED/Biped program
authored
256
257 // Swing currently stepping hips
258 this.move({
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
259 type: "swing",
908d07d Rick Waldron Adds new ED/Biped program
authored
260 right: {
261 hip: degrees
262 },
263 left: {
264 hip: degrees
265 }
266 });
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
267
268 }.bind(this)
269 },
270
271 // Phase 3
272 {
273 wait: 500,
274 task: function() {
275
276 // Flatten feet to surface
277 this.servos.right.foot.center();
278 this.servos.left.foot.center();
279
280
281
908d07d Rick Waldron Adds new ED/Biped program
authored
282 }.bind(this)
283 }
284 ]);
285 };
286
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
287 [
288 /**
289 * forward, fwd
290 *
291 * Move the bot forward
292 */
293 {
294 name: "forward",
295 abbr: "fwd"
296 },
297
298 /**
299 * reverse, rev
300 *
301 * Move the bot in reverse
302 */
303 {
304 name: "reverse",
305 abbr: "rev"
306 }
908d07d Rick Waldron Adds new ED/Biped program
authored
307
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
308 ].forEach(function(dir) {
908d07d Rick Waldron Adds new ED/Biped program
authored
309
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
310 ED.prototype[dir.name] = ED.prototype[dir.abbr] = function() {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
311 var startAt, stepper, state;
908d07d Rick Waldron Adds new ED/Biped program
authored
312
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
313 startAt = 10;
314 state = priv.get(this);
315
316 // If ED is already walking in this direction, return immediately;
317 // This prevents multiple movement loops from being scheduled.
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
318 if (this.direction === dir.abbr && state.isWalking) {
bd26733 Rick Waldron Re-render all allowed example programs. Fixes gh-65
authored
319 return;
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
320 }
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
321
322 // If a sequence reference exists, kill it. This will
323 // clear all pending queue repeaters.
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
324 if (this.sequence) {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
325 this.sequence.stop();
326 this.sequence = null;
327 }
328
329
330 this.direction = dir.abbr;
331
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
332 // Update the private state to indicate
333 // that the bot is currently walking.
334 //
335 // This is used by the behaviour loop to
336 // conditionally continue walking or to terminate.
337 //
338 // Walk termination occurs in the ED.prototype.attn method
339 //
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
340 priv.set(this, {
341 isWalking: true
342 });
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
343
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
344 stepper = function(loop) {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
345 // Capture of sequence queue reference
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
346 if (this.sequence === null) {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
347 this.sequence = loop;
348 }
349
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
350 this.step(dir.abbr);
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
351
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
352 if (!priv.get(this).isWalking) {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
353 loop.stop();
354 }
355 }.bind(this);
356
357 // If the bot is not centered, ie. all servos at 90degrees,
358 // bring the bot to attention before proceeding.
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
359 if (!this.isCentered) {
360 this.attn({
361 isWalking: true
362 });
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
363 // Offset the amount ms required for attn() to complete
364 startAt = 750;
365 }
bd26733 Rick Waldron Re-render all allowed example programs. Fixes gh-65
authored
366
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
367 this.queue([{
368 wait: startAt,
369 task: function() {
370 this.step(dir.abbr);
371 }.bind(this)
372 }, {
373 loop: 1500,
374 task: stepper
375 }]);
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
376 };
377 });
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
378
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
379 ED.prototype.dance = function() {
69e7e33 Rick Waldron Variety of doc-oriented updateds
authored
380 var isLeft, restore, state;
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
381
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
382 // Derive which side to step on; based on last step or explicit step
383 this.side = this.side !== "right" ? "right" : "left";
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
384
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
385 // Determine if this is the left foot
386 // Used in phase 3 to conditionally control the servo degrees
387 isLeft = this.side === "left";
388
389 this.attn();
390
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
391 if (typeof this.moves === "undefined") {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
392 this.moves = 0;
393 }
394
395 this.queue([
396 // Phase 1
397 {
398 wait: 500,
399 task: function() {
400 var degrees = isLeft ? 120 : 60;
401
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
402 if (this.moves % 2 === 0) {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
403 this.move({
404 type: "attn",
405 right: {
406 hip: 90,
407 foot: 60
408 },
409 left: {
410 hip: 90,
411 foot: 120
412 }
413 });
414 } else {
415
416 this.move({
417 type: "attn",
418 right: {
419 hip: 90,
420 foot: 120
421 },
422 left: {
423 hip: 90,
424 foot: 60
425 }
426 });
427 }
428
429 // Swing currently stepping hips
430 this.move({
431 type: "swing",
432 right: {
433 hip: degrees
434 },
435 left: {
436 hip: degrees
437 }
438 });
439
440 // restore = this.servos[ this.side ].foot.last.degrees;
441 // this.servos[ this.side ].foot.move( restore === 140 ? 120 : 60 );
442
443 }.bind(this)
444 },
445
446 // Phase 2
447 {
448 wait: 500,
449 task: function() {
450 var degrees = isLeft ? 60 : 120;
451
452 // Swing currently stepping hips
453 this.move({
454 type: "swing",
455 right: {
456 hip: degrees
457 },
458 left: {
459 hip: degrees
460 }
461 });
462
463 // this.servos[ this.side ].foot.move( restore );
464
465 }.bind(this)
466 },
467
468 // Phase 3
469 {
470 wait: 500,
471 task: function() {
472
473 this.move({
474 type: "attn",
475 right: {
476 hip: 90,
477 foot: 90
478 },
479 left: {
480 hip: 90,
481 foot: 90
482 }
483 });
484
485 this.dance();
486
487 }.bind(this)
488 }
489 ]);
490
491 this.moves++;
492 };
908d07d Rick Waldron Adds new ED/Biped program
authored
493
494
495 /**
496 * move Move the bot in an arbitrary direction
497 * @param {Object} positions left/right hip/foot positions
498 *
499 */
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
500 ED.prototype.move = function(positions) {
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
501 var start, type;
908d07d Rick Waldron Adds new ED/Biped program
authored
502
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
503 if (this.history.length) {
504 start = this.history[this.history.length - 1];
908d07d Rick Waldron Adds new ED/Biped program
authored
505 }
506
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
507 type = positions.type || "step";
508
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
509 ["foot", "hip"].forEach(function(section) {
510 ["right", "left"].forEach(function(side) {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
511 var interval, endAt, startAt, servo, step, s;
512
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
513 if (typeof positions[side] === "undefined") {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
514 return;
515 }
908d07d Rick Waldron Adds new ED/Biped program
authored
516
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
517 endAt = positions[side][section];
518 servo = this.servos[side][section];
519 startAt = this.degrees[side][section];
908d07d Rick Waldron Adds new ED/Biped program
authored
520
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
521 // Degrees per step
522 step = 2;
908d07d Rick Waldron Adds new ED/Biped program
authored
523
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
524 s = Date.now();
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
525
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
526 if (!endAt || endAt === startAt) {
908d07d Rick Waldron Adds new ED/Biped program
authored
527 return;
528 }
529
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
530 if (start) {
908d07d Rick Waldron Adds new ED/Biped program
authored
531 // Determine degree step direction
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
532 if (endAt < startAt) {
908d07d Rick Waldron Adds new ED/Biped program
authored
533 step *= -1;
534 }
535
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
536 // Repeat each step for required number of steps to move
537 // servo into new position. Each step is ~20ms duration
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
538 this.repeat(Math.abs(endAt - startAt) / 2, 10, function() {
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
539 // console.log( startAt );
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
540 servo.move(startAt += step);
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
541
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
542 if (startAt === endAt) {
543 this.times[type] = (this.times[type] + (Date.now() - s)) / 2;
908d07d Rick Waldron Adds new ED/Biped program
authored
544 }
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
545 }.bind(this));
908d07d Rick Waldron Adds new ED/Biped program
authored
546
547 } else {
548 // TODO: Stop doing this
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
549 servo.move(endAt);
908d07d Rick Waldron Adds new ED/Biped program
authored
550 five.Fn.sleep(500);
551 }
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
552 }, this);
553 }, this);
908d07d Rick Waldron Adds new ED/Biped program
authored
554
555 // Push a record object into the stepping history
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
556 this.history.push({
557 timestamp: Date.now(),
558 side: this.side,
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
559 right: five.Fn.extend({
560 hip: 0,
561 foot: 0
562 }, this.degrees.right, positions.right),
563 left: five.Fn.extend({
564 hip: 0,
565 foot: 0
566 }, this.degrees.left, positions.left)
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
567 });
908d07d Rick Waldron Adds new ED/Biped program
authored
568 };
569
570 // Borrow API from Compulsive
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
571 ["wait", "loop", "queue", "repeat"].forEach(function(api) {
572 ED.prototype[api] = compulsive[api];
908d07d Rick Waldron Adds new ED/Biped program
authored
573 });
574
575 // Begin program when the board, serial and
576 // firmata are connected and ready
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
577 (new five.Board()).on("ready", function() {
578 var biped;
908d07d Rick Waldron Adds new ED/Biped program
authored
579
580 // Create new Enforcement Droid
581 // assign servos
582 biped = new ED({
583 right: {
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
584 hip: 9,
585 foot: 11
908d07d Rick Waldron Adds new ED/Biped program
authored
586 },
587 left: {
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
588 hip: 10,
589 foot: 12
908d07d Rick Waldron Adds new ED/Biped program
authored
590 }
591 });
592
593 // Inject into REPL for manual controls
594 this.repl.inject({
6261f23 Rick Waldron Switch to matching servos for Biped/ED hip joints; walking.
authored
595 s: new five.Servo.Array(),
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
596 b: biped
597 });
598
599 biped.attn();
600
601 biped.wait(1000, function() {
602 biped.fwd();
908d07d Rick Waldron Adds new ED/Biped program
authored
603 });
604
605 // Controlled via REPL:
764e562 Rick Waldron ED as seen at EmpireJS and CascadiaJS
authored
606 // b.fwd(), b.rev(), b.attn()
908d07d Rick Waldron Adds new ED/Biped program
authored
607 });
608
609
610
611 // http://www.lynxmotion.com/images/html/build112.htm
612
613 ```
614
615
938e295 Rick Waldron Removes @device tags and replaces with arbitrary @markdown regions
authored
616 ## Breadboard/Illustration
908d07d Rick Waldron Adds new ED/Biped program
authored
617
618
938e295 Rick Waldron Removes @device tags and replaces with arbitrary @markdown regions
authored
619 ![docs/breadboard/ed.png](breadboard/ed.png)
908d07d Rick Waldron Adds new ED/Biped program
authored
620
621
622
623
329525f Rick Waldron Add removal delimiters to eg template. Update examples
authored
624 <!--remove-start-->
908d07d Rick Waldron Adds new ED/Biped program
authored
625 ## License
8c167ba Rick Waldron Update copyright year
authored
626 Copyright (c) 2012, 2013, 2014 Rick Waldron <waldron.rick@gmail.com>
6ee1faa Rick Waldron Regenerate the docs examples
authored
627 Licensed under the MIT license.
8c167ba Rick Waldron Update copyright year
authored
628 Copyright (c) 2014, 2015 The Johnny-Five Contributors
908d07d Rick Waldron Adds new ED/Biped program
authored
629 Licensed under the MIT license.
329525f Rick Waldron Add removal delimiters to eg template. Update examples
authored
630 <!--remove-end-->
Something went wrong with that request. Please try again.