# arm_config.py: your arm's settings, read by arm_body.py at power-on. 1026.
#
# UNMEASURED. Nobody has built this arm yet: these numbers are a cautious starting point, not a measured
# arm. Keep the ranges narrow at first. Move one joint at a time on growbot.dev/tester/arm.html in small
# steps, note where it binds or hits the robot, then set min/max a few degrees inside that.
#
# socket   the number printed next to the servo socket on the Waveshare Pico Servo Driver (it is the GPIO).
#          0 and 1 are the wheels or legs, and 8 and 9 are probed for a servo chip at boot: arm_body.py
#          refuses those (and 16, 17, 24, 25, which share their outputs). Good choices: 2 to 7, 10 to 15.
# min/max  the furthest this joint may ever go, in degrees (0 to 180). Every command is clamped to it.
# neutral  the middle of the joint: arm straight up, gripper half open. Named poses are offsets from it.
# rest     where the joint parks at power-on and for the "rest" pose. Leave the arm here before switching
#          off: a servo cannot report where it is, so at power-on each joint jumps to rest at full speed.
#          The same goes for any move after the arm let go (STOP, the idle or page timeout below): a joint
#          that sagged first snaps back to where it was at full speed, one joint at a time, then slews.
# dps      (optional) this joint's own top speed in degrees per second, instead of SLEW_DPS.
# hold_s   (optional) this joint alone lets go after this many seconds still, sooner than IDLE_S (1 to 3600).
#          A grip closed on something is a stalled servo: it draws its stall current and heats up the whole
#          time it squeezes. 15 s means it drops what it holds 15 s after your last move. Raise it if your
#          grip needs to hold longer and its servo stays cool; leave it out to hold until IDLE_S.
JOINTS = [
    {"name": "base",     "socket": 2, "min": 45, "max": 135, "neutral": 90, "rest": 90},
    {"name": "shoulder", "socket": 3, "min": 45, "max": 135, "neutral": 90, "rest": 90},
    {"name": "elbow",    "socket": 4, "min": 45, "max": 135, "neutral": 90, "rest": 90},
    {"name": "grip",     "socket": 5, "min": 45, "max": 135, "neutral": 90, "rest": 90, "hold_s": 15},
]

SLEW_DPS = 60   # top speed of every joint, degrees per second (1 to 360)
IDLE_S = 120    # holding still this long with no new command, the arm goes limp (1 to 3600)
LEASE_S = 15    # no word from the arm page this long (closed, asleep, out of signal), the arm goes limp (5 to 600)

# Optional: your own named poses, replacing the built-in ones (rest always means each joint's rest above).
# Each pose is a list of keyframes: ([offset from neutral per joint, None = leave it], ms to hold after).
# POSES = {
#     "up":    [([0, 0, 0, None], 0)],
#     "point": [([0, 40, -30, None], 0)],
#     "wave":  [([0, 0, 0, None], 150), ([None, None, 30, None], 0), ([None, None, -30, None], 0),
#               ([None, None, 30, None], 0), ([None, None, 0, None], 0)],
#     "grab-open":  [([None, None, None, 40], 0)],
#     "grab-close": [([None, None, None, -40], 0)],
# }
