"""
Parametric servo HOLDER (build123d) that wraps the servo BODY on both sides — a U-cradle
gripping the ±Y faces with a back wall, open at +Z/-Z so the output horn/idler stay clear
for the yoke. Servo frame (servo mesh at identity); body bbox X[-22.7,22.7] Y[-12.4,12.4]
Z[-19.4,20.2].
"""
from build123d import Box, Pos, export_stl

# servo body extents
BX, BY, BZ = 22.7, 12.4, 19.4
WALL = 4.0
GAP = 1.0
WALL_Y = BY + GAP + WALL / 2
BACK_X = -(BX + GAP + WALL / 2)        # back wall at the -X end (away from the output side)
WRAP_Z = 16.0                          # how much of the body height the side walls cover (from bottom)


def make_holder():
    side_h = WRAP_Z * 2
    side_zc = 0.0
    # two side walls gripping +Y / -Y faces of the body
    h = (Pos(0, WALL_Y, side_zc) * Box(2 * BX + WALL, WALL, side_h)
         + Pos(0, -WALL_Y, side_zc) * Box(2 * BX + WALL, WALL, side_h)
         + Pos(BACK_X, 0, side_zc) * Box(WALL, 2 * WALL_Y + WALL, side_h)   # back wall
         + Pos(BACK_X / 2, 0, -BZ - WALL / 2) * Box(2 * BX + WALL - 6, 2 * WALL_Y, WALL))  # floor under body
    return h


if __name__ == "__main__":
    export_stl(make_holder(), "holder_param.stl", tolerance=0.1, ascii_format=False)
    print("holder ok")
