MAGIKS  1.1
Manipulator General Inverse Kinematic Solver
 All Classes Namespaces Files Functions Variables Pages
task_reference.py
Go to the documentation of this file.
1 ## @file: task_reference.py
2 # @brief: This module provides a class representing the reference poisitions and orientations of an endeffector and the desired value for it.
3 # @author Nima Ramezani Taghiabadi
4 #
5 # PhD Researcher
6 # Faculty of Engineering and Information Technology
7 # University of Technology Sydney (UTS)
8 # Broadway, Ultimo, NSW 2007, Australia
9 # Phone No. : 04 5027 4611
10 # Email(1) : nima.ramezani@gmail.com
11 # Email(2) : Nima.RamezaniTaghiabadi@uts.edu.au
12 # @version 1.0
13 #
14 # Last Revision: 28 January 2015
15 
16 import numpy, math, general_python as genpy
17 
18 from magiks.jacobian import jacobian as jaclib
19 from math_tools.algebra import vectors_and_matrices as vecmat
20 from math_tools.geometry import pose_metric, trajectory as trajlib, geometry as geo
21 
22 class Task_Reference(object):
23 
24  def __init__(self, config_settings):
25  self.config_settings = config_settings
26 
27  # "rd" represents the desired position for the reference position with respect to the ground coordinate system
28  self.rd = None
29 
30  self.geo_jac = jaclib.Geometric_Jacobian(self.config_settings)
31 
32  self.err_jac = jaclib.Error_Jacobian(self.config_settings)
33 
34  # "error" is an instance of class "Position_Metric" which represents the error between the desired and actual positions of the reference point
35  self.error = pose_metric.Metric()
36 
37  self.clear()
38 
39  self.priority_level = 'Main Task'
40 
41  def clear_error(self):
42  self.error.clear()
43  self.err_jac.clear()
44 
45  def clear(self):
46  # "ra" represents the position vector of the reference position with respect to the ground coordinate system.
47  self.ra = None
48  self.geo_jac.clear()
49  self.clear_error()
50 
51  def set_target(self, rd):
52  self.rd = rd
53  self.clear_error()
54 
55 
57  '''
58  refernce point only for introducing an endeffector position
59 
60  reference_position == Reference Position + Target Point for this reference position + actual position for this point
61 
62  "reference_position" is a class or data structure containing properties by which a point in the task space of a chained link manipulator is defined.
63 
64  TASK POSITION is RELATIVE to the "FRAME" of the link,
65  the "FRAME" of the link is determined via DH parameters and the zero configuration
66  '''
67 
68  def __init__(self, config_settings, link_point_list):
69  '''
70  link_point_list == WEIGHTING
71 
72  Create and define the default values for class properties
73  '''
74  super(Task_Point, self).__init__(config_settings)
75 
76  # "lp" is a list of link points. The position of reference position is defined by a linear combination of the listed link points.
77  self.lp = link_point_list
78  self.error = pose_metric.Position_Metric()
79 
80  def __str__(self):
81  s = " Actual Position (mm): " + vecmat.vector_to_str(1000*(self.ra)) + "\n"
82  s += " Desired Position (mm): " + vecmat.vector_to_str(1000*(self.rd)) + "\n"
83  s += " Position Error (mm): " + vecmat.vector_to_str(1000*(self.error.value(self.ra, self.rd))) + "\n"
84  return(s)
85 
86  def position(self, H):
87  if self.ra == None:
88  self.ra = numpy.zeros((3))
89  for j in range(0, len(self.lp)):
90  x = numpy.dot(H[self.lp[j].ln], vecmat.extend_vector(self.lp[j].pv))
91  self.ra = self.ra + self.lp[j].w * x[0:3]
92  return self.ra
93 
94  def error_jacobian(self, H, ajac):
95  if self.err_jac.value == None:
96  self.err_jac.update_for_position(self, ajac)
97  return self.err_jac.value
98 
99  def geometric_jacobian(self, ajac):
100  if self.geo_jac.value == None:
101  self.geo_jac.update_for_position(self, ajac)
102  return self.geo_jac.value
103 
105  '''
106  old name: Task_Frame :
107 
108  ## link_number is NOT part of this class / element but of the SET that holds / manages these classes/elements!
109  ## -> link_number DOES NOT determine the NATURE of a Reference_Orientation
110 
111  This class is used to introduce a reference orientation for the endeffector. The reference orientation is the orientation of link which is specified by: "link_number"
112  '''
113 
114  def __init__(self, config_settings, link_number):
115 
116  super(Task_Frame, self).__init__(config_settings)
117 
118  self.ln = link_number
119 
120  self.error = pose_metric.Orientation_Metric()
121 
122  def __str__(self):
123  s = " Actual Orientation :" + "\n" + "\n" + str(self.ra) + "\n"
124  s += " Desired Orientation:" + "\n" + "\n" + str(self.rd) + "\n"
125  s += " Orientation Error : " + vecmat.vector_to_str(self.error.value(self.ra,self.rd)) + "\n"
126  return(s)
127 
128  def orientation(self, H):
129  '''
130  update the actual (current) orientation of the reference orientation. Change property "ra"
131  '''
132  if self.ra == None:
133  # Extracting the orientation (Rotation Matrix) of each reference orientation from its corresponding transformation matrix
134  self.ra = geo.Orientation_3D(H[self.ln][ 0:3, 0:3 ])
135  return self.ra
136 
137  def error_jacobian(self, ajac):
138  if self.err_jac.value == None:
139  self.err_jac.update_for_orientation(self, ajac)
140  return self.err_jac.value
141 
142  def geometric_jacobian(self, H):
143  if self.geo_jac.value == None:
144  self.geo_jac.update_for_orientation(self, H)
145  return self.geo_jac.value
146