diff --git a/pykick/colorpicker.py b/pykick/colorpicker.py index 543d2be..63fb1db 100644 --- a/pykick/colorpicker.py +++ b/pykick/colorpicker.py @@ -1,6 +1,5 @@ "A script for calibrating the color and saving parameters." - from __future__ import print_function from __future__ import division diff --git a/pykick/hsv_render.py b/pykick/hsv_render.py index 3e921fe..a04234e 100644 --- a/pykick/hsv_render.py +++ b/pykick/hsv_render.py @@ -1,3 +1,5 @@ +"""Script explaining how HSV works.""" + from __future__ import division, print_function import sys @@ -6,32 +8,34 @@ import cv2 import numpy as np -image = np.zeros((200, 200, 3), dtype=np.uint8) -window = 'HSV Explained' -h, s, v = 0, 255, 255 +if __name__ == '__main__': + image = np.zeros((200, 200, 3), dtype=np.uint8) + window = 'HSV Explained' + h, s, v = 0, 255, 255 -print('u, i, o: increase h, s, v respectively\n', - 'j, k, l: decrease h, s, v respectively\n', - '(focus on the image window for this)\n', sep='') + print('u, i, o: increase h, s, v respectively', + 'j, k, l: decrease h, s, v respectively', + '(focus on the image window for this and look at the terminal)', + sep='\n') -while True: - image[:] = h, s, v - im2show = cv2.cvtColor(image, cv2.COLOR_HSV2BGR) - print(' HSV:', h, s, v, ' ', end='\r') - sys.stdout.flush() - cv2.imshow(window, im2show) - key = cv2.waitKey(0) - if key == ord('q'): - break - elif key == ord('u'): - h = (h + 1) % 180 - elif key == ord('j'): - h = (h - 1) % 180 - elif key == ord('i'): - s = min(s + 1, 255) - elif key == ord('k'): - s = max(s - 1, 0) - elif key == ord('o'): - v = min(v + 1, 255) - elif key == ord('l'): - v = max(v - 1, 0) + while True: + image[:] = h, s, v + im2show = cv2.cvtColor(image, cv2.COLOR_HSV2BGR) + print(' HSV:', h, s, v, ' ', end='\r') + sys.stdout.flush() + cv2.imshow(window, im2show) + key = cv2.waitKey(0) + if key == ord('q'): + break + elif key == ord('u'): + h = (h + 1) % 180 + elif key == ord('j'): + h = (h - 1) % 180 + elif key == ord('i'): + s = min(s + 1, 255) + elif key == ord('k'): + s = max(s - 1, 0) + elif key == ord('o'): + v = min(v + 1, 255) + elif key == ord('l'): + v = max(v - 1, 0) diff --git a/pykick/imagereaders.py b/pykick/imagereaders.py index 89ee4cf..81613eb 100644 --- a/pykick/imagereaders.py +++ b/pykick/imagereaders.py @@ -155,8 +155,7 @@ class VideoReader(object): raise ValueError('Error while reading video.\n' + 'Or video is over.') self.ctr += 1 - if (self.ctr == self.cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT) and - self.loop): + if (self.ctr == self.cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT) and self.loop): self.ctr = 0 self.cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 0) return frame diff --git a/pykick/movements.py b/pykick/movements.py index 638a1c4..238f850 100644 --- a/pykick/movements.py +++ b/pykick/movements.py @@ -1,3 +1,8 @@ +"""Class with functions for easier movement of NAO. + +And a command line script for some movements. +""" + # from time import sleep import argparse from math import radians, pi @@ -8,7 +13,7 @@ from .utils import read_config class NaoMover(object): - KICK_SEQUENCE = [ + KICK_SEQUENCE = [ # DON'T USE THIS ONE # lean to the side using the ankle joints [[(0, 1, 'ShoulderRoll', -70), @@ -25,7 +30,7 @@ class NaoMover(object): ] # fancy kick - KICK_SEQUENCE_FANCY = [ + KICK_SEQUENCE_FANCY = [ # USE THIS ONE # base_or_kicking, unsymmetric, joint, angle # lift the arm @@ -53,7 +58,6 @@ class NaoMover(object): 0.5], ] - def __init__(self, nao_ip, nao_port=9559): nao_ip = bytes(nao_ip) self.mp = ALProxy('ALMotion', nao_ip, nao_port) @@ -70,6 +74,12 @@ class NaoMover(object): self.ready_to_move = 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_hip_stiffness(0.8) self.set_knee_stiffness(0.8) @@ -106,6 +116,7 @@ class NaoMover(object): self.set_arm_stiffness() def rest(self): + """Send robot to resting position.""" self.mp.rest() self.ready_to_move = False @@ -150,10 +161,19 @@ class NaoMover(object): return self.mp.getAngles(('HeadYaw', 'HeadPitch'), False) 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'), (d_yaw, d_pitch), speed) 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'), (d_yaw, d_pitch), speed, False) diff --git a/pykick/utils.py b/pykick/utils.py index 5dee47e..96d3897 100644 --- a/pykick/utils.py +++ b/pykick/utils.py @@ -1,3 +1,5 @@ +"""Some convenience functions which I leave up to you to explore.""" + from __future__ import division import os @@ -41,6 +43,7 @@ def hsv_mask(hsv, hsv_lower, hsv_upper): else: return cv2.inRange(hsv, tuple(hsv_lower), tuple(hsv_upper)) + class InterruptDelayed(object): def __enter__(self):