Skip to content

Commit 1cca1f3

Browse files
committed
cleaned repo
1 parent 4dc9cd2 commit 1cca1f3

18 files changed

+389
-801
lines changed

Files.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Pomelo_Aruco is the working Aruco code
2+
Pomelo_Main is the code used to test merging Pomelo_monitor and Pomelo_Aruco
3+
Pomelo_Monitor is working but not on run
4+
Pomelo_Aruco_in_class_form is file used to convert Pomelo_Aruco code to a class
5+

Pomelo_Aruco.py

+116-53
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,144 @@
33
from time import sleep
44
from pololu_drv8835_rpi import motors
55
import threading
6-
import RPi.GPIO as g
6+
import RPi.GPIO as GPIO
7+
import PiWarsTurkiyeRobotKiti2019
78
from PiWarsTurkiyeRobotKiti2019 import HizlandirilmisPiKamera
8-
#sudo modprobe bcm2835-v4l2 //this makes picamera visible
99

10+
# sudo modprobe bcm2835-v4l2 //this makes picamera visible
11+
12+
13+
motors = PiWarsTurkiyeRobotKiti2019.MotorKontrol ()
14+
controller = PiWarsTurkiyeRobotKiti2019.Kumanda ()
15+
controller.dinlemeyeBasla ()
16+
xy = controller.solVerileriOku ()
17+
xz = controller.sagVerileriOku ()
18+
xx = controller.butonlariOku ()
1019
commands = []
1120

