-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprocket_v2.m
177 lines (135 loc) · 5.63 KB
/
sprocket_v2.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
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
%MOST RECENT
%TODO:
% MoveMotor() is utilized with a power set at 60% for a set distance that
% we have yet to record. Only one wheel will be able to be put in reverse
% while the other either stays in position or moves forward.
clear all
brick = ConnectBrick('EV33');
%mycolorsensor = ColorSensor('EV33');
brick.SetColorMode(3, 2); %mode color code (port, mode)
color = brick.ColorCode(3);
display(color);
carryPerson = false;
%{
while(1 == 1)
dir = input("Enter a direction (W: Go forward, A: Turn left, S: Go backwards, D: Turn right): ", 's');
%Port D is the clutch, Port B is the motor
switch(dir)
case {'A', 'a'} %Turn left
brick.MoveMotor('D', 30); %This line changes the direction in which the clutch moves, allowing sprocket to turn
brick.MoveMotorAngleRel('B', -100, 1100, 'Brake'); %90 degrees
case {'W', 'w'} %Go forward
brick.MoveMotor('D', -30);
brick.MoveMotor('B', -100);
case {'D', 'd'} %Turn right
brick.MoveMotor('D', 30);
brick.MoveMotorAngleRel('B', 100, 1150, 'Brake');
%Port D is the clutch, Port B is the motor
case {'S', 's'} %Go backwards
brick.MoveMotor('D', -30);
brick.MoveMotor('B', 100);
case {'Q', 'q'}
brick.StopMotor('D');
brick.StopMotor('B');
end
end
%}
%As the robot moves, the drive motor pushes the clutch back and keeps it in
%neutral
%TODO:
%Gyro Control
% The gyro sensor is controlled by the object gyroSensor. This angle should be
% reset when there is a wall present. While the gyro should always stay at
% zero (theoretically) it is be if we reset it to zero every time.
%myGyro = gyroSensor(brick);
%angle = resetRotationAngle(myGyro);
%brick.GyroAngle(2);
%pause(.1);
% send a calibration command
%brick.inputReadSI(2, 4);
%pause(3);
%gyro_angle = brick.GyroAngle(2);
%TODO:
%Maze Algorithm
% The maze algorithm used will be the right wall follower. The ultrasonic
% sensor will be positioned on the right side of the robot.
distance = brick.UltrasonicDist(1);
while(1==1)
while(color == 6)
%gyro_angle = brick.GyroAngle(2);
%pause(.1);
distance = brick.UltrasonicDist(1);
if(distance > 50)
%Turn Right
brick.MoveMotor('D', 30);
brick.MoveMotorAngleRel('B', 100, 1140);
brick.WaitForMotor('B');
brick.StopMotor('D');
brick.StopMotor('B');
%Go Forward
brick.MoveMotor('D',-30);
brick.MoveMotorAngleRel('B',-100,7590);
state = brick.MotorBusy('B');
while (state)
color = brick.ColorCode(3);
disp(color);
if(color == 5)
brick.StopMotor('D');
brick.StopMotor('B');
pause(2);
brick.MoveMotor('D', -30);
brick.MoveMotorAngleRel('B', -100, 3795);
brick.WaitForMotor('B');
break;
end
% elseif(color == 3)
%if(carryPerson == false)
%keyboard claw controls
dir = input("Enter a direction (W: Go forward, A: Turn left, S: Go backwards, D: Turn right): ", 's');
%Port D is the clutch, Port B is the motor
switch(dir)
case {'A', 'a'} %Turn left
brick.MoveMotor('D', 30); %This line changes the direction in which the clutch moves, allowing sprocket to turn
brick.MoveMotorAngleRel('B', -100, 1100, 'Brake'); %90 degrees
case {'W', 'w'} %Go forward
brick.MoveMotor('D', -30);
brick.MoveMotor('B', -100);
case {'D', 'd'} %Turn right
brick.MoveMotor('D', 30);
brick.MoveMotorAngleRel('B', 100, 1150, 'Brake');
%Port D is the clutch, Port B is the motor
case {'S', 's'} %Go backwards
brick.MoveMotor('D', -30);
brick.MoveMotor('B', 100);
case {'Q', 'q'}
brick.StopMotor('D');
brick.StopMotor('B');
end
%end
end
brick.WaitForMotor('B');
brick.StopMotor('D');
brick.StopMotor('B');
end
if(distance < 50)
%Turn Left
brick.MoveMotor('D', 30);
brick.MoveMotorAngleRel('B', -100, 1100);
brick.WaitForMotor('B')
brick.StopMotor('D');
brick.StopMotor('B');
end
end
end
%TODO:
% Clutch
% The clutch is a bar with three gears at an angle where the last gear is
% connecting to the forward gear. When you want to turn, the clutch is
% flipped and the bar move at a different position where the reverse is
% activated for only one wheel. The clutch doesn't restrict which wheel we
% have to use, which mean it becomes a software issue, but something as
% simple as determining which way to turn. Use MoveMotorAngleRel to
% calculate the position of the lock-step straight motion and the reverse
% pivoting motion so that I could just tell the program the move to the
% exact position, or even set them to variables.
%straightMotionAngle = MoveMotorAngleRel();