-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS2E18-inc-mode-with-limiits.ino
More file actions
217 lines (168 loc) · 5 KB
/
Copy pathS2E18-inc-mode-with-limiits.ino
File metadata and controls
217 lines (168 loc) · 5 KB
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
#include <Servo.h>
Servo baseMotor;
Servo extendMotor;
Servo liftMotor;
Servo clawMotor;
//- soft limits for motors
int baseMotorMin = 0;
int baseMotorMax = 180;
int baseMotorMid = ((baseMotorMax - baseMotorMin) / 2) + baseMotorMin;
int baseMotorPosition = 90;
int extendMotorMax = 150;
int extendMotorMin = 50;
int extendMotorMid = ((extendMotorMax - extendMotorMin) / 2) + extendMotorMin;
int extendMotorPosition = 90;
int liftMotorMax = 180;
int liftMotorMin = 90;
int liftMotorMid = ((liftMotorMax - liftMotorMin) / 2) + liftMotorMin;
int liftMotorPosition = 90;
int clawMotorMax = 180;
int clawMotorMin = 90;
int clawClose = 180;
int clawOpen = 90;
int clawPosition = 90;
//- speed
int speed = 10;
void clawMoveInc(int incrementAngle) {
clawPosition = clawPosition + incrementAngle;
//-check to make sure that new position is not beyond the limit
if (clawPosition > clawMotorMax) {
clawPosition = clawMotorMax;
Serial.println("You've reached a max limit!");
}
if (clawPosition < clawMotorMin) {
clawPosition = clawMotorMin;
Serial.println("You've reached a min limit!");
}
Serial.print("my new claw position is: ");
Serial.println(clawPosition);
Serial.println();
clawMotor.write(clawPosition);
}
void baseMoveInc(int incrementAngle) {
baseMotorPosition = baseMotorPosition + incrementAngle;
//-check to make sure that new position is not beyond the limit
if (baseMotorPosition > baseMotorMax) {
baseMotorPosition = baseMotorMax;
Serial.println("You've reached a max limit!");
}
if (baseMotorPosition < baseMotorMin) {
baseMotorPosition = baseMotorMin;
Serial.println("You've reached a min limit!");
}
Serial.print("my new base motor position is: ");
Serial.println(baseMotorPosition);
Serial.println();
baseMotor.write(baseMotorPosition);
}
void extendMoveInc(int incrementAngle) {
extendMotorPosition = extendMotorPosition + incrementAngle;
//-check to make sure that new position is not beyond the limit
if (extendMotorPosition > extendMotorMax) {
extendMotorPosition = extendMotorMax;
Serial.println("You've reached a max limit!");
}
if (extendMotorPosition < extendMotorMin) {
extendMotorPosition = extendMotorMin;
Serial.println("You've reached a min limit!");
}
Serial.print("my new extend motor position is: ");
Serial.println(extendMotorPosition);
Serial.println();
extendMotor.write(extendMotorPosition);
}
void liftMoveInc(int incrementAngle) {
liftMotorPosition = liftMotorPosition + incrementAngle;
//-check to make sure that new position is not beyond the limit
if (liftMotorPosition > liftMotorMax) {
liftMotorPosition = liftMotorMax;
Serial.println("You've reached a max limit!");
}
if (liftMotorPosition < liftMotorMin) {
liftMotorPosition = liftMotorMin;
Serial.println("You've reached a min limit!");
}
Serial.print("my new lift motor position is: ");
Serial.println(liftMotorPosition);
Serial.println();
liftMotor.write(liftMotorPosition);
}
void setup() {
baseMotor.attach(9);
extendMotor.attach(10);
liftMotor.attach(11);
clawMotor.attach(6);
pinMode(2,INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
//Serial.println("Hello I am a robot arm.");
while (Serial.available()>0) {
char myLetter;
myLetter = Serial.read(); //- read 1 character
Serial.print("I just received: ");
Serial.println(myLetter);
if (myLetter == '1') {
//-open the claw
clawMotor.write(clawOpen);
Serial.println("opening the claw!");
}
if (myLetter == '2') {
//-close the claw
clawMotor.write(clawClose);
Serial.println("closing the claw!");
}
if (myLetter == 'q') {
//-increment move
clawMoveInc(5);
Serial.println("inc mode move 5!");
}
if (myLetter == 'w') {
clawMoveInc(-5);
Serial.println("inc mode move -5!");
}
if (myLetter == 'a') {
baseMotor.write(baseMotorMin);
Serial.println("Moving base motor to min!");
}
if (myLetter == 'b') {
baseMotor.write(baseMotorMid);
Serial.println("Moving base motor to mid!");
}
if (myLetter == 'c') {
baseMotor.write(baseMotorMax);
Serial.println("Moving base motor to max!");
}
if (myLetter == 'o') {
baseMoveInc(5);
}
if (myLetter == 'p') {
baseMoveInc(-5);
}
if (myLetter == '5') {
liftMotor.write(liftMotorMin);
Serial.println("Moving lift motor to min!");
}
if (myLetter == '6') {
liftMotor.write(liftMotorMid);
Serial.println("Moving lift motor to mid!");
}
if (myLetter == '7') {
liftMotor.write(liftMotorMax);
Serial.println("Moving lift motor to max!");
}
if (myLetter == 'n') {
liftMoveInc(5);
}
if (myLetter == 'm') {
liftMoveInc(-5);
}
if (myLetter == 'z') {
extendMoveInc(5);
}
if (myLetter == 'x') {
extendMoveInc(-5);
}
}
delay(100);
}