cgse-coordinates 2023.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,127 @@
1
+ """
2
+ A CSL reference frame model which has knowledge about the CSL Setup, and the PUNA Hexapod model.
3
+
4
+ The CSL Reference Frame Model incorporates a Hexapod PUNA model which is represented by the
5
+ Reference Frames HEXUSR, HEXOBJ, HEXMEC, and HEXPLT. A number of methods are defined here that
6
+ assume these four reference frames exist in the model and behave like a proper hexapod simulator.
7
+ Those methods start with the name `hexapod_`, e.g. `hexapod_goto_zero_position()`.
8
+
9
+ """
10
+ from typing import List
11
+
12
+ from egse.coordinates.refmodel import ReferenceFrameModel
13
+
14
+ HEXUSR = "hexusr"
15
+ HEXMEC = "hexmec"
16
+ HEXOBJ = "hexobj"
17
+ HEXPLT = "hexplt"
18
+ HEXOBUSR = "hexobusr"
19
+
20
+
21
+ class CSLReferenceFrameModel(ReferenceFrameModel):
22
+ """
23
+ The CSL Reference Frame Model is a specific reference model that adds convenience methods
24
+ for manipulating the Hexapod PUNA which is part of the overall CSH Setup.
25
+ """
26
+
27
+ _DEGREES_DEFAULT = ReferenceFrameModel._DEGREES_DEFAULT
28
+
29
+ def _create_obusr(self):
30
+
31
+ if HEXOBUSR in self:
32
+ return
33
+
34
+ hexusr = self.get_frame(HEXUSR)
35
+ hexobj = self.get_frame(HEXOBJ)
36
+
37
+ transformation = hexusr.getActiveTransformationTo(hexobj)
38
+
39
+ self.add_frame(HEXOBUSR, transformation=transformation, ref=HEXUSR)
40
+ self.add_link(HEXOBUSR, HEXOBJ)
41
+
42
+ def hexapod_move_absolute(self, translation, rotation, degrees=_DEGREES_DEFAULT):
43
+ """
44
+ Move/define the Object Coordinate System position and orientation expressed
45
+ in the invariant user coordinate system.
46
+
47
+ The rotation centre coincides with the Object Coordinates System origin and
48
+ the movements are controlled with translation components at first (Tx, Ty, tZ)
49
+ and then the rotation components (Rx, Ry, Rz).
50
+
51
+ Args:
52
+ translation: the translation vector
53
+ rotation: the rotation vector
54
+ degrees: use degrees [default: True]
55
+ """
56
+
57
+ self.move_absolute_self(HEXOBUSR, translation, rotation, degrees=degrees)
58
+
59
+ def hexapod_move_relative_object(self, translation, rotation, degrees=_DEGREES_DEFAULT):
60
+ """
61
+ Hexapod Command:
62
+ Move the object relative to its current object position and orientation.
63
+
64
+ The relative movement is expressed in the object coordinate system.
65
+
66
+ Args:
67
+ translation: the translation vector
68
+ rotation: the rotation vector
69
+ degrees: use degrees [default: True]
70
+ """
71
+
72
+ self.move_relative_self(HEXOBJ, translation, rotation, degrees=degrees)
73
+
74
+ def hexapod_move_relative_user(self, translation, rotation, degrees=_DEGREES_DEFAULT):
75
+ """
76
+ Hexapod Command:
77
+ Move the object relative to its current object position and orientation.
78
+
79
+ The relative movement is expressed in the (invariant) user coordinate system.
80
+
81
+ Args:
82
+ translation: the translation vector
83
+ rotation: the rotation vector
84
+ degrees: use degrees [default: True]
85
+ """
86
+
87
+ self.move_relative_other_local(HEXOBJ, HEXUSR, translation, rotation, degrees=degrees)
88
+
89
+ def hexapod_configure_coordinates(
90
+ self,
91
+ usr_trans: List[float],
92
+ usr_rot: List[float],
93
+ obj_trans: List[float],
94
+ obj_rot: List[float],
95
+ ):
96
+ """
97
+ Change the definition of the User Coordinate System and the Object Coordinate System in
98
+ the Hexapod.
99
+
100
+ The parameters tx_u, ty_u, tz_u, rx_u, ry_u, rz_u are used to define the user coordinate
101
+ system
102
+ relative to the Machine Coordinate System and the parameters tx_o, ty_o, tz_o, rx_o,
103
+ ry_o, rz_o
104
+ are used to define the Object Coordinate System relative to the Platform Coordinate System.
105
+
106
+ """
107
+
108
+ self.remove_link(HEXUSR, HEXMEC)
109
+ self.remove_link(HEXOBJ, HEXPLT)
110
+ self.get_frame(HEXUSR).setTranslationRotation(usr_trans, usr_rot)
111
+ self.get_frame(HEXOBJ).setTranslationRotation(obj_trans, obj_rot)
112
+ self.add_link(HEXUSR, HEXMEC)
113
+ self.add_link(HEXOBJ, HEXPLT)
114
+
115
+ def hexapod_goto_zero_position(self):
116
+ """
117
+ Ask the hexapod to go to the zero position.
118
+ """
119
+
120
+ self.move_absolute_self(HEXPLT, translation=[0, 0, 0], rotation=[0, 0, 0])
121
+
122
+ def hexapod_goto_retracted_position(self):
123
+ """
124
+ Ask the hexapod to go to its retracted position.
125
+ """
126
+
127
+ self.move_absolute_self(HEXPLT, translation=[0, 0, -20], rotation=[0, 0, 0])
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Sat Oct 3 11:53:23 2020
5
+
6
+ @author: pierre
7
+ """
8
+
9
+ import sys
10
+ import pandas
11
+
12
+
13
+ def laser_tracker_to_dict(filexls, setup):
14
+ """
15
+ laser_tracker_to_dict(filexls)
16
+
17
+ INPUT
18
+
19
+ filexls : CSL - provided excell file (from a laser tracker)
20
+
21
+ OUTPUT
22
+
23
+ dictionary compatible with egse.coordinates.dict_to_ref_model
24
+
25
+ Known Features:
26
+ - no link can be included:
27
+ the links are not in the xls file
28
+ hardcoding them would cause trouble when ingesting a partial model
29
+ - the ReferenceFrames references are included, but they are based
30
+ on a hardcoded model.
31
+ In particular it is assumed that gliso is the master!
32
+
33
+ - a "Master" ReferenceFrame is enforced, with the name "Master" (capital)
34
+
35
+ - the names of the reference frames are returned lowercase, without '_'
36
+ ("Master" is an exception)
37
+
38
+ """
39
+
40
+ # Predefined model -- gliso ~ master
41
+
42
+ """
43
+ predef_refs={}
44
+ predef_refs['gltab'] = 'glfix'
45
+ predef_refs['glfix'] = 'glrot'
46
+ predef_refs['glrot'] = 'gliso'
47
+
48
+ predef_refs['gliso'] = 'Master'
49
+ predef_refs['Master'] = 'Master'
50
+
51
+ predef_refs['hexiso'] = 'gliso'
52
+ predef_refs['hexmec'] = 'hexiso'
53
+ predef_refs['hexplt'] ='hexmec'
54
+ predef_refs['hexobj'] = 'hexplt'
55
+ predef_refs['hexobusr'] = 'hexusr'
56
+ predef_refs['hexusr'] = 'hexmec'
57
+ predef_refs['fpaaln'] = 'gliso'
58
+ predef_refs['fpasen'] = 'fpaaln'
59
+ predef_refs['fpamec'] = 'fpaaln'
60
+ predef_refs['toumec'] = 'gliso'
61
+ predef_refs['toul6'] = 'toumec'
62
+ predef_refs['toualn'] = 'toumec'
63
+ predef_refs['touopt'] = 'toualn'
64
+ predef_refs['marialn'] = 'toualn'
65
+ predef_refs['cammec'] = 'toualn'
66
+ predef_refs['cambor'] = 'toualn'
67
+ """
68
+
69
+ predef_refs=setup.csl_model.default_refs
70
+
71
+ # Read input file
72
+
73
+ pan = pandas.read_excel(filexls, sheet_name="Data", usecols="A:D", names=["desc", 'x', 'y', 'z'])
74
+
75
+ nrows = pan.shape[0]
76
+
77
+ desc = pan["desc"].values
78
+ colx = pan["x"].values
79
+ coly = pan["y"].values
80
+ colz = pan["z"].values
81
+
82
+ refFrames = {}
83
+ refFrames["Master"] = 'ReferenceFrame//([0.0000,0.0000,0.0000 | [0.0000,0.0000,0.0000 | Master | Master | [])'
84
+
85
+ links = '[]'
86
+
87
+ i,frame = -1,-1
88
+ while (i<nrows):
89
+ i += 1
90
+
91
+ try:
92
+ frame = desc[i].find("Frame")
93
+ except:
94
+ frame = -1
95
+ continue
96
+
97
+ if (frame >= 0):
98
+
99
+ try:
100
+ name = desc[i][desc[i].find("::")+2:].lower().replace("_","")
101
+
102
+ if (desc[i+2].lower().find("translation")<0) or (desc[i+3].lower().find('rotation')<0):
103
+ raise Exception(f"Unexpected File Structure after row {i} : {desc[i]}")
104
+
105
+ translation = f"[{float(colx[i+2]):.6f},{float(coly[i+2]):.6f},{float(colz[i+2]):.6f}"
106
+ rotation = f"[{float(colx[i+3]):.6f},{float(coly[i+3]):.6f},{float(colz[i+3]):.6f}"
107
+
108
+ if name in predef_refs.keys():
109
+ ref = predef_refs[name]
110
+ else:
111
+ ref = 'None'
112
+
113
+ refFrames[name] = f"ReferenceFrame//({translation} | {rotation} | {name} | {ref} | {links})"
114
+
115
+ except:
116
+ print(f"Frame extraction issue after row {i} : {desc[i]}")
117
+ print(sys.exc_info())
118
+
119
+ return refFrames
120
+