|
| 1 | +"""Showcase script demonstrating all motion types. |
| 2 | +
|
| 3 | +Exercises move_j, move_l, move_c, move_p, move_s, blended zig-zag, |
| 4 | +tool actions, TCP offset, and precision TRF rotations. |
| 5 | +
|
| 6 | +Run: |
| 7 | + python examples/demo_showcase.py |
| 8 | +""" |
| 9 | + |
| 10 | +import math |
| 11 | + |
| 12 | +from parol6 import Robot |
| 13 | + |
| 14 | +HOST = "127.0.0.1" |
| 15 | +PORT = 5001 |
| 16 | + |
| 17 | +with Robot(host=HOST, port=PORT, normalize_logs=True) as robot: |
| 18 | + rbt = robot.create_sync_client(timeout=2.0) |
| 19 | + rbt.wait_ready(timeout=5.0) |
| 20 | + rbt.simulator(True) |
| 21 | + |
| 22 | + # Select tool and home |
| 23 | + rbt.select_tool("SSG-48") |
| 24 | + rbt.home(wait=True) |
| 25 | + |
| 26 | + # move_j vs move_l (joint-space then linear-cartesian to nearby pose) |
| 27 | + rbt.move_j(pose=[100, 240, 334, 90, 0, 90], speed=0.5, wait=True) |
| 28 | + rbt.move_l([-50, 240, 334, 90, 0, 90], speed=0.5, wait=True) |
| 29 | + |
| 30 | + # ── Curved motion: three vertical circles + sine-wave spline ────────── |
| 31 | + RADIUS = 30 |
| 32 | + SPEED = 0.4 |
| 33 | + CIRCLE_Y = 340 |
| 34 | + ORIENTATION = [90, 0, 90] |
| 35 | + CENTERS = [(0, CIRCLE_Y, 280), (0, CIRCLE_Y, 210), (0, CIRCLE_Y, 140)] |
| 36 | + |
| 37 | + def circle_pt(cx, cz, angle_deg): |
| 38 | + """Circle in the XZ plane (vertical) at fixed Y.""" |
| 39 | + a = math.radians(angle_deg) |
| 40 | + return [ |
| 41 | + cx + RADIUS * math.cos(a), |
| 42 | + CIRCLE_Y, |
| 43 | + cz + RADIUS * math.sin(a), |
| 44 | + ] + ORIENTATION |
| 45 | + |
| 46 | + # Circle 1: full circle with a single move_c (start = end) |
| 47 | + cx, _, cz = CENTERS[0] |
| 48 | + rbt.move_j(pose=circle_pt(cx, cz, 0), speed=0.5, wait=True) |
| 49 | + rbt.move_c( |
| 50 | + via=circle_pt(cx, cz, 180), end=circle_pt(cx, cz, 0), speed=SPEED, wait=True |
| 51 | + ) |
| 52 | + |
| 53 | + # Circle 2: two half-circle move_c arcs |
| 54 | + cx, _, cz = CENTERS[1] |
| 55 | + rbt.move_l(circle_pt(cx, cz, 0), speed=SPEED, wait=True) |
| 56 | + rbt.move_c( |
| 57 | + via=circle_pt(cx, cz, 90), end=circle_pt(cx, cz, 180), speed=SPEED, wait=True |
| 58 | + ) |
| 59 | + rbt.move_c( |
| 60 | + via=circle_pt(cx, cz, 270), end=circle_pt(cx, cz, 0), speed=SPEED, wait=True |
| 61 | + ) |
| 62 | + |
| 63 | + # Circle 3: computed waypoints with move_p |
| 64 | + cx, _, cz = CENTERS[2] |
| 65 | + waypoints = [circle_pt(cx, cz, i * 30) for i in range(12)] |
| 66 | + waypoints.append(waypoints[0]) |
| 67 | + rbt.move_l(waypoints[0], speed=SPEED, wait=True) |
| 68 | + rbt.move_p(waypoints, speed=SPEED, wait=True) |
| 69 | + |
| 70 | + # Sine wave through all three circle centers (bottom to top) using move_s |
| 71 | + SINE_POINTS = 36 |
| 72 | + z_min, z_max = CENTERS[2][2], CENTERS[0][2] |
| 73 | + spline = [] |
| 74 | + for i in range(SINE_POINTS + 1): |
| 75 | + t = i / SINE_POINTS |
| 76 | + z = z_min + t * (z_max - z_min) |
| 77 | + x = RADIUS * math.cos(t * 3 * 2 * math.pi) |
| 78 | + spline.append([x, CIRCLE_Y, z] + ORIENTATION) |
| 79 | + rbt.move_s(spline, speed=SPEED, wait=True) |
| 80 | + |
| 81 | + # ── Zig-zag scan ───────────────────────────────────────────────────── |
| 82 | + ZZ_ORI = [-180, -90, -180] |
| 83 | + ROWS = 6 |
| 84 | + Y_MIN, Y_MAX = 0, 160 |
| 85 | + Z_MIN, Z_MAX = 200, 300 |
| 86 | + X = 280 |
| 87 | + BLEND = 15 |
| 88 | + |
| 89 | + rbt.move_j(pose=[X, 0, 334] + ZZ_ORI, speed=0.5, wait=True) |
| 90 | + rbt.move_l([X, Y_MIN, Z_MAX + 30] + ZZ_ORI, speed=0.5, wait=True) |
| 91 | + z_step = (Z_MAX - Z_MIN) / (ROWS - 1) |
| 92 | + for row in range(ROWS): |
| 93 | + z = Z_MAX - row * z_step |
| 94 | + is_last = row == ROWS - 1 |
| 95 | + y_start, y_end = (Y_MIN, Y_MAX) if row % 2 == 0 else (Y_MAX, Y_MIN) |
| 96 | + rbt.move_l([X, y_start, z] + ZZ_ORI, speed=0.5, r=BLEND, wait=False) |
| 97 | + rbt.move_l( |
| 98 | + [X, y_end, z] + ZZ_ORI, speed=0.5, r=0 if is_last else BLEND, wait=False |
| 99 | + ) |
| 100 | + rbt.wait_motion() |
| 101 | + |
| 102 | + # ── Precision demo: pencil pick-up and TCP-offset rotations ────────── |
| 103 | + # Home first — orientation flip from zigzag end requires fresh joint config. |
| 104 | + rbt.home(wait=True) |
| 105 | + PRECISION_POSE = [0, -250, 350, -90, 0, -90] |
| 106 | + rbt.move_j(pose=PRECISION_POSE, speed=0.5, wait=True) |
| 107 | + |
| 108 | + # Test gripper: two quick close/open cycles |
| 109 | + rbt.tool.close(speed=1.0) |
| 110 | + rbt.tool.open(speed=1.0) |
| 111 | + rbt.tool.close(speed=1.0) |
| 112 | + rbt.tool.open(speed=1.0) |
| 113 | + |
| 114 | + # Approach pencil: move_j to 100mm above, descend linearly, grab, retract |
| 115 | + PENCIL_ABOVE = [-90, -81.6, 161.8, 0, -69.4, 180] |
| 116 | + rbt.move_j(angles=PENCIL_ABOVE, speed=0.3, wait=True) |
| 117 | + rbt.move_l([0, 0, -100, 0, 0, 0], rel=True, speed=0.2, wait=True) |
| 118 | + rbt.tool.close(wait=True) |
| 119 | + rbt.move_l([0, 0, 100, 0, 0, 0], rel=True, speed=0.2, wait=True) |
| 120 | + rbt.move_j(pose=PRECISION_POSE, speed=0.3, wait=True) |
| 121 | + |
| 122 | + # Offset TCP to pencil tip (~100mm exposed below gripper) |
| 123 | + rbt.set_tcp_offset(-100, 0, 0) |
| 124 | + |
| 125 | + # Pencil tip traces straight lines (linear precision demo) |
| 126 | + # Forward/back (tool Z = world -Y at this pose) |
| 127 | + rbt.move_l([0, 0, 100, 0, 0, 0], speed=0.3, frame="TRF", rel=True, wait=True) |
| 128 | + rbt.move_l([0, 0, -200, 0, 0, 0], speed=0.3, frame="TRF", rel=True, wait=True) |
| 129 | + rbt.move_l([0, 0, 100, 0, 0, 0], speed=0.3, frame="TRF", rel=True, wait=True) |
| 130 | + # Side to side (tool Y = world -X at this pose) |
| 131 | + rbt.move_l([0, 60, 0, 0, 0, 0], speed=0.3, frame="TRF", rel=True, wait=True) |
| 132 | + rbt.move_l([0, -120, 0, 0, 0, 0], speed=0.3, frame="TRF", rel=True, wait=True) |
| 133 | + rbt.move_l([0, 60, 0, 0, 0, 0], speed=0.3, frame="TRF", rel=True, wait=True) |
| 134 | + |
| 135 | + # Precision TRF rotations — pencil tip stays stationary while wrist rotates |
| 136 | + SWEEP = 20 |
| 137 | + for axis in range(3): |
| 138 | + delta = [0, 0, 0, 0, 0, 0] |
| 139 | + delta[3 + axis] = -SWEEP |
| 140 | + rbt.move_l(delta, speed=0.5, frame="TRF", rel=True, wait=True) |
| 141 | + delta[3 + axis] = SWEEP |
| 142 | + rbt.move_l(delta, speed=0.5, frame="TRF", rel=True, wait=True) |
| 143 | + rbt.move_l(delta, speed=0.5, frame="TRF", rel=True, wait=True) |
| 144 | + delta[3 + axis] = -SWEEP |
| 145 | + rbt.move_l(delta, speed=0.5, frame="TRF", rel=True, wait=True) |
| 146 | + |
| 147 | + # Place pencil back: descend linearly, release, retract |
| 148 | + rbt.set_tcp_offset(0, 0, 0) |
| 149 | + rbt.move_j(angles=PENCIL_ABOVE, speed=0.3, wait=True) |
| 150 | + rbt.move_l([0, 0, -100, 0, 0, 0], rel=True, speed=0.2, wait=True) |
| 151 | + rbt.tool.open(wait=True) |
| 152 | + rbt.move_l([0, 0, 100, 0, 0, 0], rel=True, speed=0.2, wait=True) |
| 153 | + |
| 154 | + # Return and finish |
| 155 | + rbt.move_j(pose=PRECISION_POSE, speed=0.3, wait=True) |
| 156 | + rbt.home(wait=True) |
| 157 | + print("Done!") |
0 commit comments