-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovement.py
142 lines (108 loc) · 2.92 KB
/
movement.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
#!/usr/bin/env python3
'''Hello to the world from ev3dev.org'''
import os
import sys
from time import *
# state constants
ON = True
OFF = False
def forward(left_motor, right_motor):
left_motor.on(50)
right_motor.on(50)
sleep(1)
left_motor.off()
right_motor.off()
def right(left_motor, right_motor):
left_motor.on(25)
right_motor.on(0)
sleep(2)
left_motor.off()
right_motor.off()
def left(left_motor, right_motor):
left_motor.on(0)
right_motor.on(25)
sleep(2)
left_motor.off()
right_motor.off()
def debug_print(*args, **kwargs):
'''Print debug messages to stderr.
This shows up in the output panel in VS Code.
'''
print(*args, **kwargs, file=sys.stderr)
def reset_console():
'''Resets the console to the default state'''
print('\x1Bc', end='')
def set_cursor(state):
'''Turn the cursor on or off'''
if state:
print('\x1B[?25h', end='')
else:
print('\x1B[?25l', end='')
def set_font(name):
'''Sets the console font
A full list of fonts can be found with `ls /usr/share/consolefonts`
'''
os.system('setfont ' + name)
def main():
'''The main function of our program'''
# set the console just how we want it
reset_console()
set_cursor(OFF)
set_font('Lat15-Terminus24x12')
# print something to the screen of the device
print('Hello World!')
# print something to the output panel in VS Code
debug_print('Hello VS Code!')
# wait a bit so you have time to look at the display before the program
# exits
time.sleep(5)
#!/usr/bin/env python3
from ev3dev.ev3 import *
from ev3dev2.motor import *
from ev3dev2.sensor.lego import *
from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3, INPUT_4
os.system('setfont Lat15-TerminusBold14')
mL = LargeMotor('outB'); mL.stop_action = 'hold'
mR = LargeMotor('outC'); mR.stop_action = 'hold'
"""print('Hello, my name is EV3!')
Sound.speak('Hello master Bram, I am the mystery machine!').wait()
mL.run_to_rel_pos(position_sp= 840, speed_sp = 500)
mR.run_to_rel_pos(position_sp= 840, speed_sp = 500)
mL.wait_while('running')
mR.wait_while('running')"""
#intiating the sensors
l1 = ColorSensor(INPUT_2)
l2 = ColorSensor(INPUT_3)
la = l1.reflected_light_intensity
lb = l2.reflected_light_intensity
print("la_initial",la)
print("lb_initial",lb)
forward(mL,mR)
right(mL,mR)
forward(mL,mR)
left(mL,mR)
forward(mL,mR)
left(mL,mR)
forward(mL,mR)
left(mL,mR)
forward(mL,mR)
left(mL,mR)
forward(mL,mR)
right(mL,mR)
forward(mL,mR)
right(mL,mR)
forward(mL,mR)
"""t = 0
while t=0:
if(l1.reflected_light_intensity > la and l2.reflected_light_intensity() > lb):
print('We are crossing spaces')
else:
mL.on(-8)
mR.on(-8)
print('We are in a grid space')
print("l1",l1.reflected_light_intensity)
print("l2",l2.reflected_light_intensity)
sleep(1)
t+=1"""
#if __name__ == '__main__':
#main()