Skip to content

Commit

Permalink
Add description
Browse files Browse the repository at this point in the history
  • Loading branch information
KuranosukeOhta committed Mar 4, 2020
1 parent 088931d commit 06b76be
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
It is a tank made by japanese junior high school students with Raspberry pi.

###This article uses Google Translate.###
This project was created to make a remote control car work with Raspberry Pi and Python. I'm still inexperienced, so I'd like you to give me any advice.
93 changes: 82 additions & 11 deletions s2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,36 @@
gpio_pin2 = 27
#1= left
#2= right
import sys
import time
import cv2
import numpy as np
import RPi.GPIO as GPIO
cap = cv2.VideoCapture(0)

GPIO.setmode(GPIO.BCM)

GPIO.setup(gpio_pin , GPIO.OUT)
GPIO.setup(gpio_pin2 , GPIO.OUT)
#27 = right
run_time = 0.1
def Right(none):
GPIO.output(gpio_pin, 0)
GPIO.output(gpio_pin2, 1)
time.sleep(0.60)
time.sleep(run_time)
Off("a")
return 0
def Left(none):
GPIO.output(gpio_pin, 1)
GPIO.output(gpio_pin2, 0)
time.sleep(0.60)
time.sleep(run_time)
Off("a")
return 0
def Straight(none):
for i in range(2):
Right(0)
time.sleep(0.1)
Off("r")
Left(0)
time.sleep(0.17)
Off("l")
GPIO.output(gpio_pin, 1)
GPIO.output(gpio_pin2, 1)
time.sleep(run_time + 0.5)
Off("a")
return 0
def Off(which):
if which == "r":
Expand All @@ -46,8 +49,74 @@ def Off(which):
GPIO.output(gpio_pin , 0)
GPIO.output(gpio_pin2 , 0)
return 0


before = None
camera_mode = 3
while True:
try:
ret, frame = cap.read()
if camera_mode == 2:
cv2.imshow("camera", frame)
else:
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
if camera_mode == 1:
if before is None:
before = gray.copy().astype("float")
continue
cv2.imshow("camera", gray)

else:

#before = gray.copy().astype("float")

#ret,two = cv2.threshold(gray,147,255,cv2.THRESH_BINARY)
ret,two = cv2.threshold(gray,127,255,cv2.THRESH_BINARY)
cv2.imshow("camera", two)
"""
cv2.accumulateWeighted(gray, before, 0.7)
mdframe = cv2.absdiff(gray, cv2.convertScaleAbs(before))
ret,thresh2 = cv2.threshold(mdframe,10,255,cv2.THRESH_BINARY)
ret,thresh1 = cv2.threshold(gray,147,255,cv2.THRESH_BINARY)
cv2.imshow("threshed1", thresh1)
"""





k = cv2.waitKey(1)&0xff
if k == ord("w"):
print("w")
Straight(0)
elif k == ord("d"):
print("r")
Right(0)
elif k == ord("a"):
print("l")
Left(0)
elif k == ord("i"):
run_time += 0.1
print(run_time)
print("Straight" , str(run_time + 0.5))
elif k == ord("k"):
run_time -= 0.1
print(run_time)
print("Straight" , str(run_time + 0.5))
elif k == ord("o"):
if camera_mode < 3:
camera_mode += 1
print("camera_mode set "+ str(camera_mode) + ".")
elif k == ord("l"):
if camera_mode > 1:
camera_mode -= 1
print("camera_mode set "+ str(camera_mode) + ".")
elif k == 27:
break
"""
answer = ""
answer = raw_input("Chose, s or r or l or ss or e.")
if answer == "s":
Expand All @@ -58,14 +127,16 @@ def Off(which):
Left(0)
elif answer == "ss":
Off("a")
elif answer == "e":
break
else:
print("What?")

"""
except KeyboardInterrupt:
print("safe end.")
break

cv2.destroyAllWindows()
cap.release
GPIO.cleanup()
print("All end.")

0 comments on commit 06b76be

Please sign in to comment.