@@ -214,19 +214,63 @@ def ini_preamble():
214214
215215 return inistring , newini , all_sections
216216
217- # We need info from TRAJ to get KINS right
218- def get_joints_coordinates ():
217+ if version == "1.0" :
218+ #Just update the version in the INI
219+ inistring = open (filename ,'r' ).read ()
220+ newini = open (filename , 'w' )
221+ inistring = re .sub ("VERSION *= *(.*)" , "VERSION = %s" % THIS_VERSION , inistring )
222+ newini .write (inistring )
223+ newini .close ()
224+
225+ if version == "$Revision$" or version < "1.0" :
226+ inistring , newini , all_sections = ini_preamble ()
227+ #These sections don't need any work.
228+ copysection ("DISPLAY" )
229+ copysection ("FILTER" )
230+
231+ #[RS274NGC] Section, change FEATURES to separate entries
232+ all_sections .remove ("RS274NGC" )
233+ section = re .search (r"\[RS274NGC\](.+?)\n\[" , inistring , re .DOTALL )
234+ if section : section = section .group (1 )
235+ newini .write ("\n [RS274NGC]\n " )
236+ if section != None :
237+ features = ini .find ('RS274NGC' , 'FEATURES' )
238+ if features != None :
239+ features = int (features )
240+ section = re .sub ("FEATURES.*?\n " , "" , section )
241+ section += ("RETAIN_G43 = %s\n " % ("1" if features & 0x1 else "0" ))
242+ section += ("INI_VARS = %s\n " % ("1" if features & 0x4 else "0" ))
243+ section += ("HAL_PIN_VARS = %s\n " % ("1" if features & 0x8 else "0" ))
244+ if features & 0x2 : section += ("OWORD_NARGS = 1\n " )
245+ if features & 0x10 : section += ("NO_DOWNCASE_OWORD = 1\n " )
246+ if features & 0x20 : section += ("OWORD_WARNONLY = 1\n " )
247+ section += "\n "
248+ newini .write (section )
249+
250+ all_sections .remove ("EMCMOT" )
251+ section = re .search (r"\[EMCMOT\](.+?)\n\[" , inistring , re .DOTALL )
252+ if section : section = section .group (1 )
253+ newini .write ("[EMCMOT]\n " )
254+ section = re .sub ("# Interval between tries to emcmot.*?\n " , "" , section )
255+ section = re .sub ("COMM_WAIT.*?\n " , "" , section )
256+ newini .write (section )
257+
258+ copysection ("TASK" )
259+ copysection ("HAL" )
260+ copysection ("HALUI" )
261+
262+ # We need info from TRAJ to get KINS right
263+
219264 joints = ini .find ("TRAJ" , "JOINTS" )
220265 coordinates = ini .find ("TRAJ" , "COORDINATES" ).replace (" " ,"" )
221266 if coordinates != None : joints = len (coordinates )
222267 if joints == None : joints = ini .find ("TRAJ" , "AXES" )
223268 if joints == None : joints = "3"
224269 joints = int (joints )
225270 if coordinates == None : coordinates = "XYZABCUVW"
271+
226272 coordinates = list (coordinates )
227- return joints , coordinates
228273
229- def get_kins (joints , coordinates ):
230274 # Search the Halfiles to find the kinematics.
231275 kins = None
232276 kinstype = None
@@ -250,7 +294,7 @@ def get_kins(joints, coordinates):
250294
251295 #gantrykins and gentrivkins are gone, so need special treatment
252296
253- if kins == "gantrykins" :
297+ if kins == "gantrykins" :
254298 kins = "trivkins"
255299 kinstype = "BOTH"
256300 coords_entry = True
@@ -266,58 +310,6 @@ def get_kins(joints, coordinates):
266310
267311 if kins == "gentrivkins" :
268312 kins = "trivkins" #trivkins has the same defaults as gentrivkins
269-
270- return kins , kinstype , coords_entry
271-
272-
273-
274- if version == "1.0" :
275- #Just update the version in the INI
276- inistring = open (filename ,'r' ).read ()
277- newini = open (filename , 'w' )
278- inistring = re .sub ("VERSION *= *(.*)" , "VERSION = %s" % THIS_VERSION , inistring )
279- newini .write (inistring )
280- newini .close ()
281-
282- if version == "$Revision$" or version < "1.0" :
283- inistring , newini , all_sections = ini_preamble ()
284- #These sections don't need any work.
285- copysection ("DISPLAY" )
286- copysection ("FILTER" )
287-
288- #[RS274NGC] Section, change FEATURES to separate entries
289- all_sections .remove ("RS274NGC" )
290- section = re .search (r"\[RS274NGC\](.+?)\n\[" , inistring , re .DOTALL )
291- if section : section = section .group (1 )
292- newini .write ("\n [RS274NGC]\n " )
293- if section != None :
294- features = ini .find ('RS274NGC' , 'FEATURES' )
295- if features != None :
296- features = int (features )
297- section = re .sub ("FEATURES.*?\n " , "" , section )
298- section += ("RETAIN_G43 = %s\n " % ("1" if features & 0x1 else "0" ))
299- section += ("INI_VARS = %s\n " % ("1" if features & 0x4 else "0" ))
300- section += ("HAL_PIN_VARS = %s\n " % ("1" if features & 0x8 else "0" ))
301- if features & 0x2 : section += ("OWORD_NARGS = 1\n " )
302- if features & 0x10 : section += ("NO_DOWNCASE_OWORD = 1\n " )
303- if features & 0x20 : section += ("OWORD_WARNONLY = 1\n " )
304- section += "\n "
305- newini .write (section )
306-
307- all_sections .remove ("EMCMOT" )
308- section = re .search (r"\[EMCMOT\](.+?)\n\[" , inistring , re .DOTALL )
309- if section : section = section .group (1 )
310- newini .write ("[EMCMOT]\n " )
311- section = re .sub ("# Interval between tries to emcmot.*?\n " , "" , section )
312- section = re .sub ("COMM_WAIT.*?\n " , "" , section )
313- newini .write (section )
314-
315- copysection ("TASK" )
316- copysection ("HAL" )
317- copysection ("HALUI" )
318-
319- joints , coordinates = get_joints_coordinates ()
320- kins , kinstype , coords_entry = get_kins (joints , coordinates )
321313
322314 # In JA [TRAJ] expects MAX_LINEAR_VELOCITY not MAX_VELOCITY
323315 all_sections .remove ("TRAJ" )
@@ -348,7 +340,6 @@ def get_kins(joints, coordinates):
348340
349341 # Insert the new-fangled [KINS] section
350342
351- coords_entry = True
352343 newini .write ("\n \n [KINS]\n " )
353344 newini .write ("KINEMATICS = %s" % kins )
354345 if coords_entry : newini .write (" coordinates=%s" % '' .join (coordinates [: joints ]))
@@ -490,96 +481,9 @@ def get_kins(joints, coordinates):
490481 copysection ("TRAJ" )
491482 copysection ("EMCIO" )
492483
493- joints , coordinates = get_joints_coordinates ()
494- kins , kinstype , coords_entry = get_kins (joints , coordinates )
495-
496- newini .write ("\n \n [KINS]\n " )
497- newini .write ("KINEMATICS = %s" % kins )
498- if coords_entry : newini .write (" coordinates=%s" % '' .join (coordinates [: joints ]))
499- if kinstype : newini .write (" kinstype=%s" % kinstype )
500- newini .write ("\n " )
501- newini .write ("#This is a best-guess at the number of joints, it should be checked\n " )
502- newini .write ("JOINTS = %i\n " % joints )
503-
504- j = 0
505- lock_mask = 0x0
506- L2J = {}
507- while 1 :
508- # Search preferentially in "[JOINT_N] in case the file is part-converted already
509- if re .search (r"^(\[JOINT_%i\])" % j , inistring , re .MULTILINE ):
510- if re .search (r"^(\[AXIS_%s\])" % "XYZABCUVW" [j ], inistring , re .MULTILINE ):
511- copysection ("AXIS_%s" % "XYZABCUVW" [j ])
512- # copysection("JOINT_%i" % j)
513- elif j < len (coordinates ):
514- newini .write ("\n [AXIS_%s]\n " % coordinates [j ])
515- writeifexists (newini , "JOINT_%i" % j , "HOME" )
516- writeifexists (newini , "JOINT_%i" % j , "MIN_LIMIT" )
517- writeifexists (newini , "JOINT_%i" % j , "MAX_LIMIT" )
518- writeifexists (newini , "JOINT_%i" % j , "MAX_VELOCITY" )
519- writeifexists (newini , "JOINT_%i" % j , "MAX_ACCELERATION" )
520- copysection ("[JOINT_%i]" % j )
521- elif j < len (coordinates ):
522- # in this "elif" j is an index in to coordinates.
523- if coordinates [j ] in L2J : # duplicate axis letter
524- L2J [coordinates [j ]].append (j ) # = [L2J[coordinates[j]], j]
525- else :
526- L2J .update ({coordinates [j ] : [j ]})
527- elif j >= 9 :
528- break
529- else :
530- pass
531-
532- j += 1
533-
534- for L in list ("XYZABCUVW" ):
535- if L in L2J :
536- axisnum = "XYZABCUVW" .index (L )
537- newini .write ("\n [AXIS_%s]\n " % L )
538- writeifexists (newini , "AXIS_%i" % axisnum , "MIN_LIMIT" )
539- writeifexists (newini , "AXIS_%i" % axisnum , "MAX_LIMIT" )
540- writeifexists (newini , "AXIS_%i" % axisnum , "MAX_VELOCITY" )
541- writeifexists (newini , "AXIS_%i" % axisnum , "MAX_ACCELERATION" )
542- if ini .find ("AXIS_%i" % j , "LOCKING_INDEXER" ):
543- lock_mask |= 1 << j
544- newini .write ("LOCKING_INDEXER_JOINT = %i\n " % j )
545-
546- hs = ini .find ("AXIS_%i" % axisnum , "HOME_SEQUENCE" )
547- if hs == "-1" or hs == None : # -1 used to exclude a joint now we use no entry
548- sequence = ""
549- elif len (L2J [L ]) > 1 : # tandem axis
550- sequence = "HOME_SEQUENCE = -%s" % hs
551- else :
552- sequence = "HOME_SEQUENCE = %s" % hs
553- for J in L2J [L ]:
554- # Take the coordinates index as the JOINT_Number
555- newini .write ("\n [JOINT_%i]" % J )
556- section = re .search (r"\[AXIS_%i\](.+?)(\n\[|$)" % J , inistring , re .DOTALL )
557- if not section :
558- section = re .search (r"\[AXIS_%i\](.+?)(\n\[|$)" % "XYZABCUVW" .index (coordinates [J ]), inistring , re .DOTALL )
559- if section :
560- section = re .sub ("HOME_SEQUENCE.*" , sequence , section .group (1 ))
561- newini .write (section )
562- if not r'\[AXIS_%i\]' % axisnum in subs :
563- subs .update ({r'\[AXIS_%i\]' % axisnum : '[JOINT_%i]' % J })
564- subs2 .update ({r'joint\.%i\.' % axisnum : 'joint.%i.' % J })
565- else :
566- subs .update ({r'\[AXIS_%i\]' % J : '[JOINT_%i]' % J })
567- else :
568- print ("File parsing error, found an [AXIS_%i] section, but no content" % J )
569- exit ()
570- # We no longer need the [AXIS_N] data
571- for j in range (0 ,8 ):
572- if ("AXIS_%i" % j ) in all_sections : all_sections .remove ("AXIS_%i" % j )
573-
574484 # If there were any custom sections, tag them on the end.
575485 while all_sections :
576486 copysection (all_sections [0 ])
577-
578- # and turn the locking mask into a string
579- if lock_mask :
580- lock_string = 'unlock_joints_mask=%i' % lock_mask
581- else :
582- lock_string = ""
583487
584488 #That's the INI file done:
585489 newini .close ()
0 commit comments