Go to the documentation of this file.00001 import numpy as np
00002
00003
00004 def random_pose_generator(n_poses=1):
00005 """A generator that yields random poses, position: [x,y,z] orientation: [x,y,z,w]."""
00006 for i in xrange(n_poses):
00007 orient = np.random.random(4)
00008 mag = np.sqrt(sum(np.power(orient, 2)))
00009 yield np.random.random(3), orient / mag
00010
00011
00012 def poses_from_file(filepath):
00013 """A generator that yields poses from file, position: [x,y,z] orientation: [x,y,z,w]."""
00014 with open(filepath) as f:
00015 for line in f.readlines():
00016 if len(line) > 10:
00017 vals = [float(n) for n in line.strip('\n').split(' ')[:7]]
00018 mag = np.sqrt(sum(np.power(vals[3:], 2)))
00019 yield vals[:3], vals[3:] / mag
00020
00021
00022 def random_joint_angles_generator(n_poses=1):
00023 """A generator that yields random joint angles."""
00024 for i in xrange(n_poses):
00025
00026
00027
00028
00029
00030 offset = np.array([0.0, -0.5 * np.pi, -0.5 * np.pi, 0.0, 0.0, 0.0])
00031 scale = np.array([2 * np.pi, 2.1, 3.2, 2 * np.pi, 2 * np.pi, 2 * np.pi])
00032 yield (np.random.random(6) - 0.5) * scale + offset
00033
00034
00035 def joint_angles_from_file(filepath):
00036 """A generator that yields joint angles from file."""
00037 with open(filepath) as f:
00038 for line in f.readlines():
00039 if len(line) > 10:
00040 yield [float(n) for n in line.strip('\n').split(' ')[:6]]
00041
00042
00043 def random_jaco_finger_positions(n_positions=1):
00044 """ """
00045 for i in xrange(n_positions):
00046
00047 yield np.random.random(3) * 55.75 + 0.25
00048
00049
00050 def random_mico_finger_positions(n_positions=1):
00051 """ """
00052 for i in xrange(n_positions):
00053
00054 yield np.random.random(2) * 6300.0 + 12.0
00055
00056
00057 if __name__ == '__main__':
00058
00059 print('You probably want to include these functions in a larger project')
00060 print('rather than executing this file on its own, but here are some ')
00061 print('things these functions can do!\n')
00062
00063 print('Use random_pose_generator() to generate five random poses:')
00064 for position, orientation in random_pose_generator(5):
00065 print(' position: {}, orientation: {}'.format(position, orientation))
00066 print('')
00067
00068 print('Use poses_from_file() to load a predefined sequence of poses:')
00069 for position, orientation in poses_from_file('pose_sequences/demo_pose_sequence.txt'):
00070 print(' position: {}, orientation: {}'.format(position, orientation))
00071 print('')
00072
00073 print('Use random_joint_angles_generator() to generate five random sets of joint angles:')
00074 for angle_set in random_joint_angles_generator(5):
00075 print(' angles: {}'.format(angle_set))
00076 print('')
00077
00078 print('Use joint_angles_from_file() to load a predefined sequence of poses:')
00079 for angle_set in joint_angles_from_file('joint_sequences/demo_joint_sequence.txt'):
00080 print(' angles: {}'.format(angle_set))
00081 print('')
00082
00083 print('Use random_finger_positions() to generate five random sets of finger positions:')
00084 for positions in random_jaco_finger_positions(5, n_fingers=3):
00085 print(' positions: {}'.format(positions))
00086 print('')