-
Notifications
You must be signed in to change notification settings - Fork 2
/
testmotor.m
69 lines (64 loc) · 1.63 KB
/
testmotor.m
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
prompt = 'Input Distance(cms)';
dist = str2double(inputdlg(prompt));
t=(dist/7.5);
disp(t);
st(t)
function st(d)
%Connection and motor assigning
mylego = legoev3('bt','00165344463c');
%mylego = legoev3('Bluetooth', 'COM3');
%mylego = legoev3('USB')
mymotor1 = motor(mylego, 'A');
mymotor2 = motor(mylego, 'B');
mysensor = gyroSensor(mylego, 1)
angle = readRotationAngle(mysensor)
disp('THe angle is,'); disp(angle);
%speed assigning
PERIOD = 1/8;
SPEED = 50;
%motor init
mymotor1.Speed = SPEED;
mymotor2.Speed = SPEED;
resetRotation(mymotor1);
resetRotation(mymotor2);
pause(PERIOD);
%motor loop
for i=0:d
start(mymotor1);
start(mymotor2);
rotation1=readRotation(mymotor1)
disp(rotation1)
rotation2 = readRotation(mymotor2)
disp(rotation2)
end
pause(d);
stop(mymotor1);
stop(mymotor2);
end
function rv(d)
%Connection and motor assigning
mylego = legoev3('bt','00165344463c');
mymotor1 = motor(mylego, 'A');
mymotor2 = motor(mylego, 'B');
%speed assigning
PERIOD = 1/8;
SPEED = -50;
%motor init
mymotor1.Speed = SPEED;
mymotor2.Speed = SPEED;
resetRotation(mymotor1);
resetRotation(mymotor2);
pause(PERIOD);
%motor loop
for i=0:d
start(mymotor1);
start(mymotor2);
rotation1=readRotation(mymotor1)
disp(rotation1)
rotation2 = readRotation(mymotor2)
disp(rotation2)
end
pause(d);
stop(mymotor1);
stop(mymotor2);
end