Compare commits
2 Commits
3154e334e3
...
a9f099b8ca
Author | SHA1 | Date |
---|---|---|
Siwat Sirichai | a9f099b8ca | |
Siwat Sirichai | ad16c4908e |
|
@ -0,0 +1,27 @@
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
def init():
|
||||||
|
pygame.init()
|
||||||
|
win = pygame.display.set_mode((100,100))
|
||||||
|
|
||||||
|
def getKey(keyName):
|
||||||
|
ans = False
|
||||||
|
for eve in pygame.event.get():pass
|
||||||
|
keyInput = pygame.key.get_pressed()
|
||||||
|
myKey = getattr(pygame,'K_{}'.format(keyName))
|
||||||
|
if keyInput [myKey]:
|
||||||
|
ans = True
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
return ans
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if getKey('LEFT'):
|
||||||
|
print('Key Left was pressed')
|
||||||
|
if getKey('RIGHT'):
|
||||||
|
print('Key Right was pressed')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
init()
|
||||||
|
while True:
|
||||||
|
main()
|
|
@ -30,7 +30,7 @@ def main():
|
||||||
if curveVal>-0.08: curveVal=0
|
if curveVal>-0.08: curveVal=0
|
||||||
car.motion.skt_drive(0.4,-curveVal*sen,0.05)
|
car.motion.skt_drive(0.4,-curveVal*sen,0.05)
|
||||||
turn_value = -curveVal*sen
|
turn_value = -curveVal*sen
|
||||||
print("Curve Value : " + str(curveVal) + "Turn Value : "+ str(turn_value))
|
print("Curve Value : " + str(curveVal) + " Turn Value : "+ str(round(turn_value,2))
|
||||||
cv2.waitKey(1)
|
cv2.waitKey(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
from kuukar.kuukar import kuukar
|
||||||
|
import KeyPressModule as kp
|
||||||
|
|
||||||
|
car = kuukar()
|
||||||
|
kp.init()
|
||||||
|
|
||||||
|
def main(self):
|
||||||
|
|
||||||
|
if kp.getKey('UP'):
|
||||||
|
car.motion.skt_drive(0.4,0.0,0.05)
|
||||||
|
elif kp.getKey('DOWN'):
|
||||||
|
car.motion.skt_drive(-0.4,0.0,0.05)
|
||||||
|
elif kp.getKey('LEFT'):
|
||||||
|
car.motion.skt_drive(0.5,0.3,0.05)
|
||||||
|
elif kp.getKey('RIGHT'):
|
||||||
|
car.motion.skt_drive(0.5,-0.3,0.05)
|
||||||
|
else:
|
||||||
|
car.motion.stop()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
while True:
|
||||||
|
main()
|
|
@ -16,7 +16,7 @@ class cv:
|
||||||
def _cv_loop(self):
|
def _cv_loop(self):
|
||||||
while True:
|
while True:
|
||||||
img = self.capture_image()
|
img = self.capture_image()
|
||||||
stop_sign = self.detect_sign(img)
|
##stop_sign = self.detect_sign(img)
|
||||||
|
|
||||||
def get_road_curve(self, frame):
|
def get_road_curve(self, frame):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -132,8 +132,8 @@ class motion:
|
||||||
|
|
||||||
self.motor_write(MOTOR_FL_F, MOTOR_FL_R, abs(leftSpeed))
|
self.motor_write(MOTOR_FL_F, MOTOR_FL_R, abs(leftSpeed))
|
||||||
self.motor_write(MOTOR_FR_F, MOTOR_FR_R, abs(rightSpeed))
|
self.motor_write(MOTOR_FR_F, MOTOR_FR_R, abs(rightSpeed))
|
||||||
##self.motor_write(MOTOR_RL_F, MOTOR_RL_R, speed)
|
self.motor_write(MOTOR_RL_F, MOTOR_RL_R, speed)
|
||||||
##self.motor_write(MOTOR_RR_F, MOTOR_RR_R, speed)
|
self.motor_write(MOTOR_RR_F, MOTOR_RR_R, speed)
|
||||||
time.sleep(t)
|
time.sleep(t)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue