-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMotionSynchSRC.py
64 lines (51 loc) · 3.2 KB
/
MotionSynchSRC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# This code is to use on a SRC file to make the program for the KUKA Robots to work in Synch
# This is useful when you have more than 10 points in the KUKA program for the robots to do in Synch
# IMPORTANT INFORMATION #########################################################################
# The POINTS NEED TO BE DEFINED AS SLIN for the program to work and for Synch to work!!!!!!!!
# Points should be named ONLY BY NUMBERS IN ASCENDING ORDER!!!!!!! E.g: 1, 2, 3, ... 800
# This program will go through each point declared
# You will need to process the DAT file as well with the other program MotionSynchDAT.py
# You need to do this for BOTH Robot program that will work in synch
# Enter the correct path file and path output with a new name (L55-56). Make sure the name of the generated file is the same as the associated dat file program.
# Run the program
###################################################################################################
import re
# Add Synch command
to_sync_slin = r"Tool\["
sub_sync_slin = r"Sync=AutoSync -> 1_2 Tool["
# Needed for Synch, change type
to_L_type = r"m/s L"
sub_L_type = r"m/s CPDAT"
# Remove extra generated by Visual Components that are not needed and can generate issue
to_remove_extra = r"PE}.*"
sub_extra = r"PE}"
# Add the required parameters for Synch for each point
to_add_params = r"SLIN X(\d{1,3})"
sub_params = r";FOLD Parameters ;%{h}\n ;Params IlfProvider=kukaroboter.basistech.inlineforms.movement.spline; Kuka.IsGlobalPoint=False; Kuka.PointName=P\1; Kuka.BlendingEnabled=True; Kuka.MoveDataName=CPDAT\1; Kuka.VelocityPath=2; Kuka.VelocityFieldEnabled=True; Kuka.ColDetectFieldEnabled=True; Kuka.CurrentCDSetIndex=0; Kuka.MovementParameterFieldEnabled=True; SyncLabel=AutoSync; CoopRobots=R1_R2; IlfCommand=SLIN\n;ENDFOLD\n SLIN X\1"
# Needed for Synch, change type
to_other_L = r", ,L"
sub_other_L = r", ,LCPDAT"
# Add the required parameters for Synch for each point
to_param_2 = r"F(\d{1,3}).TOOL_NO.*"
sub_param_2 = r'F\1.TOOL_NO), $ACC = SACC_CP(LCPDAT\1), $ORI_TYPE = SORI_TYP(LCPDAT\1), $APO = SAPO(LCPDAT\1), $JERK = SJERK(LCPDAT\1), $COLLMON_TOL_PRO[1] = USE_CM_PRO_VALUES(0), $Sync_Id[] = "AutoSync", $Sync_List =' + r"'B0011' C_Spl"
# "replacements" contains all the replacement to do defined above. They are all required for Synch to work
replacements = [
(to_sync_slin, sub_sync_slin),
(to_param_2, sub_param_2),
(to_L_type, sub_L_type),
(to_add_params, sub_params),
(to_other_L, sub_other_L),
(to_remove_extra, sub_extra),
]
# Enter text file Path
# Input: file path for file to change. Model to follow: r"C:\Users\...\File_Name.src"
# Output: file path for file to generate. Model to follow: r"C:\Users\...\File_Name.src"
input_file_path = r"C:\Users\Name.Name\Document\Input_File_Name.src"
output_file_path = r"C:\Users\Name.Name\Document\Input_File_Name.src"
# Code will create a new file with the changes wanted
with open(output_file_path, "w+") as new, open(input_file_path, "r") as original:
for line in original:
new_line = line
for pattern, replacement in replacements:
new_line = re.sub(pattern, replacement, new_line)
new.write(new_line)