21+
1222
def setup():
1323
global camera, aruco_dict, parameters
14-
camera = HizlandirilmisPiKamera()
15-
camera.veriOkumayaBasla()
16-
aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_250)
17-
parameters = aruco.DetectorParameters_create()
18-
motors.setSpeeds(0, 0)
19-
g.setmode(g.BCM)
20-
g.setup(26, g.IN, pull_up_down=g.PUD_DOWN)
21-
print(g.input(26))
22-
23-
def forward(n):
24-
motors.setSpeeds(240, 240) #max: 480
25-
sleep(n)
26-
motors.setSpeeds(0, 0)
27-
28-
def back(n):
29-
motors.setSpeeds(-240, -240)
30-
sleep(n)
31-
motors.setSpeeds(0, 0)
32-
24+
camera = HizlandirilmisPiKamera ()
25+
camera.veriOkumayaBasla ()
26+
aruco_dict = aruco.Dictionary_get (aruco.DICT_4X4_250)
27+
parameters = aruco.DetectorParameters_create ()
28+
motors.hizlariAyarla (0, 0)
29+
GPIO.setmode (GPIO.BCM)
30+
GPIO.setup (26, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
31+
print(GPIO.input (26))
32+
33+
34+
def forward(duration):
35+
motors.hizlariAyarla (240, 240) # max: 480
36+
sleep (duration)
37+
motors.hizlariAyarla (0, 0)
38+
39+
40+
def back(duration):
41+
motors.hizlariAyarla (-240, -240)
42+
sleep (duration)
43+
motors.hizlariAyarla (0, 0)
44+
45+
46+
def right(duration):
47+
motors.hizlariAyarla (-240, 240)
48+
sleep (duration)
49+
motors.hizlariAyarla (0, 0)
50+
51+
52+
def left(duration):
53+
motors.hizlariAyarla (240, -240)
54+
sleep (duration)
55+
motors.hizlariAyarla (0, 0)
56+
57+
3358
def takePic():
3459
global commands, camera, aruco_dict, parameters
35-
frame = camera.veriOku()
60+
frame = camera.veriOku ()
3661

37-
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
62+
gray = cv2.cvtColor (frame, cv2.COLOR_BGR2GRAY)
63+
3864

39-
ids = aruco.detectMarkers(gray, aruco_dict, parameters=parameters)[1]
65+
ids = aruco.detectMarkers (gray, aruco_dict, parameters=parameters)[1]
4066

41-
if ids is None or len(ids) == 0:
67+
if ids is None or len (ids) == 0:
4268
print("no aruco")
4369
return
44-
45-
ids = ids.tolist()
70+
71+
ids = ids.tolist ()
4672
commands = []
4773
for i in ids:
4874
commands += i
4975
print(i)
50-
51-
#if ids is not None and len(ids) > 0:print(ids.tolist()) #0, 18, 20, 39
76+
77+
# if ids is not None and len(ids) > 0:print(ids.tolist()) #0, 18, 20, 39
78+
5279

5380
def run():
5481
global commands
55-
n = 1
56-
for i in commands:
57-
if i == 11:
58-
back(n)
59-
n = 1
60-
if i == 0:
61-
forward(n)
62-
n = 1
63-
if i == 9: n = 3
82+
duration = 1
83+
if len(commands) >=1:
84+
print(len(commands))
85+
for i in range(len(commands)):
86+
print(i)
87+
arucoNumber = commands[i]
88+
if len(commands)-1>i:
89+
arucoNumberSecond = commands[i+1]
90+
else:
91+
arucoNumberSecond = 1
92+
print("no specified seconds")
93+
if arucoNumber == 12:
94+
if arucoNumberSecond <= 10:
95+
duration = arucoNumberSecond
96+
print ("back", duration)
97+
back (duration)
98+
if arucoNumber == 11:
99+
if arucoNumberSecond <= 10:
100+
duration = arucoNumberSecond
101+
print ("forward", duration)
102+
forward (duration)
103+
if arucoNumber == 14:
104+
if arucoNumberSecond <= 10:
105+
duration = arucoNumberSecond
106+
left (duration)
107+
if arucoNumber == 13:
108+
if arucoNumberSecond <= 10:
109+
duration = arucoNumberSecond
110+
print ("right", duration)
111+
right (duration)
112+
if arucoNumber == 15: duration = 3
113+
114+
64115

65116
def takeInput():
66-
67-
while(1):
68-
y = g.input(26)
117+
while (1):
118+
y = GPIO.input (26)
69119
if (y == True):
70-
print("ey")
71-
takePic()
72-
run()
73-
sleep(0.2)
74-
120+
print("button pressed")
121+
takePic ()
122+
123+
run ()
124+
while (xx != controller.butonlariOku () or xy != controller.sagVerileriOku () or xz != controller.solVerileriOku ()):
125+
lx, ly = controller.solVerileriOku ()
126+
print(lx, ly)
127+
rightSpeed, leftSpeed = motors.kumandaVerisiniMotorVerilerineCevirme (lx, ly)
128+
#leftSpeed = motors.kumandaVerisiniMotorVerilerineCevirme (lx, ly, False)
129+
print(lx, " ", ly, " ", rightSpeed, " ", leftSpeed)
130+
motors.hizlariAyarla (rightSpeed, leftSpeed)
131+
sleep (0.3)
132+
motors.hizlariAyarla (0, 0)
133+
134+
sleep (0.2)
75135

76-
setup()
77-
sleep(1)
78-
thread = threading.Thread(target=takeInput)
79-
thread.start()
80-
while(1):
81-
frame = camera.veriOku()
82-
sleep(0.05)
136+
setup ()
137+
138+
sleep (1)
139+
thread = threading.Thread (target=takeInput)
140+
thread.start ()
141+
142+
while (1):
143+
144+
frame = camera.veriOku ()
145+
camera.kareyiGoster()
83146

Pomelo_Aruco_in_class_form.py

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import cv2
2+
import cv2.aruco as aruco
3+
from time import sleep
4+
from pololu_drv8835_rpi import motors
5+
import threading
6+
import RPi.GPIO as GPIO
7+
import PiWarsTurkiyeRobotKiti2019
8+
#sudo modprobe bcm2835-v4l2 //this makes picamera visible
9+
10+
11+
GPIO.setmode (GPIO.BCM)
12+
GPIO.setup (26, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
13+
14+
class Aruco_Controll:
15+
def __init__(self):
16+
self.motors = PiWarsTurkiyeRobotKiti2019.MotorKontrol()
17+
self.controller = PiWarsTurkiyeRobotKiti2019.Kumanda()
18+
self.controller.dinlemeyeBasla()
19+
self.xy = self.controller.solVerileriOku()
20+
self.xz = self.controller.sagVerileriOku()
21+
self.xx = self.controller.butonlariOku()
22+
self.commands = []
23+
self.camera = PiWarsTurkiyeRobotKiti2019.HizlandirilmisPiKamera()
24+
self.aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_250)
25+
self.parameters = aruco.DetectorParameters_create()
26+
27+
28+
29+
def setup(self):
30+
self.camera.veriOkumayaBasla()
31+
self.motors.hizlariAyarla(0, 0)
32+
print(GPIO.input(26))
33+
34+
def forward(self, n):
35+
self.motors.hizlariAyarla(240, 240) #max: 480
36+
sleep(n)
37+
self.motors.hizlariAyarla(0, 0)
38+
def back(self, n):
39+
self.motors.hizlariAyarla(-240, -240)
40+
sleep(n)
41+
self.motors.hizlariAyarla(0, 0)
42+
def right(self, n):
43+
self.motors.hizlariAyarla(-240, 240)
44+
sleep(n)
45+
self.motors.hizlariAyarla(0, 0)
46+
def left(self, n):
47+
self.motors.hizlariAyarla(240, -240)
48+
sleep(n)
49+
self.motors.hizlariAyarla(0, 0)
50+
51+
def takePic(self):
52+
self.frame = self.camera.veriOku()
53+
gray = cv2.cvtColor(self.frame, cv2.COLOR_BGR2GRAY)
54+
ids = aruco.detectMarkers(gray, self.aruco_dict, parameters=self.parameters)[1]
55+
56+
if ids is None or len(ids) == 0:
57+
print("no aruco")
58+
return
59+
60+
ids = ids.tolist()
61+
self.commands = []
62+
for i in ids:
63+
self.commands += i
64+
print(i)
65+
66+
#if ids is not None and len(ids) > 0:print(ids.tolist()) #0, 18, 20, 39
67+
68+
def run(self):
69+
n = 1
70+
for i in self.commands:
71+
if i == 11:
72+
self.back(n)
73+
n = 1
74+
if i == 0:
75+
self.forward(n)
76+
n = 1
77+
if i == 1:
78+
self.left(n)
79+
n = 1
80+
if i == 10:
81+
self.right(n)
82+
n = 1
83+
if i == 9: n = 3
84+
85+
def takeInput(self):
86+
87+
while(1):
88+
if ( GPIO.input(26) == True): #GPIO.input(26) is buttons state when pressed == true
89+
print("button pressed")
90+
self.takePic()
91+
self.run()
92+
self.Controller()
93+
94+
def Controller(self):
95+
while(self.xx != self.controller.butonlariOku() or self.xy != self.controller.sagVerileriOku() or self.xz != self.controller.solVerileriOku()):
96+
lx, ly = self.controller.solVerileriOku()
97+
rightSpeed = self.motors.kumandaVerisiniMotorVerilerineCevirme(lx, ly, True)
98+
leftSpeed = self.motors.kumandaVerisiniMotorVerilerineCevirme(lx, ly, False)
99+
print(lx," ", ly, " ", rightSpeed, " ", leftSpeed)
100+
self.motors.hizlariAyarla(rightSpeed, leftSpeed)
101+
sleep(0.3)
102+
self.motors.hizlariAyarla(0, 0)
103+
sleep(0.2)
104+
105+
class Build_Thread:
106+
def Thread_Monitor(self):
107+
thread = threading.Thread (target=Aruco.takeInput) #monitör threadi
108+
"""
109+
def Thread_Aruco_Input(self):
110+
thread = threading.Thread (target=) #monitör threadi
111+
112+
def Thread_(self):
113+
thread = threading.Thread (target=) #monitör threadi
114+
"""
115+
116+
117+
Aruco = Aruco_Controll()
118+
threads = Build_Thread()
119+
Aruco.setup()
120+

Pomelo_Assistnat.py

-43
This file was deleted.

Pomelo_Gassist.py

Whitespace-only changes.

0 commit comments

Comments
 (0)