|
| 1 | +from ABBRobotEGM import EGM |
| 2 | +import numpy as np |
| 3 | +import time |
| 4 | + |
| 5 | +# Ensure the robot is configured correctly by setting up "EGMPathCorr" with "Path" level in the Motion configuration. |
| 6 | +# This can be done in the robot's controller under: Motion configuration -> External Motion Interface Data. |
| 7 | +# MODULE MainModule |
| 8 | +# VAR egmident egmID1; |
| 9 | +# CONST robtarget Target_10:=[[0.771953305,2.548198209,204.864360938],[-0.000000176,-0.000000006,1,-0.000000002],[-1,0,-1,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]]; |
| 10 | +# TASK PERS wobjdata Workobject_1:=[FALSE,TRUE,"",[[525,-125,308],[1,0,0,0]],[[0,0,0],[1,0,0,0]]]; |
| 11 | +# PERS tooldata Pen_TCP:=[TRUE,[[110,0,140],[0.707106781,0,0.707106781,0]],[1,[10.7435139,0,140],[1,0,0,0],0,0,0]]; |
| 12 | + |
| 13 | +# PROC main() |
| 14 | +# EGMReset egmID1; |
| 15 | +# EGMGetId egmID1; |
| 16 | +# EGMSetupUC ROB_1,egmId1,"EGMPathCorr","UCdevice"\PathCorr\APTR; |
| 17 | +# EGMActMove EGMid1,Pen_TCP.tframe\SampleRate:=48; |
| 18 | +# MoveL Target_10,vmax,fine,Pen_TCP\WObj:=Workobject_1; |
| 19 | +# EGMMoveL egmID1,Offs(Target_10,200,0,0),v10,fine,Pen_TCP\WObj:=Workobject_1; |
| 20 | +# MoveL Offs(Target_10,0,0,200),vmax,fine,Pen_TCP\WObj:=Workobject_1; |
| 21 | +# EGMStop egmID1,EGM_STOP_HOLD; |
| 22 | +# ENDPROC |
| 23 | +# ENDMODULE |
| 24 | + |
| 25 | + |
| 26 | +def main() -> None: |
| 27 | + """ |
| 28 | + Example showing how to apply path corrections during robot movement. |
| 29 | + This will apply a sinusoidal correction in the Y direction while the robot |
| 30 | + moves along a straight line in the X direction (using EGMMoveL in RAPID). |
| 31 | +
|
| 32 | + The sinusoidal pattern: |
| 33 | + - Amplitude: 100mm |
| 34 | + - Frequency: 2.0 Hz |
| 35 | +
|
| 36 | + This creates a wavy pattern perpendicular to the robot's movement direction. Run the python script before |
| 37 | + running the RAPID program on the robot. |
| 38 | + """ |
| 39 | + with EGM() as egm: |
| 40 | + print("Waiting for initial message from robot...") |
| 41 | + # Wait for first message from robot to establish connection |
| 42 | + while True: |
| 43 | + success, _ = egm.receive_from_robot(timeout=1.0) |
| 44 | + if success: |
| 45 | + print("Connected to robot!") |
| 46 | + break |
| 47 | + # Parameters for sinusoidal correction |
| 48 | + amplitude = 100.0 # mm |
| 49 | + frequency = 2.0 # Hz |
| 50 | + t_start = time.time() |
| 51 | + print("Sending Y-axis path corrections...") |
| 52 | + |
| 53 | + while True: |
| 54 | + # Always receive from robot first to maintain connection |
| 55 | + success, _ = egm.receive_from_robot(timeout=0.1) |
| 56 | + if not success: |
| 57 | + print("Lost connection to robot") |
| 58 | + break |
| 59 | + |
| 60 | + # Calculate Y correction using sine wave |
| 61 | + t = time.time() - t_start |
| 62 | + y_correction = amplitude * np.sin(2 * np.pi * frequency * t) |
| 63 | + |
| 64 | + correction = np.array([0.0, y_correction, 0.0]) |
| 65 | + egm.send_to_robot_path_corr(correction, age=1) |
| 66 | + |
| 67 | + # Match robot's sensor refresh rate of 48ms |
| 68 | + time.sleep(0.048) |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + main() |
0 commit comments