A simple 2-DOF robotic arm kinematics controller for educational purposes, built with PlatformIO and Arduino.
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.
- 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)
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) |
- Clone or download this repository
- Open the project folder in PlatformIO
- Build and upload to your Arduino board
- Open the Serial Monitor (9600 baud)
- 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
- Press Switch 1
- Enter two joint angles in radians via Serial Monitor
- Example:
1.57 0.785
(90° and 45°) - The arm moves and displays the calculated end-effector position
- Press Switch 2
- Enter target X and Y coordinates in meters
- Example:
0.15 0.05
(15cm right, 5cm up) - The arm calculates angles and moves to the position
- Press Switch 3
- Enter target X and Y coordinates in meters
- Same input as Mode 2, but uses the alternative elbow configuration
Given joint angles θ₁ and θ₂, calculate position:
x = l₁ × cos(θ₁) + l₂ × cos(θ₁ + θ₂)
y = l₁ × sin(θ₁) + l₂ × sin(θ₁ + θ₂)
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]
forward_kinematic()
- Calculates FK and moves servosinverse_kinematic_elbow_up()
- IK solution with elbow aboveinverse_kinematic_elbow_down()
- IK solution with elbow belowis_reachable()
- Checks if target position is validread_input_*()
- Handles serial input parsing
Try these to learn more:
- Workspace Mapping: Input different angles and plot the reachable positions
- Singularities: Try positions at exactly 0m and 0.2m distance - what happens?
- Configuration Comparison: Send the same target to both elbow-up and elbow-down modes
- Unreachable Targets: Try positions beyond 0.2m radius and see the error handling
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
If your servos don't move correctly, you might need to adjust the angle mapping or add offsets.
- PlatformIO platform: Arduino
- Framework: Arduino
- Library: Servo (built-in Arduino library)
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
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.