Week 3.2 - 2R Robotic Arm Challenge
Aim
To simulate the forward kinematics of a 2R Robotic arm
Objective
- To understand and implement forward kinematics for a 2R robotic arm.
- To visualise the motion of the robotic arm as the joint angles change.
- To generate an animation of the arm's movement and save it as a videofile.
Methodology
- Define the length of the two links.
- Generate a range of angles for each joint.
- Compute the position of the robotic arm’s joints using trigonometric calculations.
- Plot and animate the robotic arm’s motion frame by frame.
- Capture and save the animation as a video file.
Code
% Code to simulate the forward kinematics of a 2R Robotic Arm
clear all
close all
clc
Errors faced while programming
An issue arose where link two was getting longer and longer, eventually reaching the same length of the first link. After a step-by-step line check of the code, it was discovered that the length of link two was mistakenly used for the y-coordinate of the end of link one. Correcting this mistake ensured accurate link positioning and proper simulation.
Additionally, when creating figures, using a counter to store individual frames resulted in multiple figures being created, leading to increased execution time. By changing it to figure(1), the process became more efficient, reducing unnecessary figures and making it easier to access and update the figure during simulation.

Results
The simulation successfully visualises the movement of the 2R robotic arm as the joint angles vary. The trajectory and motion of the end effector demonstrate the expected kinematic behaviour. The captured frames are compiled into an animation, stored as a video file.