This repository contains servicing_arm_sim.py, an educational simulation of a
three-degree-of-freedom planar servicing arm that performs a multi-phase capture
sequence. The simulator highlights the modeling, design, and analysis layers of a
cyber-physical system (CPS) workflow and mirrors many of the calculations that a
real on-orbit robotic arm would execute.
python servicing_arm_sim.py [--steps N] [--dt DT] [--plots {0,1}] [--use_ros {0,1}]--steps(default4000) controls the number of discrete integration steps.--dt(default0.005seconds) sets the simulation time step.--plotstoggles generation of tracking-error and torque plots inout/plots/.--use_rosenables the lightweight ROS bridge inros_shim.pyso external tools can publish target overrides or subscribe to state streams.
During runtime you can send JSON messages to the /external/commands topic via
ROS (or the shim) to update the target position, which lets you interactively
study off-nominal scenarios. Every run produces a JSON log at out/latest_run.json
that captures the state, control commands, and errors at each step.
- Target model – The target starts near
(1.0, 0.2)meters and drifts slowly. Gaussian noise (0.5 cmσ) imitates pose sensing uncertainty. - Finite-state machine (FSM) – The mission transitions through SEARCH, APPROACH, ALIGN, CAPTURE, and RETREAT phases with distance and time-based guards. Each phase picks a different workspace goal relative to the noisy target estimate so you can demonstrate high-level autonomy.
- Planning – A minimum-jerk interpolator produces smooth Cartesian targets for the end effector (EE) within each phase window, mimicking the way flight software enforces gentle, fuel-efficient motion profiles.
- Inverse kinematics (IK) – The damped-least-squares solver converts the EE reference into joint-velocity commands so the 3-DOF planar arm avoids singularities, just as onboard guidance software regularizes IK for manipulators with limited reach.
- Joint control – A joint-space PID controller with torque saturation sends commands through a second-order joint-dynamics integrator. The gains approximate how each joint drive on an actual arm rejects disturbances and respects motor limits.
- Analysis outputs – After the run, plots quantify tracking error and torque history, while the JSON log provides per-step telemetry for offline studies.
Although simplified to a plane, each block mirrors a real subsystem:
- Forward kinematics (
fk) and Jacobian (jacobian) compute the EE pose and sensitivity to joint motion. Real arms rely on the same trigonometric chains for pose estimation and momentum management. - IK and minimum-jerk planning replicate how flight software converts supervisory goals into smooth joint references that avoid exciting structural modes or saturating reaction wheels.
- PID regulation with torque limits models the low-level joint controllers
that keep link motion stable despite damping, flexible harnesses, or capture
contact forces. The
K_TAUandBASE_DAMPINGparameters encapsulate actuator stiffness and passive dissipation present in hardware. - Finite-state autonomy reflects mission timelines: SEARCH emulates coarse pointing, APPROACH mirrors guided motion near the client vehicle, ALIGN and CAPTURE correspond to fine alignment and latch closure, and RETREAT represents back-away maneuvers.
- ROS I/O hook stands in for spacecraft avionics or ground commanding, where operators can update target poses or monitor telemetry in real time.
By tuning the same parameters (link lengths, torque limits, damping, planner horizons) that drive real mechanisms, you can explain how sensing uncertainty, controller gains, and state-machine logic jointly determine whether a servicing arm captures a drifting satellite.