A Rust simulation and visualization project for a 3-DOF, two-link manipulator with a fixed base in 3D space. The arm executes a simple pick-and-place loop using an analytic inverse kinematics solver and a linear end-effector trajectory.
- Joint 0 (base): revolute yaw about the +Z axis at the origin
(0,0,0). - Joints 1–2 (links): revolute pitch angles defining motion in the arm’s vertical plane (relative to the X–Y plane).
- IK: reduces the 3D target to a 2D planar problem in
(r,z), solves with the law of cosines, and supports elbow-up / elbow-down branches. - Visualization: rendered with raylib, including an overlay panel and a simple suction-tool “ball” pick-and-place animation.
- User input: START/GOAL are entered in the UI overlay (no console prompts). Press PLAY to start; press PAUSE to edit inputs.
Build system: Cargo • Rendering: raylib • Language: Rust (Edition 2021) • IK: Closed-form
- About this repository
- Repository structure
- Robotics: kinematics, dynamics, and inverse kinematics
- Building the project
- Operating system guides (Windows / macOS / Linux)
- Running the simulator
- Repository file guide (full explanation)
- Simulation video
- Troubleshooting
This project simulates a 3-DOF, two-link manipulator mounted on a fixed base at the origin:
- The base joint rotates around the Z axis (yaw).
- The two link joints rotate as pitch angles (relative to the X–Y plane) in the arm’s vertical plane.
- The end-effector (EE) tracks a sequence of target points with analytic inverse kinematics.
- A small “ball” is used to visualize a pick-and-place loop:
- HOME → START
- PICK at START (attach ball)
- START → GOAL
- PLACE at GOAL (detach ball)
- GOAL → HOME
- wait briefly and repeat
User inputs (via overlay panel):
- START position
(x y z)and GOAL position(x y z) - Constraint enforced by IK: z must be ≥ 0
- Reachability enforced by IK:
|p|must be within the arm’s reachable shell.
Controls / interaction
- Mouse wheel: zoom camera
- F11: toggle fullscreen
- Overlay includes a PAUSE/PLAY button, editable START/GOAL fields, and reachability feedback
Manipulator3D_Rust/
Cargo.toml
Cargo.lock
README.md
.cargo/
config.toml
resources/
fonts/
Inter-Regular.ttf
src/
main.rs
robot/
mod.rs
robot_arm.rs
sim/
mod.rs
trajectory.rs
ui/
mod.rs
overlay.rs
render/
mod.rs
draw_utils.rsThis repository includes a .cargo/config.toml tuned for slow/unstable networks and environments where Cargo downloads time out.
If your network is stable, you can keep it as-is (it does not change runtime behavior), or adjust the values.
Typical improvements it provides:
- avoids flaky HTTP/2 multiplexing
- increases timeouts/retries
- relaxes low-speed limits for very slow links
- uses the
gitcrates.io index protocol to avoid sparse-index issues
- World frame origin is at the center of the base revolute joint: (0,0,0).
- Joint angles:
q0_yaw: rotation about +Z (sets the arm’s radial direction in the X–Y plane)q1_pitch: shoulder elevation angle relative to the X–Y planeq2_pitch: elbow pitch angle (relative bend in the same vertical plane)
We use the radial unit direction in the X–Y plane:
Let link lengths be
- Elbow position:
- End-effector position:
This manipulator is effectively a 2-link arm in a vertical plane, rotated by yaw. Therefore the reachable radius must satisfy:
The implementation enforces:
target.z >= 0|p|within[MinReach(), MaxReach()]
Given target
Step A — base yaw
Step B — reduce to planar IK in
Now solve a 2-link planar problem for the triangle formed by
Step C — elbow angle from law of cosines
Clamp to
This sign is the elbow-up / elbow-down branch selection.
Step D — shoulder angle
Define:
Then:
- Rust toolchain (Rustup recommended)
- A native C/C++ toolchain (raylib is built natively via
raylib-sys)- Windows: Visual Studio Build Tools / MSVC
- macOS: Xcode Command Line Tools
- Linux: build-essential (GCC/Clang + make)
From the repository root (where Cargo.toml is):
cargo clean
cargo build --releaseThis project targets the MSVC Rust toolchain on Windows. The most reliable approach is to build from the Developer PowerShell for VS 2022 (or the x64 Native Tools Command Prompt), because it pre-configures the MSVC compiler + linker environment.
- Install prerequisites:
- Rust (Rustup) using the
x86_64-pc-windows-msvctoolchain - Visual Studio 2022 Build Tools with the workload: Desktop development with C++
- Windows 10/11 SDK (installed with the Build Tools when selected)
-
Open: Developer PowerShell for VS 2022.
-
Build and run:
cd path\to\Manipulator3D_Rust
cargo fetch
cargo run --releaseSome Windows environments (especially when MSYS2 / Git Bash is installed) can accidentally pick up a non-MSVC link.exe.
If you see errors referencing paths like C:\msys64\usr\bin\link.exe, you can explicitly configure the MSVC libraries and linker
inside PowerShell before building.
Run the following PowerShell commands (edit the version/path to match your machine):
# 1) MSVC version you have (taken from your MSVC folder name)
# Change this to match your system.
# How to find it:
# Open: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\
# Pick the newest folder name (example: 14.44.35207)
$msvcVer = "14.44.35207"
# 2) MSVC lib directory (x64)
$msvcLib = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\$msvcVer\lib\x64"
# 3) Windows SDK (Windows Kits) library directories
$sdkRoot = "C:\Program Files (x86)\Windows Kits\10\Lib"
$sdkVer = (Get-ChildItem $sdkRoot -Directory | Sort-Object Name -Descending | Select-Object -First 1).Name
$umLib = Join-Path $sdkRoot "$sdkVer\um\x64"
$ucrtLib = Join-Path $sdkRoot "$sdkVer\ucrt\x64"
# 4) Sanity checks (should print True / True)
Test-Path (Join-Path $umLib "kernel32.lib")
Test-Path (Join-Path $msvcLib "msvcrt.lib")
# 5) Tell the linker where to find .lib files
$env:LIB = "$msvcLib;$ucrtLib;$umLib;$env:LIB"
# 6) Force Cargo to use MSVC's linker (NOT MSYS2/Git's link.exe)
$env:CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64\link.exe"
# 7) Build and run from the repository root (where Cargo.toml is)
cd "$env:USERPROFILE\Desktop\Manipulator3D_Rust"
cargo clean
cargo fetch
cargo run --release
- Install Rust (or verify it is installed):
rustc --version
cargo --version- Ensure build tools are available (Xcode Command Line Tools):
xcode-select --install- Run:
cd path/to/Manipulator3D_Rust
cargo fetch
cargo run --release- Install Rust (or verify it is installed):
rustc --version
cargo --version- Install native build dependencies:
sudo apt-get update
sudo apt-get install -y build-essential pkg-config- Run:
cd path/to/Manipulator3D_Rust
cargo fetch
cargo run --releaseFrom the repository root:
cargo fetch
cargo run --release- Mouse wheel: zoom camera
- F11: toggle fullscreen
- Overlay:
- edit START and GOAL when paused
- press PLAY to start the simulation
- press PAUSE to stop and edit inputs again
This section explains every important file in the repository and its role.
- Declares the package and dependencies.
- Uses
raylibcrate (which pullsraylib-sysfor native compilation).
- Cargo networking configuration tuned for slow/unstable connections.
- Useful when downloads repeatedly timeout or reset.
Runtime loop + simulation state machine:
- reads START/GOAL from overlay input fields
- validates reachability using IK for:
- fixed HOME EE point
- START
- GOAL
- runs a pick-and-place finite-state machine:
- HOME → START → PICK → GOAL → PLACE → HOME → WAIT → LOOP
- generates a linear Cartesian trajectory between targets
- runs IK each frame to get joint angles for the current EE target
- calls FK for rendering joint/link positions
- renders:
- robot geometry, axes, ball, suction tool
- overlay panel (inputs, parameters, status, play/pause)
Implements analytic FK and IK:
- IK:
- rejects invalid targets (z < 0)
- checks radius bounds (min/max reach)
- computes yaw from
atan2(y,x) - reduces to planar IK in
(r,z) - solves elbow angle via law of cosines
- solves shoulder angle via triangle decomposition
- FK:
- constructs radial axis from yaw
- builds elbow and EE positions from link lengths and pitch angles
Minimal trajectory generator:
- linear interpolation with normalized time:
$\alpha = \mathrm{clamp}(t/T, 0, 1)$
- position:
$\mathbf{p}(\alpha) = \mathbf{a} + (\mathbf{b}-\mathbf{a})\alpha$
Overlay rendering and interaction:
- editable START and GOAL input boxes
- reachability checks and status display
- PLAY/PAUSE button:
- PLAY validates inputs and starts a new simulation
- PAUSE stops simulation so inputs can be edited
Rendering helpers:
- text helpers (small and bold)
- robot visuals:
- base pedestal + flange
- joint housings
- tapered links
- suction tool
Below is a link to the simulation video on YouTube.
- This repo includes
.cargo/config.tomlto improve reliability on slow/unstable networks. - If you still see timeouts:
- try again later or from a different network
- ensure proxies/VPNs are not interfering with
static.crates.io
- Use Developer PowerShell for VS 2022.
- If
kernel32.libis missing or a wronglink.exeis used, follow the PowerShell configuration in:
Some systems require LLVM/Clang to be installed for bindgen/clang-sys when building native dependencies.
- Windows: install LLVM and ensure
libclangis discoverable - macOS: Xcode Command Line Tools usually provide clang
- Linux: install clang/llvm packages if needed
- Ensure:
z >= 0|p|is within the workspace shell:[|L1 - L2|, L1 + L2]