Skip to content

Repository files navigation

SafeArm AI - AI-Controlled Robotic Arm Simulation

An AI-powered robotic arm controlled by natural language using Cerebras GLM 4.7

React TypeScript Three.js Cerebras

Demo

Watch the Demo Video: https://youtu.be/sG32tBE-YMw

Try it Live: https://main.safearm-ai.pages.dev/ (Best viewed on desktop)

Showcase Image

What It Does

SafeArm AI is a browser-based robotic arm simulation where you can talk to an AI to control the robot. Just say things like:

  • "Pick up the red cube"
  • "Move the sphere to the left"
  • "Wave hello"
  • "Grab the cylinder and lift it"

The AI (powered by Cerebras GLM 4.7) understands your commands, plans the movements, and executes them in real-time using inverse kinematics for precise object manipulation.

Features

  • 🦾 6-DOF Robotic Arm - Physics-based simulation with realistic joint limits
  • 🧠 AI Brain (Cerebras GLM 4.7) - Natural language understanding with tool calling
  • 🎯 Inverse Kinematics - Automatic angle calculation for precise positioning
  • 🔧 Object Manipulation - Spawn, grab, move, and drop objects
  • Real-time Physics - Powered by Rapier physics engine
  • 💬 Chat Interface - Conversational control with action transparency

Tech Stack

Layer Technology
AI/LLM Cerebras API (GLM 4.7) with tool calling
Frontend React 19 + TypeScript
3D Engine Three.js via React Three Fiber
Physics Rapier (via @react-three/rapier)
State Zustand
Styling Tailwind CSS 4
Build Vite 7

Quick Start

Prerequisites

  • Node.js 18+
  • pnpm (or npm/yarn)
  • Cerebras API key (get one here)

Installation

# Clone the repo
git clone https://github.com/mutaician/safearm-ai.git
cd safearm-ai

# Install dependencies
pnpm install

# Set up environment
cp .env.example .env
# Edit .env and add your VITE_CEREBRAS_API_KEY

# Start development server
pnpm dev

Open http://localhost:5173 and start chatting with the robot!

How Cerebras GLM 4.7 Powers This

The magic happens through function calling (tool use). The AI has access to these tools:

Tool Description
move_joint Move individual joints (base, shoulder, elbow, wrist)
approach_object Use inverse kinematics to reach an object
gripper_action Open/close the gripper
get_objects_on_table See what objects exist
get_distance_to_target Check gripper proximity to object
spawn_object Add cubes, spheres, cylinders, cones
move_to_preset Go to home/ready positions

When you say "pick up the red cube", the AI:

  1. Calls get_objects_on_table to find the cube
  2. Uses approach_object with inverse kinematics to position the gripper
  3. Calls gripper_action(close) to grab it

All at Cerebras speed - responses in milliseconds, not seconds!

Project Structure

src/
├── components/
│   ├── simulation/     # 3D components (RobotArm, Environment, etc.)
│   └── ui/             # Chat interface, controls
├── lib/
│   └── cerebras/       # AI integration (client, tools, agent)
└── store/              # Zustand state management

🌐 Deploy to Cloudflare Pages

Option 1: Cloudflare Dashboard (Easiest)

  1. Push your code to GitHub
  2. Go to Cloudflare Dashboard → Pages
  3. Click Create a projectConnect to Git
  4. Select your repository
  5. Configure build settings:
    • Build command: pnpm build
    • Build output directory: dist
    • Root directory: / (leave default)
  6. Add environment variable:
    • VITE_CEREBRAS_API_KEY = your API key
  7. Click Save and Deploy

Option 2: Wrangler CLI

# Install Wrangler
pnpm add -g wrangler

# Login to Cloudflare
wrangler login

# Build the project
pnpm build

# Deploy
wrangler pages deploy dist --project-name=safearm-ai

Then add your VITE_CEREBRAS_API_KEY in Cloudflare Dashboard → Pages → Your Project → Settings → Environment variables.

⚠️ Security Note

The API key is bundled into the client-side code (prefixed with VITE_). For a production app, you'd want to:

  1. Create a Cloudflare Worker as a backend proxy
  2. Store the API key in Worker secrets
  3. Have the frontend call your Worker instead of Cerebras directly

For hackathon purposes, the current setup works fine!

🎓 What We Learned

  • Cerebras is FAST - Tool calling responses feel instant, making the robot responsive
  • Inverse Kinematics is hard - Spent time getting the math right for arm positioning
  • GLM 4.7 + Tools = Perfect for Robotics - The model naturally plans multi-step actions

🔮 Future Ideas

  • Add action verification layer (confirm dangerous moves)
  • Multiple arm coordination
  • Voice commands via Web Speech API
  • Save/replay movement sequences
  • VR controller support

📜 License

MIT


Built for the Cerebras x Cline Hackathon 🏆

About

SafeArm AI is a browser-based robotic arm simulation where you can talk to an AI to control the robot.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages