Skip to content

Adem-Aoun/arm2d-kinematics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arm2d-kinematic

A simple 2-DOF robotic arm kinematics controller for educational purposes, built with PlatformIO and Arduino.

📚 Educational Purpose

This project demonstrates the fundamental concepts of robotic arm kinematics:

  • Forward Kinematics: Calculate end-effector position from joint angles
  • Inverse Kinematics: Calculate joint angles from desired position
  • Workspace Analysis: Understanding reachable areas
  • Elbow Configurations: Different solutions for the same target point

Perfect for robotics students learning the basics of arm control and kinematics calculations.

🔧 Hardware Requirements

  • Arduino Uno/Nano
  • 2x Servo motors (SG90 or similar)
  • 3x Push buttons
  • Breadboard and jumper wires
  • Simple 2-link arm structure (can be 3D printed or made from cardboard)

Pin Connections

Component Arduino Pin
Joint 1 Servo Pin 9
Joint 2 Servo Pin 10
Mode Switch 1 Pin 3 (with internal pullup)
Mode Switch 2 Pin 4 (with internal pullup)
Mode Switch 3 Pin 5 (with internal pullup)

🚀 Getting Started

PlatformIO Setup

  1. Clone or download this repository
  2. Open the project folder in PlatformIO
  3. Build and upload to your Arduino board
  4. Open the Serial Monitor (9600 baud)

Arm Parameters

  • Link 1 Length: 0.1m (10cm)
  • Link 2 Length: 0.1m (10cm)
  • Workspace: Circular area from 0m to 0.2m radius

Note: Adjust the l1 and l2 constants in the code to match your actual arm dimensions

🎮 How to Use

Mode 1: Forward Kinematics

  1. Press Switch 1
  2. Enter two joint angles in radians via Serial Monitor
  3. Example: 1.57 0.785 (90° and 45°)
  4. The arm moves and displays the calculated end-effector position

Mode 2: Inverse Kinematics (Elbow-Up)

  1. Press Switch 2
  2. Enter target X and Y coordinates in meters
  3. Example: 0.15 0.05 (15cm right, 5cm up)
  4. The arm calculates angles and moves to the position

Mode 3: Inverse Kinematics (Elbow-Down)

  1. Press Switch 3
  2. Enter target X and Y coordinates in meters
  3. Same input as Mode 2, but uses the alternative elbow configuration

📐 The Math Behind It

Forward Kinematics

Given joint angles θ₁ and θ₂, calculate position:

x = l₁ × cos(θ₁) + l₂ × cos(θ₁ + θ₂)
y = l₁ × sin(θ₁) + l₂ × sin(θ₁ + θ₂)

Inverse Kinematics

Given position (x,y), calculate joint angles:

cos(θ₂) = (x² + y² - l₁² - l₂²) / (2 × l₁ × l₂)
θ₂ = ±arccos(cos(θ₂))    [+ for elbow-up, - for elbow-down]
θ₁ = atan2(...) [complex formula based on configuration]

🛠️ Code Structure

  • forward_kinematic() - Calculates FK and moves servos
  • inverse_kinematic_elbow_up() - IK solution with elbow above
  • inverse_kinematic_elbow_down() - IK solution with elbow below
  • is_reachable() - Checks if target position is valid
  • read_input_*() - Handles serial input parsing

🎓 Educational Exercises

Try these to learn more:

  1. Workspace Mapping: Input different angles and plot the reachable positions
  2. Singularities: Try positions at exactly 0m and 0.2m distance - what happens?
  3. Configuration Comparison: Send the same target to both elbow-up and elbow-down modes
  4. Unreachable Targets: Try positions beyond 0.2m radius and see the error handling

🔧 Customization

For Your Own Arm

Measure your arm links and update these lines:

const float l1 = 0.12f; // Your first link length in meters
const float l2 = 0.08f; // Your second link length in meters

Servo Calibration

If your servos don't move correctly, you might need to adjust the angle mapping or add offsets.

📝 Dependencies

  • PlatformIO platform: Arduino
  • Framework: Arduino
  • Library: Servo (built-in Arduino library)

🤝 Educational Use

This code is intended for learning robotics concepts. Feel free to:

  • Modify it for your own arm dimensions
  • Add new features as learning exercises
  • Use it in robotics courses or workshops
  • Experiment with different control methods

🐛 Troubleshooting

Servos not moving?

  • Check power connections
  • Verify servo wires are connected to pins 9 and 10
  • Make sure servos are powered (5V for most small servos)

Getting "unreachable" errors?

  • Check that your target positions are within 0.2m of the origin
  • Remember coordinates are in meters, not centimeters

Switches not working?

  • The code uses internal pullups, so switches should connect pin to ground
  • Just press the switch once to select the mode - no need to hold it

This is a basic educational implementation. Real robotic arms have much more sophisticated control systems, sensors, and safety features.

Releases

No releases published

Packages

No packages published

Languages