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,13 +8,15 @@ import cv2
import numpy as np import numpy as np
if __name__ == '__main__':
image = np.zeros((200, 200, 3), dtype=np.uint8) image = np.zeros((200, 200, 3), dtype=np.uint8)
window = 'HSV Explained' window = 'HSV Explained'
h, s, v = 0, 255, 255 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

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):