Skip to content

Commit 06d1934

Browse files
author
Aaron Tainter
committed
Add setup guide
1 parent 0cee071 commit 06d1934

File tree

2 files changed

+132
-12
lines changed

2 files changed

+132
-12
lines changed

README.md

+84
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,86 @@
11
# Tracking-Turret
22
A motion tracking turret.
3+
4+
## Install Guide
5+
6+
Make sure pip is installed.
7+
```bash
8+
sudo apt-get install python pip
9+
```
10+
11+
Setup I2C on your Raspberry Pi
12+
13+
https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c
14+
15+
Install the Adafruit stepper motor HAT library.
16+
17+
```bash
18+
sudo pip install git+https://github.com/adafruit/Adafruit-Motor-HAT-Python-Library
19+
```
20+
21+
Install OpenCV 3. Follow all steps for python 2.7 instructions
22+
23+
http://www.pyimagesearch.com/2016/04/18/install-guide-raspberry-pi-3-raspbian-jessie-opencv-3/
24+
25+
Make sure to create your virtual environment with the extra flag.
26+
27+
```bash
28+
mkvirtualenv cv --system-site-packages -p python2
29+
```
30+
31+
Source your bash profile
32+
33+
```bash
34+
source ~/.profile
35+
```
36+
37+
Activate your virtual environment
38+
39+
```
40+
workon cv
41+
```
42+
43+
Clone this repository
44+
45+
```
46+
git clone [email protected]:HackerHouseYT/Tracking-Turret.git
47+
```
48+
49+
Navigate to the directory
50+
51+
```
52+
cd Tracking-Turret
53+
```
54+
55+
Install dependencies to your virtual environment
56+
57+
```
58+
pip install imutils RPi.GPIO
59+
```
60+
61+
Run the project!
62+
63+
```
64+
python turret.py
65+
```
66+
67+
## Setting Parameters
68+
69+
turret.py has a couple parameters that you can set.
70+
71+
```python
72+
### User Parameters ###
73+
74+
MOTOR_X_REVERSED = False
75+
MOTOR_Y_REVERSED = False
76+
77+
MAX_STEPS_X = 30
78+
MAX_STEPS_Y = 15
79+
80+
RELAY_PIN = 22
81+
82+
#######################
83+
```
84+
85+
These will be located at the top of the file. Use `vim turret.py` to open the file. Press `i` to edit.
86+
Once you've made your changes, press `esc` then `ZZ` to save.

turret.py

+48-12
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,15 @@ def __calibrate_x_axis(self):
220220
break
221221

222222
elif ch == "a":
223-
Turret.move_forward(self.sm_x, 5)
223+
if MOTOR_X_REVERSED:
224+
Turret.move_backward(self.sm_x, 5)
225+
else:
226+
Turret.move_forward(self.sm_x, 5)
224227
elif ch == "d":
225-
Turret.move_backward(self.sm_x, 5)
228+
if MOTOR_X_REVERSED:
229+
Turret.move_forward(self.sm_x, 5)
230+
else:
231+
Turret.move_backward(self.sm_x, 5)
226232
elif ch == "\n":
227233
break
228234

@@ -243,9 +249,15 @@ def __calibrate_y_axis(self):
243249
break
244250

245251
if ch == "w":
246-
Turret.move_backward(self.sm_y, 5)
252+
if MOTOR_Y_REVERSED:
253+
Turret.move_forward(self.sm_y, 5)
254+
else:
255+
Turret.move_backward(self.sm_y, 5)
247256
elif ch == "s":
248-
Turret.move_forward(self.sm_y, 5)
257+
if MOTOR_Y_REVERSED:
258+
Turret.move_backward(self.sm_y, 5)
259+
else:
260+
Turret.move_forward(self.sm_y, 5)
249261
elif ch == "\n":
250262
break
251263

@@ -278,18 +290,30 @@ def __move_axis(self, contour, frame):
278290
# move x
279291
if (target_steps_x - self.current_x_steps) > 0:
280292
self.current_x_steps += 1
281-
t_x = threading.Thread(target=Turret.move_backward, args=(self.sm_x, 2,))
293+
if MOTOR_X_REVERSED:
294+
t_x = threading.Thread(target=Turret.move_forward, args=(self.sm_x, 2,))
295+
else:
296+
t_x = threading.Thread(target=Turret.move_backward, args=(self.sm_x, 2,))
282297
elif (target_steps_x - self.current_x_steps) < 0:
283298
self.current_x_steps -= 1
284-
t_x = threading.Thread(target=Turret.move_forward, args=(self.sm_x, 2,))
299+
if MOTOR_X_REVERSED:
300+
t_x = threading.Thread(target=Turret.move_backward, args=(self.sm_x, 2,))
301+
else:
302+
t_x = threading.Thread(target=Turret.move_forward, args=(self.sm_x, 2,))
285303

286304
# move y
287305
if (target_steps_y - self.current_y_steps) > 0:
288306
self.current_y_steps += 1
289-
t_y = threading.Thread(target=Turret.move_forward, args=(self.sm_y, 2,))
307+
if MOTOR_Y_REVERSED:
308+
t_y = threading.Thread(target=Turret.move_backward, args=(self.sm_y, 2,))
309+
else:
310+
t_y = threading.Thread(target=Turret.move_forward, args=(self.sm_y, 2,))
290311
elif (target_steps_y - self.current_y_steps) < 0:
291312
self.current_y_steps -= 1
292-
t_y = threading.Thread(target=Turret.move_backward, args=(self.sm_y, 2,))
313+
if MOTOR_Y_REVERSED:
314+
t_y = threading.Thread(target=Turret.move_forward, args=(self.sm_y, 2,))
315+
else:
316+
t_y = threading.Thread(target=Turret.move_backward, args=(self.sm_y, 2,))
293317

294318
# fire if necessary
295319
if not self.friendly_mode:
@@ -322,13 +346,25 @@ def interactive(self):
322346
break
323347

324348
if ch == "w":
325-
Turret.move_backward(self.sm_y, 5)
349+
if MOTOR_Y_REVERSED:
350+
Turret.move_forward(self.sm_y, 5)
351+
else:
352+
Turret.move_backward(self.sm_y, 5)
326353
elif ch == "s":
327-
Turret.move_forward(self.sm_y, 5)
354+
if MOTOR_Y_REVERSED:
355+
Turret.move_backward(self.sm_y, 5)
356+
else:
357+
Turret.move_forward(self.sm_y, 5)
328358
elif ch == "a":
329-
Turret.move_forward(self.sm_x, 5)
359+
if MOTOR_X_REVERSED:
360+
Turret.move_backward(self.sm_x, 5)
361+
else:
362+
Turret.move_forward(self.sm_x, 5)
330363
elif ch == "d":
331-
Turret.move_backward(self.sm_x, 5)
364+
if MOTOR_X_REVERSED:
365+
Turret.move_forward(self.sm_x, 5)
366+
else:
367+
Turret.move_backward(self.sm_x, 5)
332368
elif ch == "\n":
333369
Turret.fire()
334370

0 commit comments

Comments
 (0)