Commit 3a06ccc5e97178ca9f891f2a784af1372d9cb3dd

Authored by Alain Klotz
1 parent 267a8905
Exists in master

Update and debug motoraxis.

Showing 1 changed file with 100 additions and 27 deletions   Show diff stats
src/guitastro/motoraxis.py
... ... @@ -142,24 +142,32 @@ class Motoraxis(GuitastroTools):
142 142  
143 143 def nat2phy(self, rot, lin, **kwargs):
144 144 # This function must be over defined
145   - # default physical unit = rot
146   - phy = rot
  145 + # Here we return only the value corresponding to the axis type
  146 + if self.axis_type == "LIN":
  147 + phy = lin
  148 + else:
  149 + phy = rot
147 150 return phy
148 151  
149 152 def phy2nat(self, phy, **kwargs):
150 153 # This function must be over defined
151 154 # default physical unit = rot
152   - rot = phy
153   - lin = rot /360 * self._mm_per_turn
  155 + if self.axis_type == "LIN":
  156 + lin = phy
  157 + if self._mm_per_turn != 0:
  158 + rot = lin * 360 / self._mm_per_turn
  159 + else:
  160 + rot = 0
  161 + else:
  162 + rot = phy
  163 + lin = rot /360 * self._mm_per_turn
154 164 return rot, lin
155 165  
156   - def _set_compute_phy(self, nat2phy, phy2nat=None):
157   - self._nat2phy = nat2phy
158   - if phy2nat != None:
159   - self._phy2nat = phy2nat
  166 + def _set_define_phy(self, nat2phy_phy2nat: list):
  167 + self._nat2phy, self._phy2nat = nat2phy_phy2nat
160 168  
161   - def _get_compute_phy(self):
162   - return self._nat2phy, self._phy2nat
  169 + def _get_define_phy(self) -> list:
  170 + return [self._nat2phy, self._phy2nat]
163 171  
164 172 def _set_phy_unit(self, unit:str):
165 173 self._phy_unit = unit
... ... @@ -337,7 +345,7 @@ class Motoraxis(GuitastroTools):
337 345 """
338 346 return self._phys
339 347  
340   - def _set_physimu(self, phy:float) -> int:
  348 + def _set_physimu(self, phy:float) -> float:
341 349 """Set the physical simulated value.
342 350  
343 351 Args:
... ... @@ -346,7 +354,7 @@ class Motoraxis(GuitastroTools):
346 354 self._physimu = phy
347 355 return self.NO_ERROR
348 356  
349   - def _get_physimu(self) -> int:
  357 + def _get_physimu(self) -> float:
350 358 """Set the physical simulated value.
351 359  
352 360 Returns:
... ... @@ -612,7 +620,7 @@ class Motoraxis(GuitastroTools):
612 620 incsimu = property(_get_incsimu , _set_incsimu)
613 621 physimu = property(_get_physimu , _set_physimu)
614 622  
615   - compute_phy = property(_get_compute_phy , _set_compute_phy)
  623 + define_phy = property(_get_define_phy , _set_define_phy)
616 624  
617 625 slew_deg_per_sec = property(_get_slew_deg_per_sec , _set_slew_deg_per_sec)
618 626 slewmax_deg_per_sec = property(_get_slewmax_deg_per_sec , _set_slewmax_deg_per_sec)
... ... @@ -660,12 +668,12 @@ class Motoraxis(GuitastroTools):
660 668 -------------------- SIMU INC -> ANG = LIN
661 669 inc = 0.0 : inc is read from encoder
662 670 rot = 0.0000000 : rot = (inc - inc0) * senseinc / inc_per_deg
663   - lin = 0.0000000 : m
  671 + lin = 0.0000000 : mm
664 672 phy = 0.0000000 : deg
665 673 -------------------- REAL INC -> ANG = LIN
666 674 inc = 0.0 : inc is read from encoder
667 675 rot = 0.0000000 : rot = (inc - inc0) * senseinc / inc_per_deg
668   - lin = 0.0000000 : m
  676 + lin = 0.0000000 : mm
669 677 phy = 0.0000000 : deg
670 678  
671 679 """
... ... @@ -697,7 +705,7 @@ class Motoraxis(GuitastroTools):
697 705 print("{} {} INC -> ROT, LIN, PHY".format(20*"-",msg_simu))
698 706 print("inc = {:12.1f} : inc is read from encoder ".format(inc))
699 707 print("rot = {:12.7f} : rot = (inc - inc0) * senseinc / inc_per_deg".format(rot))
700   - print("lin = {:12.7f} : m ".format(lin))
  708 + print("lin = {:12.7f} : mm ".format(lin))
