-
Notifications
You must be signed in to change notification settings - Fork 1
/
Action.py
40 lines (33 loc) · 952 Bytes
/
Action.py
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
import Stepper
import numpy as np
import cv2
import time
import RPi.GPIO as GPIO
def action(img, rect):
height, weight, _ignore = img.shape
print(rect[0][0], rect[0][2])
bonduary = (weight * 0.2, weight * 0.8)
print(bonduary)
GPIO.setmode(GPIO.BOARD)
motor = Stepper.Motor((29, 31, 33, 35), 15)
center = int((rect[0][2] + rect[0][0]) / 2)
if center < bonduary[0]:
print("Here")
#motor.move_to(0)
motor.move_to(-5) #counterclockwise
time.sleep(0.2)
return True
GPIO.cleanup()
if center > bonduary[1]:
print("Here2")
#motor.move_to(0)
motor.move_to(5) #clockwise
time.sleep(0.2)
return True
GPIO.cleanup()
GPIO.cleanup()
def reset(steps):
GPIO.setmode(GPIO.BOARD)
motor = Stepper.Motor((29, 31, 33, 35), 15)
motor.move_to(int(steps * 5))
GPIO.cleanup()