|
| 1 | +import compas_rrc as rrc |
| 2 | +from compas.geometry import Frame |
| 3 | +from compas.geometry import Point |
| 4 | +from compas.geometry import Vector |
| 5 | + |
| 6 | +if __name__ == '__main__': |
| 7 | + |
| 8 | + # Create Ros Client |
| 9 | + ros = rrc.RosClient() |
| 10 | + ros.run() |
| 11 | + |
| 12 | + # Create ABB Client |
| 13 | + abb = rrc.AbbClient(ros, '/rob1') |
| 14 | + print('Connected.') |
| 15 | + |
| 16 | + # Define robot joints |
| 17 | + robot_joints_start_position = [0.0, -20.0, 40.0, 0.0, -20.0, 0.0] |
| 18 | + robot_joints_end_position = [0.0, -30.0, 50.0, 0.0, -20.0, 0.0] |
| 19 | + |
| 20 | + # Define print frames x |
| 21 | + frame_print_start_X = Frame(Point(750.000, 250.000, -0.000), Vector(-1.000, 0.000, 0.000), Vector(0.000, 1.000, 0.000)) |
| 22 | + frame_print_end_X = Frame(Point(250.000, 250.000, -0.000), Vector(-1.000, 0.000, 0.000), Vector(0.000, 1.000, 0.000)) |
| 23 | + |
| 24 | + # Define print frames x |
| 25 | + frame_print_start_Y = Frame(Point(750.000, 350.000, -0.000), Vector(-1.000, 0.000, 0.000), Vector(0.000, 1.000, 0.000)) |
| 26 | + frame_print_end_Y = Frame(Point(250.000, 350.000, -0.000), Vector(-1.000, 0.000, 0.000), Vector(0.000, 1.000, 0.000)) |
| 27 | + |
| 28 | + # Define print frames x |
| 29 | + frame_print_start_Z = Frame(Point(750.000, 450.000, -0.000), Vector(-1.000, 0.000, 0.000), Vector(0.000, 1.000, 0.000)) |
| 30 | + frame_print_end_Z = Frame(Point(250.000, 450.000, -0.000), Vector(-1.000, 0.000, 0.000), Vector(0.000, 1.000, 0.000)) |
| 31 | + |
| 32 | + # Define external axis |
| 33 | + external_axis_dummy = [] |
| 34 | + |
| 35 | + # Select tool and print output |
| 36 | + print_tool = 't_RRC_Tool_Z' |
| 37 | + print_signal = 'do_Z' |
| 38 | + |
| 39 | + # Select print path |
| 40 | + frame_print_start = frame_print_start_Z |
| 41 | + frame_print_end = frame_print_end_Z |
| 42 | + |
| 43 | + # Define speed |
| 44 | + speed = 800 |
| 45 | + speed_print = 150 |
| 46 | + |
| 47 | + # Set Acceleration |
| 48 | + acc = 100 # Unit [%] |
| 49 | + ramp = 100 # Unit [%] |
| 50 | + abb.send(rrc.SetAcceleration(acc, ramp)) |
| 51 | + |
| 52 | + # Set Max Speed |
| 53 | + override = 100 # Unit [%] |
| 54 | + max_tcp = 2500 # Unit [mm/s] |
| 55 | + abb.send(rrc.SetMaxSpeed(override, max_tcp)) |
| 56 | + |
| 57 | + # Reset signals |
| 58 | + abb.send(rrc.SetDigital('do_X',0)) |
| 59 | + abb.send(rrc.SetDigital('do_Y',0)) |
| 60 | + abb.send(rrc.SetDigital('do_Z',0)) |
| 61 | + |
| 62 | + # Set tool |
| 63 | + abb.send(rrc.SetTool(print_tool)) |
| 64 | + |
| 65 | + # Set work object |
| 66 | + abb.send(rrc.SetWorkObject('ob_RRC_Workplace')) |
| 67 | + |
| 68 | + # User message -> basic settings send to robot |
| 69 | + print('Tool, Wobj, Acc and MaxSpeed sent to robot') |
| 70 | + |
| 71 | + # Stop task user must press play button on the FlexPendant (RobotStudio) before robot starts to move |
| 72 | + abb.send(rrc.PrintText('Press Play to move.')) |
| 73 | + abb.send(rrc.Stop()) |
| 74 | + |
| 75 | + # Move robot to start position |
| 76 | + done = abb.send_and_wait(rrc.MoveToJoints(robot_joints_start_position, external_axis_dummy, speed, rrc.Zone.FINE)) |
| 77 | + |
| 78 | + # User message and input |
| 79 | + input('Robot start position reached, press any key to start the print.') |
| 80 | + |
| 81 | + # Move to print start |
| 82 | + abb.send(rrc.MoveToFrame(frame_print_start, speed, rrc.Zone.FINE)) |
| 83 | + |
| 84 | + # Start watch |
| 85 | + done = abb.send_and_wait(rrc.StartWatch()) |
| 86 | + |
| 87 | + # Start print |
| 88 | + abb.send(rrc.SetDigital(print_signal, 1)) |
| 89 | + |
| 90 | + # Print path |
| 91 | + abb.send(rrc.MoveToFrame(frame_print_end, speed_print, rrc.Zone.FINE, rrc.Motion.LINEAR)) |
| 92 | + |
| 93 | + # End print |
| 94 | + abb.send(rrc.SetDigital(print_signal, 0)) |
| 95 | + |
| 96 | + # Stop watch |
| 97 | + done = abb.send_and_wait(rrc.StopWatch()) |
| 98 | + |
| 99 | + # Read watch |
| 100 | + future = abb.send(rrc.ReadWatch()) |
| 101 | + |
| 102 | + # Move robot to end position |
| 103 | + abb.send(rrc.MoveToJoints(robot_joints_end_position, external_axis_dummy, speed, rrc.Zone.FINE)) |
| 104 | + |
| 105 | + # Read and print printing time |
| 106 | + watch_time = future.result(timeout=3.0) |
| 107 | + print('Print Time [s] = ', watch_time) |
| 108 | + |
| 109 | + # Print Text |
| 110 | + done = abb.send_and_wait(rrc.PrintText('Compas_RRC Example finish.')) |
| 111 | + |
| 112 | + # End of Code |
| 113 | + print('Finished') |
| 114 | + |
| 115 | + # Close client |
| 116 | + ros.close() |
| 117 | + ros.terminate() |
0 commit comments