701 709 print("phy = {:12.7f} : {}".format(phy, self.phy_unit))
702 710  
703 711 def synchro_real2simu(self):
... ... @@ -728,7 +736,8 @@ class Motoraxis(GuitastroTools):
728 736 inc = self._inc
729 737 rot = self.inc2rot(inc)
730 738 lin = self.rot2lin(rot)
731   - phy = self.nat2phy(rot, lin)
  739 + xnat2phy, xphy2nat = maxis.define_phy
  740 + phy = xnat2phy(rot, lin)
732 741 self._incsimu = inc
733 742 self._rotsimu = rot
734 743 self._linsimu = lin
... ... @@ -753,7 +762,8 @@ class Motoraxis(GuitastroTools):
753 762 inc = self._incsimu
754 763 rot = self.inc2rot(inc)
755 764 lin = self.rot2lin(rot)
756   - phy = self.nat2phy(rot, lin)
  765 + xnat2phy, xphy2nat = maxis.define_phy
  766 + phy = xnat2phy(rot, lin)
757 767 self._inc = inc
758 768 self._rot = rot
759 769 self._lin = lin
... ... @@ -846,8 +856,8 @@ class Motoraxis(GuitastroTools):
846 856  
847 857 The save parameter allows to update the real or simu internal values of and, pierside and rot:
848 858  
849   - * SAVE_AS_SIMU: Only _physimu, _rotsimu and _piersidesimu for simulated values are updated.
850   - * SAVE_AS_REAL: Only _ang, _rot and _pierside for real values are updated.
  859 + * SAVE_AS_SIMU: Only _physimu, _rotsimu for simulated values are updated.
  860 + * SAVE_AS_REAL: Only _ang, _rot for real values are updated.
851 861 * SAVE_NONE: No internal variables are updates.
852 862  
853 863 Instanciation of the axis is indispensable.
... ... @@ -1201,6 +1211,7 @@ class Motoraxis(GuitastroTools):
1201 1211 # --- Dico of optional parameters for all axis_types
1202 1212 param_optionals = {}
1203 1213 param_optionals["INC_PER_MOTOR_REV"] = (float, 1000.0)
  1214 + param_optionals["MM_PER_MOTOR_REV"] = (float, 0.0)
1204 1215 param_optionals["INC0"] = (float, 0.0)
1205 1216 param_optionals["SENSEINC"] = (float, Motoraxis.POSITIVE)
1206 1217 param_optionals["SENSEANG"] = (float, Motoraxis.POSITIVE)
... ... @@ -1223,6 +1234,8 @@ class Motoraxis(GuitastroTools):
1223 1234 self._language_protocol = self._axis_params["LANGUAGE_PROTOCOL"]
1224 1235 # === relations mechanics and inc
1225 1236 self.inc_per_motor_rev = self._axis_params["INC_PER_MOTOR_REV"]
  1237 + # === relations mechanics and mm
  1238 + self.mm_per_motor_rev = self._axis_params["MM_PER_MOTOR_REV"]
1226 1239 # === relations angle and inc
1227 1240 self.inc0 = self._axis_params["INC0"]
1228 1241 self.senseinc = self._axis_params["SENSEINC"]
... ... @@ -1246,8 +1259,11 @@ class Motoraxis(GuitastroTools):
1246 1259 self._history = []
1247 1260 self._simu_start_t0 = time.time()
1248 1261 # ===
1249   - self.compute_phy = self.nat2phy, self.phy2nat
1250   - self._phy_unit = "deg"
  1262 + self.define_phy = [self.nat2phy, self.phy2nat]
  1263 + if self.axis_type == "LIN":
  1264 + self._phy_unit = "mm"
  1265 + else:
  1266 + self._phy_unit = "deg"
1251 1267  
1252 1268 # #####################################################################
1253 1269 # #####################################################################
... ... @@ -1260,8 +1276,8 @@ class Motoraxis(GuitastroTools):
1260 1276 if __name__ == "__main__":
1261 1277 cwd = os.getcwd()
1262 1278  
1263   - default = 1
1264   - example = input(f"Select the example (0 to 1) ({default}) ")
  1279 + default = 2
  1280 + example = input(f"Select the example (0 to 3) ({default}) ")
