Skip to content

Commit

Permalink
Merge branch 'demo' into cv
Browse files Browse the repository at this point in the history
  • Loading branch information
georgecwan committed Nov 18, 2021
2 parents 761dee3 + e7c4630 commit 5dcb4b2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
venv/
.idea/
**/.DS_Store
**/__pycache__/
**/__pycache__/
*.pyc
2 changes: 1 addition & 1 deletion BaseLibrary/Code/Server/servo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from PCA9685 import PCA9685
from BaseLibrary.Code.Server.PCA9685 import PCA9685
class Servo:
def __init__(self):
self.PwmServo = PCA9685(0x40, debug=True)
Expand Down
23 changes: 23 additions & 0 deletions ControlsDemo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from BaseLibrary.Code.Server.Motor import *
import time

PWM = Motor()


try:
while True:
a = input()
if a == 'w':
PWM.setMotorModel(1000, 1000, 1000, 1000)
elif a == 'a':
PWM.setMotorModel(-1900, -1500, 2000, 2000)
elif a == 's':
PWM.setMotorModel(-1000, -1000, -1000, -1000)
elif a == 'd':
PWM.setMotorModel(2000, 2000, -2500, -1500)
else:
PWM.setMotorModel(0, 0, 0, 0)

except KeyboardInterrupt:
PWM.setMotorModel(0, 0, 0, 0)

39 changes: 21 additions & 18 deletions Robot.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from BaseLibrary.Code.Server.Motor import*
from cv.faceDetect import Vision
from rpi_ws281x import *
from BaseLibrary.Code.Server.Led import Led
# from rpi_ws281x import *
from BaseLibrary.Code.Server.servo import Servo
import time

cv = Vision()
PWM = Motor()
led = Led()

servo = Servo()

try:
servo.setServoPwm('0', 90)
servo.setServoPwm('1', 120)
idleCount = 0
m1i = m2i = m3i = m4i = 0 # Forward/backwards values
m1t = m2t = m3t = m4t = 0 # Turning Values
Expand All @@ -20,14 +21,20 @@
relativeX = 160 - x - w / 2
if (x, y, w, h) == (0, 0, 0, 0):
print("No face detected")
if w != 0 and abs(relativeX) >= 20:
if relativeX < 0:

if w != 0 and abs(relativeX) >= 10:
if relativeX < -50:
print("Turning right")
m1t, m2t, m3t, m4t = 600, 600, 0, 0
m1t, m2t, m3t, m4t = 1000, 1000, 0, 0
elif relativeX > 50:
print("Turning left")
m1t, m2t, m3t, m4t = 0, 0, 1000, 1000
elif relativeX < 0:
print("Turning right")
m1t, m2t, m3t, m4t = 700, 700, 0, 0
elif relativeX > 0:
print("Turning left")
m1t, m2t, m3t, m4t = 0, 0, 600, 600
m1t, m2t, m3t, m4t = 0, 0, 700, 700
else:
print("No turning")
m1t = m2t = m3t = m4t = 0
Expand All @@ -36,26 +43,22 @@
# Too close
print("Going backwards")
m1i, m2i, m3i, m4i = -600, -600, -600, -600
# led.colorWipe(led.strip, Color(255, 0, 0))
idleCount = 0
elif 0 < w < 40 and 0 < h < 40:
# Too far
print("Going forwards")
m1i, m2i, m3i, m4i = 600, 600, 600, 600
# led.colorWipe(led.strip, Color(0, 255, 0))
idleCount = 0
# elif idleCount < 2:
# print("Idling")
# idleCount += 1
# led.colorWipe(led.strip, Color(255, 255, 255))
elif idleCount < 2:
print("Idling")
idleCount += 1
else:
print("No f/b movement")
m1i, m2i, m3i, m4i = 0, 0, 0, 0
# led.colorWipe(led.strip, Color(0, 0, 255))

PWM.setMotorModel(m1t + m1i, m2t + m2i, m3t + m3i, m4t + m4i)

except KeyboardInterrupt:
PWM.setMotorModel(0, 0, 0, 0)
cv.destroy()
# led.colorWipe(led.strip, Color(0, 0, 0), 10)
servo.setServoPwm('0', 90)
servo.setServoPwm('1', 90)
4 changes: 2 additions & 2 deletions cv/faceDetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def destroy(self):
ret, img = cap.read()
# img = cv2.flip(img, -1)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = imutils.resize(gray, width=320)
gray = imutils.resize(gray, width=360)
img = imutils.resize(img, width=360)

faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.2,
Expand Down

0 comments on commit 5dcb4b2

Please sign in to comment.