even further documentation

This commit is contained in:
2018-11-12 13:34:12 +01:00
parent 661c44f459
commit b9beddd4a4
5 changed files with 58 additions and 33 deletions

View File

@@ -1,6 +1,5 @@
"A script for calibrating the color and saving parameters." "A script for calibrating the color and saving parameters."
from __future__ import print_function from __future__ import print_function
from __future__ import division from __future__ import division

View File

@@ -1,3 +1,5 @@
"""Script explaining how HSV works."""
from __future__ import division, print_function from __future__ import division, print_function
import sys import sys
@@ -6,32 +8,34 @@ import cv2
import numpy as np import numpy as np
image = np.zeros((200, 200, 3), dtype=np.uint8) if __name__ == '__main__':
window = 'HSV Explained' image = np.zeros((200, 200, 3), dtype=np.uint8)
h, s, v = 0, 255, 255 window = 'HSV Explained'
h, s, v = 0, 255, 255
print('u, i, o: increase h, s, v respectively\n', print('u, i, o: increase h, s, v respectively',
'j, k, l: decrease h, s, v respectively\n', 'j, k, l: decrease h, s, v respectively',
'(focus on the image window for this)\n', sep='') '(focus on the image window for this and look at the terminal)',
sep='\n')
while True: while True:
image[:] = h, s, v image[:] = h, s, v
im2show = cv2.cvtColor(image, cv2.COLOR_HSV2BGR) im2show = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)
print(' HSV:', h, s, v, ' ', end='\r') print(' HSV:', h, s, v, ' ', end='\r')
sys.stdout.flush() sys.stdout.flush()
cv2.imshow(window, im2show) cv2.imshow(window, im2show)
key = cv2.waitKey(0) key = cv2.waitKey(0)
if key == ord('q'): if key == ord('q'):
break break
elif key == ord('u'): elif key == ord('u'):
h = (h + 1) % 180 h = (h + 1) % 180
elif key == ord('j'): elif key == ord('j'):
h = (h - 1) % 180 h = (h - 1) % 180
elif key == ord('i'): elif key == ord('i'):
s = min(s + 1, 255) s = min(s + 1, 255)
elif key == ord('k'): elif key == ord('k'):
s = max(s - 1, 0) s = max(s - 1, 0)
elif key == ord('o'): elif key == ord('o'):
v = min(v + 1, 255) v = min(v + 1, 255)
elif key == ord('l'): elif key == ord('l'):
v = max(v - 1, 0) v = max(v - 1, 0)

View File

@@ -155,8 +155,7 @@ class VideoReader(object):
raise ValueError('Error while reading video.\n' + raise ValueError('Error while reading video.\n' +
'Or video is over.') 'Or video is over.')
self.ctr += 1 self.ctr += 1
if (self.ctr == self.cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT) and if (self.ctr == self.cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT) and self.loop):
self.loop):
self.ctr = 0 self.ctr = 0
self.cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 0) self.cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 0)
return frame return frame

View File

@@ -1,3 +1,8 @@
"""Class with functions for easier movement of NAO.
And a command line script for some movements.
"""
# from time import sleep # from time import sleep
import argparse import argparse
from math import radians, pi from math import radians, pi
@@ -8,7 +13,7 @@ from .utils import read_config
class NaoMover(object): class NaoMover(object):
KICK_SEQUENCE = [ KICK_SEQUENCE = [ # DON'T USE THIS ONE
# lean to the side using the ankle joints # lean to the side using the ankle joints
[[(0, 1, 'ShoulderRoll', -70), [[(0, 1, 'ShoulderRoll', -70),
@@ -25,7 +30,7 @@ class NaoMover(object):
] ]
# fancy kick # fancy kick
KICK_SEQUENCE_FANCY = [ KICK_SEQUENCE_FANCY = [ # USE THIS ONE
# base_or_kicking, unsymmetric, joint, angle # base_or_kicking, unsymmetric, joint, angle
# lift the arm # lift the arm
@@ -53,7 +58,6 @@ class NaoMover(object):
0.5], 0.5],
] ]
def __init__(self, nao_ip, nao_port=9559): def __init__(self, nao_ip, nao_port=9559):
nao_ip = bytes(nao_ip) nao_ip = bytes(nao_ip)
self.mp = ALProxy('ALMotion', nao_ip, nao_port) self.mp = ALProxy('ALMotion', nao_ip, nao_port)
@@ -70,6 +74,12 @@ class NaoMover(object):
self.ready_to_move = False self.ready_to_move = False
def kick(self, foot='L', fancy=False): def kick(self, foot='L', fancy=False):
"""Kick the ball with the foot.
For now optimized for Left foot. Also please always
set fancy to True when calling this.
"""
self.set_arm_stiffness(0.8) self.set_arm_stiffness(0.8)
self.set_hip_stiffness(0.8) self.set_hip_stiffness(0.8)
self.set_knee_stiffness(0.8) self.set_knee_stiffness(0.8)
@@ -106,6 +116,7 @@ class NaoMover(object):
self.set_arm_stiffness() self.set_arm_stiffness()
def rest(self): def rest(self):
"""Send robot to resting position."""
self.mp.rest() self.mp.rest()
self.ready_to_move = False self.ready_to_move = False
@@ -150,10 +161,19 @@ class NaoMover(object):
return self.mp.getAngles(('HeadYaw', 'HeadPitch'), False) return self.mp.getAngles(('HeadYaw', 'HeadPitch'), False)
def change_head_angles(self, d_yaw, d_pitch, speed=0.5): def change_head_angles(self, d_yaw, d_pitch, speed=0.5):
"""Change the head angles by a relative amount.
This function DOES return before movement is finished.
"""
self.mp.changeAngles(('HeadYaw', 'HeadPitch'), self.mp.changeAngles(('HeadYaw', 'HeadPitch'),
(d_yaw, d_pitch), speed) (d_yaw, d_pitch), speed)
def change_head_angles_blocking(self, d_yaw, d_pitch, speed=0.5): def change_head_angles_blocking(self, d_yaw, d_pitch, speed=0.5):
"""Same as `change_head_angles` but block until finished.
Doesn't work quite as expected though. You may need to work on it.
"""
self.mp.angleInterpolatioWithSpeed(('HeadYaw', 'HeadPitch'), self.mp.angleInterpolatioWithSpeed(('HeadYaw', 'HeadPitch'),
(d_yaw, d_pitch), speed, False) (d_yaw, d_pitch), speed, False)

View File

@@ -1,3 +1,5 @@
"""Some convenience functions which I leave up to you to explore."""
from __future__ import division from __future__ import division
import os import os
@@ -41,6 +43,7 @@ def hsv_mask(hsv, hsv_lower, hsv_upper):
else: else:
return cv2.inRange(hsv, tuple(hsv_lower), tuple(hsv_upper)) return cv2.inRange(hsv, tuple(hsv_lower), tuple(hsv_upper))
class InterruptDelayed(object): class InterruptDelayed(object):
def __enter__(self): def __enter__(self):