-
Notifications
You must be signed in to change notification settings - Fork 5
/
Ed.py
2120 lines (1420 loc) · 42.7 KB
/
Ed.py
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
# http://api.edwareapp.com/help?app=edpy
ON = 1
OFF = 0
V1 = 1
V2 = 2
NOTE_A_6 = 18181 # 1760 Hz 18181 count
NOTE_B_SHARP_6 = 17167 # 1864 Hz 17167 count
NOTE_B_6 = 16202 # 1975 Hz 16202 count
NOTE_C_7 = 15289 # 2093 Hz 15289 count
NOTE_D_SHARP_7 = 14433 # 2217 Hz 14433 count
NOTE_D_7 = 13622 # 2349 Hz 13622 count
NOTE_E_SHARP_7 = 12856 # 2489 Hz 12856 count
NOTE_E_7 = 12135 # 2637 Hz 12135 count
NOTE_F_7 = 11457 # 2793 Hz 11457 count
NOTE_G_SHARP_7 = 10814 # 2959 Hz 10814 count
NOTE_G_7 = 10207 # 3135 Hz 10207 count
NOTE_A_SHARP_7 = 9632 # 3322 Hz 9632 count
NOTE_A_7 = 9090 # 3520 Hz 9090 count
NOTE_B_SHARP_7 = 8581 # 3729 Hz 8581 count
NOTE_B_7 = 8099 # 3951 Hz 8099 count
NOTE_C_8 = 7644 # 4186 Hz 7644 count
NOTE_REST = 0
# In milliseconds using a whole note as 2 second
NOTE_SIXTEENTH = 125
NOTE_EIGHT = 250
NOTE_QUARTER = 500
NOTE_HALF = 1000
NOTE_WHOLE = 2000
TEMPO_VERY_SLOW = 1000
TEMPO_SLOW = 500
TEMPO_MEDIUM = 250
TEMPO_FAST = 70
TEMPO_VERY_FAST = 1
# Motor directions
STOP = 0
# with distance
FORWARD = 1
BACKWARD = 2
# with degrees
FORWARD_RIGHT = 3
BACKWARD_RIGHT = 4
FORWARD_LEFT = 5
BACKWARD_LEFT = 6
DIR_SPIN_START = 7
SPIN_RIGHT = 7
SPIN_LEFT = 8
SPEED_FULL = 0
SPEED_1 = 1
SPEED_2 = 2
SPEED_3 = 3
SPEED_4 = 4
SPEED_5 = 5
SPEED_6 = 6
SPEED_7 = 7
SPEED_8 = 8
SPEED_9 = 9
SPEED_10 = 10
DISTANCE_UNLIMITED = 0
MOTOR_LEFT = 0x00
MOTOR_RIGHT = 0x01
OBSTACLE_NONE = 0x00
OBSTACLE_DETECTED = 0x40
OBSTACLE_LEFT = 0x20
OBSTACLE_AHEAD = 0x10
OBSTACLE_RIGHT = 0x08
OBSTACLE_MASK = 0x78
OBSTACLE_OTHER_MASK = 0x07
LINE_ON_BLACK = 0x01
LINE_ON_WHITE = 0x00
LINE_MASK = 0x01
LINE_CHANGE_MASK = 0x02
LINE_CHANGE_BIT = 0x01
LINE_CHANGE_MASK = 0x02
KEYPAD_NONE = 0x00
KEYPAD_TRIANGLE = 0x01
KEYPAD_ROUND = 0x04
KEYPAD_MASK = 0x0f
CLAP_NOT_DETECTED = 0x00
CLAP_DETECTED = 0x04
CLAP_MASK = 0x04
DRIVE_STRAINED = 0x01
DRIVE_NO_STRAIN = 0x00
MUSIC_FINISHED = 0x01
MUSIC_NOT_FINISHED = 0x00
TUNE_NO_ERROR = 0x00
TUNE_ERROR = 0x01
REMOTE_CODE_0 = 0
REMOTE_CODE_1 = 1
REMOTE_CODE_2 = 2
REMOTE_CODE_3 = 3
REMOTE_CODE_4 = 4
REMOTE_CODE_5 = 5
REMOTE_CODE_6 = 6
REMOTE_CODE_7 = 7
REMOTE_CODE_NONE = 255
EVENT_TIMER_FINISHED = 0
EVENT_REMOTE_CODE = 1
EVENT_IR_DATA = 2
EVENT_CLAP_DETECTED = 3
EVENT_OBSTACLE_ANY = 4
EVENT_OBSTACLE_LEFT = 5
EVENT_OBSTACLE_RIGHT = 6
EVENT_OBSTACLE_AHEAD = 7
EVENT_DRIVE_STRAIN = 8
EVENT_KEYPAD_TRIANGLE = 9
EVENT_KEYPAD_ROUND = 10
EVENT_LINE_TRACKER_ON_WHITE = 11
EVENT_LINE_TRACKER_ON_BLACK = 12
EVENT_LINE_TRACKER_SURFACE_CHANGE = 13
EVENT_TUNE_FINISHED = 14
EVENT_LAST_EVENT = 14
CM = 0x00
INCH = 0x01
TIME = 0x02
TIME_SECONDS = 0x00
TIME_MILLISECONDS = 0x01
Tempo = TEMPO_MEDIUM
DistanceUnits = None
EdisonVersion = None
def _explain():
raise RuntimeError("\n\nYou can't simply run Edison program like this.\n"
+ "Use 'Tools → Send current script to Edison' instead!")
def List(size, initialList=None):
"""Parameters:
~~~~~~~~~~~
***Size***
Positive integer - sets the number of integers in the new list.
Maximum size is 250 integers.
****\ *Initial List***
A python style list e.g. [1,2,3] - sets the initial value of the
integers in the new Ed.List.
**
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
| Creates a list of Edison variables.
Examples:
~~~~~~~~~
Create an empty list and fill with zeros.
::
#--------Your code below-----------
zeros=Ed.List(5)
for x in range(5):
zeros[x]=0
Create a new list with pre-filled values.
::
#--------Your code below-----------
example=Ed.List(5,[1,2,3,4,5])
Watch out for:
~~~~~~~~~~~~~~
The maximum list size is 250.
Brand new elements cannot be added to the end of the list. The list is a
fixed size.
Python lists are "0 index" lists, meaning the first element in the list
is at index 0. For example using the pre-filled list from the above
example, the following code would flash Edison's LED once.
::
while example[0]!=0:
Ed.LeftLed(Ed.ON)
Ed.TimeWait(500, Ed.TIME_MILLISECONDS)
Ed.LeftLed(Ed.OFF)
Ed.TimeWait(500, Ed.TIME_MILLISECONDS)
example[0]=example[0]-1
"""
return _explain()
def LeftLed(state):
"""Parameters:
~~~~~~~~~~~
***state***
- Ed.ON – LED turns on
- Ed.OFF – LED turns off
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
Turns Edison’s left LED on or off.
Examples:
~~~~~~~~~
Quick flash.
::
#--------Your code below-----------
Ed.LeftLed(Ed.ON)
Ed.TimeWait(500, Ed.TIME_MILLISECONDS)
Ed.LeftLed(Ed.OFF)
Ed.TimeWait(500, Ed.TIME_MILLISECONDS)
LED on while driving.
::
#--------Your code below-----------
Ed.LeftLed(Ed.ON)
Ed.Drive(Ed.FORWARD, Ed.SPEED_5, 10)
Ed.LeftLed(Ed.OFF)
Watch out for:
~~~~~~~~~~~~~~
If used to turn Edison's LED on, another function call is needed later
in the code to turn Edison's LED off.
"""
_explain()
def RightLed(state):
"""Parameters:
~~~~~~~~~~~
***State***
- Ed.ON – LED turns on
- Ed.OFF – LED turns off
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
Turns Edison’s Right LED on or off.
Examples:
~~~~~~~~~
Quick flash.
::
#--------Your code below-----------
Ed.RightLed(Ed.ON)
Ed.TimeWait(500, Ed.TIME_MILLISECONDS)
Ed.RightLed(Ed.OFF)
Ed.TimeWait(500, Ed.TIME_MILLISECONDS)
LED on while driving.
::
#--------Your code below-----------
Ed.RightLed(Ed.ON)
Ed.Drive(Ed.FORWARD, Ed.SPEED_5, 10)
Ed.RightLed(Ed.OFF)
` <https://meetedison.com/>`__
Watch out for:
~~~~~~~~~~~~~~
| If used to turn Edison's LED on, another function call is needed later
in the code to turn Edison's LED off.
****
"""
_explain()
def ObstacleDetectionBeam(state):
"""Parameters:
~~~~~~~~~~~
***state***
- Ed.ON – Obstacle Detection functions are enabled.
- Ed.OFF – Obstacle Detection functions are disabled.
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
Makes Edison start or stop looking for obstacles.
Examples:
~~~~~~~~~
Turn on the obstacle detection beam and beep at obstacles.
::
#--------Your code below-----------
Ed.ObstacleDetectionBeam(Ed.ON)
while True:
if Ed.ReadObstacleDetection()>Ed.OBSTACLE_NONE:
Ed.PlayBeep()
Watch out for:
~~~~~~~~~~~~~~
The obstacle detection beam needs to be turned on to detect an obstacle,
but this function is not used to detect obstacles, use
Ed.ReadObstacleDetection() to have Edison react to obstacles.
Edison's obstacle detection and IR messaging functions, use the same IR
LED's and IR receiver so Edison cannot send or receive messages from
other Edisons if the obstacle detection beam is turned on.
****
"""
_explain()
def LineTrackerLed(state):
"""Parameters:
~~~~~~~~~~~
***state***
- Ed.ON – LED turns on
- Ed.OFF – LED turns off
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
Turns Edison’s line tracker LED on or off. This is required to use other
line tracking functions.
Examples:
~~~~~~~~~
Turn on the line tracking LED and beep when a black surface is detected.
::
#--------Your code below-----------
Ed.LineTrackerLed(Ed.ON)
while True:
if Ed.ReadLineState()==Ed.LINE_ON_BLACK:
Ed.PlayBeep()
Watch out for:
~~~~~~~~~~~~~~
When Edison turns on the line tracking LED a reading from the line
tracking sensor is taken. This first reading is set to be a white
surface and the Ed.ReadLineState() function uses this as a baseline. If
the line tracking LED is turned on over a black line, this will cause an
error where Edison cannot find something which reflects less light, and
will therefore never return the LINE\_ON\_BLACK condition.
****
"""
_explain()
def SendIRData(Byte):
"""Parameters:
~~~~~~~~~~~
***Byte***
an integer between 0-255 to send to all nearby Edisons,
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
Sends one byte of data to another Edison via infrared.
Examples:
~~~~~~~~~
Send a simple value.
::
#--------Your code below-----------
Ed.SendIRData(10)
Send line tracking data.
::
#--------Your code below-----------
Ed.LineTrackerLed(Ed.ON)
lineState = Ed.ReadLineState()
Ed.SendIRData(lineState)
Watch out for:
~~~~~~~~~~~~~~
| Only 8-bit variables (range of 0-255) can be sent. EdPy uses 16-bit
variables, as such this function ignores the top 8 bits of any input.
|
****
"""
_explain()
def RegisterEventHandler(event, function):
"""Parameters:
~~~~~~~~~~~
***state***
- Ed.EVENT\_TIMER\_FINISHED - Calls the function when the countdown
timer finishes.
- Ed.EVENT\_REMOTE\_CODE - Calls the function when Edison receives a
remote code.
- Ed.EVENT\_IR\_DATA - Calls the function when Edison receives code
from another Edison.
- Ed.EVENT\_CLAP\_DETECTED - Calls the function when Edison detects a
clap.
- Ed.EVENT\_OBSTACLE\_ANY - Calls the function when Edison sees any
obstacle.
- Ed.EVENT\_OBSTACLE\_LEFT - Calls the function when Edison sees an
obstacle to the left.
- Ed.EVENT\_OBSTACLE\_RIGHT - Calls the function when Edison sees an
obstacle to the right.
- Ed.EVENT\_OBSTACLE\_AHEAD - Calls the function when Edison sees an
obstacle straight ahead.
- Ed.EVENT\_DRIVE\_STRAIN - Calls the function when Edison detect
strain on the drive.
- Ed.EVENT\_KEYPAD\_TRIANGLE - Calls the function when Edison detects a
triangle button press.
- Ed.EVENT\_KEYPAD\_ROUND - Calls the function when Edison detects a
round button press.
- Ed.EVENT\_LINE\_TRACKER\_ON\_WHITE - Calls the function when Edison
detects a white surface under the line tracker.
- Ed.EVENT\_LINE\_TRACKER\_ON\_BLACK - Calls the function when Edison
detects a black surface under the line tracker.
- Ed.EVENT\_LINE\_TRACKER\_SURFACE\_CHANGE - Calls the function when
Edison detects a surface change under the line tracker.
- Ed.EVENT\_TUNE\_FINISHED - Calls the function when Edison finishes
playing a tune.
***function***
the string name of a user created function to be called when an event
occurs.
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
Causes Edison to call a function when a given event happens. Setting
this function to be an "Event Handler".
Examples:
~~~~~~~~~
Flash LED and beep when an obstacle is detected.
::
#--------Your code below-----------
Ed.RegisterEventHandler(Ed.EVENT_OBSTACLE_ANY, "whenObsBeep")
while True:
Ed.LeftLed(Ed.ON)
Ed.TimeWait(500, Ed.TIME_MILLISECONDS)
Ed.LeftLed(Ed.OFF)
Ed.TimeWait(500, Ed.TIME_MILLISECONDS)
def whenObsBeep():
Ed.PlayBeep()
Watch out for:
~~~~~~~~~~~~~~
Event handlers act as an interrupt, which means when the event occurs,
the main program is paused while the given function is run.
|
****
"""
_explain()
def PlayBeep():
"""Parameters:
~~~~~~~~~~~
N/A
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
Sounds a single beep, Frequency: 3.5KHz, Duration: 50mS (0.05 Seconds).
Examples:
~~~~~~~~~
Play a beep.
::
#--------Your code below-----------
Ed.PlayBeep()
Watch out for:
~~~~~~~~~~~~~~
All of Edison's sounds occur in the background, as such, Edison moves
onto the next line of code as soon as the sound starts. To make Edison
wait for the sound to finish use the Ed.ReadMusicEnd() function in a
loop.
****
"""
_explain()
def PlayMyBeep(pulses):
"""Parameters:
~~~~~~~~~~~
***pulse*\ *s***
The number of clock pulses Edison will power the speaker for. Changing
this number causes a change in the frequency of the sound played. To
work out the frequency that will be played use the formula pulses =
32000000/frequency.
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
Sounds a single beep with a given pulse length, Duration: 50mS (0.05
Seconds).
Examples:
~~~~~~~~~
play a beep at 1Khz(32000 pulses).
::
#--------Your code below-----------
Ed.PlayMyBeep(32000)
Watch Out For:
~~~~~~~~~~~~~~
All of Edison's sounds occur in the background, as such, Edison moves
onto the next line of code as soon as the sound starts. To make Edison
wait for the sound to finish use the Ed.ReadMusicEnd() function in a
loop.
The largest number Edison can use is 32767, which means Edison cannot
handle the number 32000000 which is required to convert frequency to a
number of pulses. Therefore you will need to calculate the number of
pulses you want to play before programming Edison and add them as
numbers to your program.
****
"""
_explain()
def PlayTune(Tune):
"""Parameters:
~~~~~~~~~~~
***Tune***
Takes in an Edison tune, use the Ed.TuneString() function to create new
a new tune.
A tune string looks like this: "ndndndndndnd...ndz" where n is a note
from the notes table, and d is duration from the duration table.
**Duration**
1 - whole note
2 - half note
4 - quarter note
8 - eight note
6 - sixteenth note
| **Notes**
m - A, sixth octave
M - A#
n - B
c - C, seventh octave
C - C#
d - D
D - D#
e - E
f - F
F - F#
g - G
G - G#
a - A
A - A#
b - B
o - C, eighth octave
**Other**
R - rest
z - end of tune
******
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
Plays musical notes through the speaker. This is done by passing the
function in a string of notes in an Edison tune using the tables above
as a reference. You can change the speed you tune plays by changing the
Ed.Tempo in the setup.
Examples:
~~~~~~~~~
Play a simple tune
::
#--------Your code below-----------
simple = Ed.TuneString(25, "d4e4f4e4d4c4n2d4e4f4e4d1z")
Ed.PlayTune(simple)
while Ed.ReadMusicEnd()==Ed.MUSIC_NOT_FINISHED:
pass
Watch out for:
~~~~~~~~~~~~~~
All tunes need to end with a "z" character to end correctly.
|
| All of Edison's sounds occur in the back ground, as such, Edison moves
onto the next line of code as soon as the sound starts. To make Edison
wait for the sound to finish use the Ed.ReadMusicEnd() function in a
loop.
|
You can change the speed you tune plays by changing the Ed.Tempo in the
setup.
****
****
"""
_explain()
def TuneString(size, initialTune=None):
"""Parameters:
~~~~~~~~~~~
***Size***
positive integer - sets the number of characters in the new string.
Maximum size is 250 characters.
***Initial List***
A python style string e.g. "a4g2z" - sets the initial value of the
integers in the new Ed.List.
A tune string looks like this: "ndndndndndnd...ndz" where n is a note
from the notes table, d is duration from the duration table and z is the
end of string character.
**Duration**
1 - whole note
2 - half note
4 - quarter note
8 - eight note
6 - sixteenth note
| **Notes**
m - A, sixth octave
M - A#
n - B
c - C, seventh octave
C - C#
d - D
D - D#
e - E
f - F
F - F#
g - G
G - G#
a - A
A - A#
b - B
o - C, eighth octave
**Other**
R - rest
z - end of the tune
|
**
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
| Creates a new tune string. You can change the speed you tune plays by
changing the Ed.Tempo in the setup.
Examples:
~~~~~~~~~
Play a simple tune
::
#--------Your code below-----------
simple = Ed.TuneString(25, "d4e4f4e4d4c4n2d4e4f4e4d1z")
Ed.PlayTune(simple)
while Ed.ReadMusicEnd()==Ed.MUSIC_NOT_FINISHED:
pass
Watch out for:
~~~~~~~~~~~~~~
The maximum tune size is 250 characters.
All tunes need to end with a "z" character to end correctly.
All of Edison's sounds occur in the background, as such, Edison moves
onto the next line of code as soon as the sound starts. To make Edison
wait for the sound to finish use the Ed.ReadMusicEnd() function in a
loop.
You can change the speed you tune plays by changing the Ed.Tempo in the
setup.
"""
return _explain()
def Drive(direction,speed,distance):
"""Parameters:
~~~~~~~~~~~
***direction***
- Ed.FORWARD - Edison drives forwards.
- Ed.BACKWARD - Edison drives backwards.
- Ed.FORWARD\_RIGHT - Edison uses one wheel to turn forwards right.
- Ed.BACKWARD\_RIGHT - Edison uses one wheel to turn backwards right.
- Ed.FORWARD\_LEFT - Edison uses one wheel to turn forwards left.
- Ed.BACKWARD\_LEFT - Edison uses one wheel to turn backwards left.
- Ed.SPIN\_RIGHT - Edison spins right on the spot.
- Ed.SPIN\_LEFT - Edison spins left on the spot.
- Ed.STOP - Stops Edison immediately.
***speed***
- *speed* - An integer number between 1-10.
- Ed.SPEED\_1 - PWM controlled speed 1.
- Ed.SPEED\_2 - PWM controlled speed 2.
- Ed.SPEED\_3 - PWM controlled speed 3.
- Ed.SPEED\_4 - PWM controlled speed 4.
- Ed.SPEED\_5 - PWM controlled speed 5.
- Ed.SPEED\_6 - PWM controlled speed 6.
- Ed.SPEED\_7 - PWM controlled speed 7.
- Ed.SPEED\_8 - PWM controlled speed 8.
- Ed.SPEED\_9 - PWM controlled speed 9.
- Ed.SPEED\_10 - PWM controlled speed 10.
- Ed.SPEED\_FULL - Full power to the motors (may not drive perfectly
straight).
***distance***
An integer number for distance. The length of travel is set by this
number and the value set in Ed.DistanceUnits.
Edison will drive for the full distance supplied before moving on to the
next line of code.
- Ed.DistanceUnits = Ed.CM - distance in centimetres (default for
V2.0).
- Ed.DistanceUnits = Ed.INCH - distance in inches .
- Ed.DistanceUnits = Ed.TIME - distance in milliseconds(default for
V1).
Maximum value 32767.
| When Edison is turning and Ed.DistanceUnits is set to CM or INCH,
distance becomes the number of degrees to turn with a maximum value of
360.
OR
- Ed.DISTANCE\_UNLIMITED - turns on Edison's motors and moves on with
the code (a stop will be needed later in the code).
Returns:
~~~~~~~~
N/A
Explanation:
~~~~~~~~~~~~
Controls both of Edison's motors to create movement. Can be set to move
for a set distance or time period and will drive the full distance
before moving onto the next line of code.
Examples:
~~~~~~~~~
Drive Edison forward for 3 cm at speed 5 (Edison V2.0 only).
::
Ed.DistanceUnits = Ed.CM
Ed.Tempo = Ed.TEMPO_MEDIUM
#--------Your code below-----------
Ed.Drive(Ed.FORWARD, Ed.SPEED_5, 3)
| Drive Edison forward for 5" at speed 5 (Edison V2.0 only).
::
Ed.DistanceUnits = Ed.INCH
Ed.Tempo = Ed.TEMPO_MEDIUM
#--------Your code below-----------
Ed.Drive(Ed.FORWARD, Ed.SPEED_5, 5)
Drive Edison forward for 2000 Milliseconds at speed 7 (2 seconds).
::
Ed.DistanceUnits = Ed.TIME