Skip to content

Commit 7b9d2b7

Browse files
Add 'Sumo_2023/' from commit 'c6eab37f0174a69411231fa11e7738cf257acb79'
git-subtree-dir: Sumo_2023 git-subtree-mainline: 9c97e30 git-subtree-split: c6eab37
2 parents 9c97e30 + c6eab37 commit 7b9d2b7

24 files changed

+1402
-0
lines changed

Sumo_2023/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
All files for my previous sumo robot at the HTU in jordan, 2023
2+
3+
These include solidworks schematics and arduino nano code for a 2 wheel symtic motor robot,
4+
5+
Most parts from JSumo
Binary file not shown.
40.7 KB
Binary file not shown.
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#include <Ramp.h>
2+
3+
ramp LM_R; // Left motor R_PWM
4+
ramp LM_L; // Left motor L_PWM
5+
ramp RM_R; // Right motor R_PWM
6+
ramp RM_L; // Right motor L_PWM
7+
8+
// ========== 5 second delay ==========
9+
int b_pin = 13;
10+
bool delayed;
11+
12+
// ========== IR ==========
13+
const int IR_pins[3] = {2, 3, 4};
14+
bool IR[3];
15+
16+
const bool _clear[3] = {false, false, false};
17+
const bool front[3] = {true, false, false};
18+
const bool right[3] = {false, true, false};
19+
const bool left[3] = {false, false, true};
20+
const bool frontRight[3] = {true, true, false};
21+
const bool frontLeft[3] = {true, false, true};
22+
23+
// ========== ML2 ==========
24+
const int ml2_right_p = 7;
25+
int ml2_right;
26+
const int ml2_left_p = 8;
27+
int ml2_left;
28+
const int ml2_back_p = 9;
29+
int ml2_back;
30+
31+
// ========== BTS ==========
32+
int EN = 12;
33+
int R_PWM = 11;
34+
int L_PWM = 10;
35+
36+
int R_PWM2 = 5;
37+
int L_PWM2 = 6;
38+
39+
unsigned long currentMillis;
40+
unsigned long prevMillis;
41+
int stepFlag;
42+
43+
void setup() {
44+
// Sensors
45+
for (int i = 0; i < 3; i++) pinMode(IR_pins[i], INPUT);
46+
pinMode(b_pin, INPUT_PULLUP);
47+
pinMode(ml2_right_p, INPUT);
48+
pinMode(ml2_left_p, INPUT);
49+
pinMode(ml2_back_p, INPUT);
50+
51+
// BTS
52+
pinMode(EN, OUTPUT);
53+
digitalWrite(EN, LOW);
54+
55+
Serial.begin(9600);
56+
57+
Serial.println("End of setup");
58+
}
59+
60+
void loop() {
61+
currentMillis = millis();
62+
63+
// Sensor readings
64+
for (int i = 0; i < 3; i++) IR[i] = digitalRead(IR_pins[i]);
65+
ml2_right = digitalRead(ml2_right_p);
66+
ml2_left = digitalRead(ml2_left_p);
67+
ml2_back = digitalRead(ml2_back_p);
68+
69+
// 5 second delay
70+
//while (digitalRead(b_pin)) Serial.println("Waiting for button");
71+
if (!delayed && currentMillis - prevMillis >= 1000) {
72+
Serial.println(currentMillis);
73+
stepFlag = 1;
74+
prevMillis = currentMillis;
75+
delayed = true;
76+
}
77+
else if (delayed) Loop();
78+
} // End of main loop
79+
80+
int mapSpeed(int _s) {
81+
int s = map(_s, 0, 100, 0, 255);
82+
return s;
83+
}
84+
85+
void Loop() {
86+
while (true) {
87+
currentMillis = millis();
88+
89+
if (stepFlag == 1) {
90+
Serial.println("STEP 1");
91+
LM_R.go(mapSpeed(100), 1000);
92+
93+
prevMillis = currentMillis;
94+
stepFlag = 2;
95+
}
96+
if (stepFlag == 2 && currentMillis - prevMillis >= 3000) {
97+
Serial.println("STEP 2");
98+
LM_R.go(mapSpeed(0), 1000);
99+
100+
prevMillis = currentMillis;
101+
stepFlag = 3;
102+
}
103+
Serial.print("SPEED: ");
104+
Serial.print(LM_R.update());
105+
Serial.println();
106+
Serial.println(currentMillis);
107+
108+
if (IR != _clear) {
109+
if (IR == front) {
110+
Serial.println("FRONT");
111+
}
112+
else if (IR == right) {
113+
Serial.println("RIGHT");
114+
}
115+
else if (IR == left) {
116+
Serial.println("LEFT");
117+
}
118+
else if (IR == frontRight) {
119+
Serial.println("FRONT RIGHT");
120+
}
121+
else if (IR == frontLeft) {
122+
Serial.println("FRONT LEFT");
123+
}
124+
}
125+
else {
126+
Serial.println("CLEAR");
127+
}
128+
/*
129+
if (ml2_right && ml2_left) {
130+
Serial.println("ML2 RIGHT LEFT");
131+
}
132+
if (ml2_right) {
133+
Serial.println("ML2 RIGHT");
134+
}
135+
if (ml2_left) {
136+
Serial.println("ML2 Left");
137+
}
138+
if (ml2_back) {
139+
Serial.println("ML2 Back");
140+
}*/
141+
142+
}
143+
}
144+
145+
void Forward(int s) {
146+
analogWrite(R_PWM, s);
147+
analogWrite(L_PWM, 0);
148+
analogWrite(R_PWM2, s);
149+
analogWrite(L_PWM2, 0);
150+
}
151+
152+
void Backward(int s) {
153+
analogWrite(R_PWM, 0);
154+
analogWrite(L_PWM, s);
155+
analogWrite(R_PWM2, 0);
156+
analogWrite(L_PWM2, s);
157+
}
158+
159+
void Right(int s) {
160+
analogWrite(R_PWM, s);
161+
analogWrite(L_PWM, 0);
162+
analogWrite(R_PWM2, 0);
163+
analogWrite(L_PWM2, s);
164+
}
165+
166+
void Left(int s) {
167+
analogWrite(R_PWM, 0);
168+
analogWrite(L_PWM, s);
169+
analogWrite(R_PWM2, s);
170+
analogWrite(L_PWM2, 0);
171+
}
286 KB
Binary file not shown.
47.7 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)