1265 1281 try:
1266 1282 example = int(example)
1267 1283 except:
... ... @@ -1270,13 +1286,70 @@ if __name__ == "__main__":
1270 1286 print("Example = {}".format(example))
1271 1287  
1272 1288 if example == 1:
  1289 + """
  1290 + Pure rotation motor
  1291 + """
  1292 + inc_per_motor_rev = 1000.0
  1293 + # ---
  1294 + maxis = Motoraxis("ROT", name = "Test of a pure rotation motor", inc_per_motor_rev=inc_per_motor_rev, inc0=0, senseinc=1, real=False)
  1295 + maxis.disp()
  1296 + maxis.simu_motion_start("SLEW", position=1000, velocity=100, frame='inc', drift=0)
  1297 + time.sleep(1)
  1298 + inc = maxis.simu_update_inc()
  1299 + rot = maxis.inc2rot(inc, maxis.SAVE_AS_SIMU)
  1300 + lin = maxis.rot2lin(rot, maxis.SAVE_AS_SIMU)
  1301 + nat2phy, phy2nat = maxis.define_phy
  1302 + maxis.physimu = nat2phy(rot, lin)
  1303 + maxis.synchro_simu2real()
  1304 + maxis.disp()
1273 1305  
1274   - inc_per_motor_rev = 1000.0 ; # IMC parameter. System Confg -> System Parameters - Distance/Revolution
  1306 + if example == 2:
  1307 + """
  1308 + Translation motor
  1309 + """
  1310 + inc_per_motor_rev = 1000.0
  1311 + mm_per_motor_rev = 2.0
1275 1312 # ---
1276   - maxis = Motoraxis("LIN", name = "test", inc_per_motor_rev=inc_per_motor_rev, inc0=0, senseinc=1, real=False)
  1313 + maxis = Motoraxis("LIN", name = "Test of a translation motor", inc_per_motor_rev=inc_per_motor_rev, inc0=0, senseinc=1, real=False, mm_per_motor_rev=mm_per_motor_rev)
1277 1314 maxis.disp()
1278 1315 maxis.simu_motion_start("SLEW", position=1000, velocity=100, frame='inc', drift=0)
1279 1316 time.sleep(1)
1280 1317 inc = maxis.simu_update_inc()
1281   - maxis.inc2rot(inc, maxis.SAVE_AS_SIMU)
  1318 + rot = maxis.inc2rot(inc, maxis.SAVE_AS_SIMU)
  1319 + lin = maxis.rot2lin(rot, maxis.SAVE_AS_SIMU)
  1320 + nat2phy, phy2nat = maxis.define_phy
  1321 + maxis.physimu = nat2phy(rot, lin)
1282 1322 maxis.synchro_simu2real()
  1323 + maxis.disp()
  1324 +
  1325 + if example == 3:
  1326 + """
  1327 + Motor with a physical unit (phy is inches)
  1328 + """
  1329 + inc_per_motor_rev = 1000.0
  1330 + mm_per_motor_rev = 2.0
  1331 + def nat2phy(rot, lin, **kwargs):
  1332 + # Arguments are imposed
  1333 + phy = lin / 2.54
  1334 + return phy
  1335 + def phy2nat(phy, **kwargs):
  1336 + # Arguments are imposed
  1337 + mm_per_motor_rev = 2.0
  1338 + lin = phy * 2.54
  1339 + rot = lin * 360 / mm_per_motor_rev
  1340 + return rot, lin
  1341 + # ---
  1342 + maxis = Motoraxis("LIN", name = "Test of a physical unit", inc_per_motor_rev=inc_per_motor_rev, inc0=0, senseinc=1, real=False, mm_per_motor_rev=mm_per_motor_rev)
  1343 + maxis.define_phy = [nat2phy, phy2nat]
  1344 + maxis.phy_unit = "inch"
  1345 + # ---
  1346 + maxis.disp()
  1347 + maxis.simu_motion_start("SLEW", position=1000, velocity=100, frame='inc', drift=0)
  1348 + time.sleep(1)
  1349 + inc = maxis.simu_update_inc()
  1350 + rot = maxis.inc2rot(inc, maxis.SAVE_AS_SIMU)
  1351 + lin = maxis.rot2lin(rot, maxis.SAVE_AS_SIMU)
  1352 + xnat2phy, xphy2nat = maxis.define_phy
  1353 + maxis.physimu = xnat2phy(rot, lin)
  1354 + maxis.synchro_simu2real()
  1355 + maxis.disp()
... ...