# =============================================================================
# robot_arm.ini  —  LinuxCNC machine config for 5-axis serial robot arm
# =============================================================================

[EMC]
MACHINE = Robot Arm
VERSION = 1.1
DEBUG   = 0


[DISPLAY]
DISPLAY          = axis
POSITION_OFFSET  = RELATIVE
POSITION_FEEDBACK = ACTUAL
MAX_FEED_OVERRIDE = 1.5
MAX_SPINDLE_OVERRIDE = 1.0
PROGRAM_PREFIX   = ~/linuxcnc/nc_files
INTRO_GRAPHIC    = linuxcnc.gif
INTRO_TIME       = 2
CYCLE_TIME       = 0.100
DEFAULT_ANGULAR_VELOCITY    = 30.0
MAX_ANGULAR_VELOCITY        = 150.0
MIN_LINEAR_VELOCITY         = 1.0
DEFAULT_LINEAR_VELOCITY     = 100.0
MAX_LINEAR_VELOCITY         = 500.0

[HAL]
HALFILE = max-arm.hal
HALUI   = halui


[FILTER]
PROGRAM_EXTENSION = .ngc,.nc G-Code


[TASK]
TASK      = milltask
CYCLE_TIME = 0.010


[RS274NGC]
PARAMETER_FILE = robot_arm.var


[EMCMOT]
EMCMOT             = motmod
COMM_TIMEOUT       = 1.0
BASE_PERIOD        = 100000
SERVO_PERIOD       = 20000000


#[PICO]
#USB_PORT = /dev/ttyACM0
# For WiFi instead of USB, leave USB_PORT empty and set:
# WIFI_HOST = 192.168.x.x
# WIFI_PORT = 8888


[KINS]
KINEMATICS = genserkins coordinates=XYZAB
JOINTS     = 5

# DH parameters — match the arm_config.json link geometry.
# a     link lengths along x  (mm or same unit as UNITS below)
# alpha twist angle (rad) between successive z-axes
# d     offset along z
# theta constant angle offset (joint home offsets handled via HOME_OFFSET)
[GENSERKINS]
A_0     = 0.0
A_1     = 220
A_2     = 93.5
A_3     = 110
A_4     = 192.5
ALPHA_0 =  1.5707963
ALPHA_1 =  0.0
ALPHA_2 =  0.0
ALPHA_3 =  1.5707963
ALPHA_4 =  0.0
D_0     = 3.0           
D_1     = 0.0
D_2     = 0.0
D_3     = 0.0
D_4     = 0.0
# EE link length 2.5 — set as tool length offset in TOOL_TABLE, not DH.


[TRAJ]
COORDINATES        = XYZAB
ANGULAR_UNITS      = degree
LINEAR_UNITS 		= mm
DEFAULT_ANGULAR_VELOCITY     = 20.0
MAX_ANGULAR_VELOCITY         = 150.0
DEFAULT_ANGULAR_ACCELERATION = 75.0
MAX_ANGULAR_ACCELERATION     = 75.0
MAX_LINEAR_VELOCITY			= 500.0
DEFAULT_LINEAR_VELOCITY     = 100.0
NO_FORCE_HOMING              = 1



[EMCIO]
EMCIO         = io
CYCLE_TIME    = 0.100
TOOL_TABLE    = max-arm.tbl


# ─── Motor constants — derived from linuxcnc_main.py JOINTS config ────────────
# SCALE       = steps_per_rev / 360  (gear_ratio=1.0 for all joints)
# MAX_VELOCITY = max_sps / SCALE
# MAX_ACCEL    = accel_sps2 / SCALE

# ─── Joint 0: Base yaw ───────────────────────────────────────────────────────
# steps_per_rev=4240  max_sps=6000  GP8/7  (firmware limit: 509 deg/s)
[JOINT_0]
TYPE                = ANGULAR
MAX_VELOCITY        = 450.0
MAX_ACCELERATION    = 250.0
BACKLASH            = 0
SCALE               = 11.7778
MIN_LIMIT           = -170.0
MAX_LIMIT           =  170.0
FERROR              = 5.0
MIN_FERROR          = 2.0
HOME                = 0.0
HOME_OFFSET         = 0.0
HOME_SEARCH_VEL     = 0
HOME_LATCH_VEL      = 0
HOME_USE_INDEX      = NO
HOME_IGNORE_LIMITS  = NO
HOME_SEQUENCE       = 0
HOME_IS_SHARED      = 0


# ─── Joint 1: Shoulder pitch ─────────────────────────────────────────────────
# steps_per_rev=32000  max_sps=14000  accel=8000  GP4/3
[JOINT_1]
TYPE                = ANGULAR
MAX_VELOCITY        = 157.5
MAX_ACCELERATION    = 90.0
BACKLASH            = .2
SCALE               = 88.8889
MIN_LIMIT           = -170.0
MAX_LIMIT           =  170.0
FERROR              = 5.0
MIN_FERROR          = 2.0
HOME                = 0.0
HOME_OFFSET         = 0.0
HOME_SEARCH_VEL     = 0
HOME_LATCH_VEL      = 0
HOME_USE_INDEX      = NO
HOME_IGNORE_LIMITS  = NO
HOME_SEQUENCE       = 1


# ─── Joint 2: Elbow pitch ────────────────────────────────────────────────────
# steps_per_rev=57600  max_sps=20000  GP6/5  (firmware limit: 125 deg/s)
[JOINT_2]
TYPE                = ANGULAR
MAX_VELOCITY        = 120.0
MAX_ACCELERATION    = 60.0
BACKLASH            = 1
SCALE               = 160.0
MIN_LIMIT           = -170.0
MAX_LIMIT           =  170.0
FERROR              = 5.0
MIN_FERROR          = 2.0
HOME                = 0.0
HOME_OFFSET         = 0.0
HOME_SEARCH_VEL     = 0
HOME_LATCH_VEL      = 0
HOME_USE_INDEX      = NO
HOME_IGNORE_LIMITS  = NO
HOME_SEQUENCE       = 2


# ─── Joint 3: Wrist roll ─────────────────────────────────────────────────────
# steps_per_rev=7600  max_sps=4000  GP26/22  (firmware limit: 189 deg/s)
[JOINT_3]
TYPE                = ANGULAR
MAX_VELOCITY        = 180.0
MAX_ACCELERATION    = 90.0
BACKLASH            = 0
SCALE               = 21.1111
MIN_LIMIT           = -170.0
MAX_LIMIT           =  170.0
FERROR              = 5.0
MIN_FERROR          = 2.0
HOME                = 0.0
HOME_OFFSET         = 0.0
HOME_SEARCH_VEL     = 0
HOME_LATCH_VEL      = 0
HOME_USE_INDEX      = NO
HOME_IGNORE_LIMITS  = NO
HOME_SEQUENCE       = 3


# ─── Joint 4: Wrist pitch ────────────────────────────────────────────────────
# steps_per_rev=6000  max_sps=4000  GP28/27  (firmware limit: 240 deg/s)
[JOINT_4]
TYPE                = ANGULAR
MAX_VELOCITY        = 230.0
MAX_ACCELERATION    = 115.0
BACKLASH            = 0
SCALE               = 16.6667
MIN_LIMIT           = -170.0
MAX_LIMIT           =  170.0
FERROR              = 5.0
MIN_FERROR          = 2.0
HOME                = 0.0
HOME_OFFSET         = 0.0
HOME_SEARCH_VEL     = 0
HOME_LATCH_VEL      = 0
HOME_USE_INDEX      = NO
HOME_IGNORE_LIMITS  = NO
HOME_SEQUENCE       = 4
