Skip to main content

7. Humanoid Robot Kinematics & Dynamics

Humanoid robots are complex machines designed to mimic human form and movement. Understanding their kinematics (geometry of motion) and dynamics (forces and torques causing motion) is fundamental to designing and controlling them effectively.

Kinematics

Kinematics describes the motion of a robot without considering the forces that cause that motion.

  • Forward Kinematics: Calculating the position and orientation of the end-effector (e.g., hand) given the joint angles.
  • Inverse Kinematics: Calculating the joint angles required to achieve a desired position and orientation of the end-effector. This is often more challenging and has multiple solutions.

Dynamics

Dynamics deals with the relationship between forces, torques, and the resulting motion of the robot's links and joints. This is crucial for controlling balance, interaction forces, and energy efficiency.

  • Equations of Motion: Often derived using Newton-Euler or Lagrangian mechanics.
  • Jacobian Matrix: Relates joint velocities to end-effector velocities, crucial for both kinematics and dynamics.

Simple Forward Kinematics (2D Arm)

import numpy as np
import matplotlib.pyplot as plt

def forward_kinematics_2d(l1, l2, theta1, theta2):
"""
Calculates the end-effector position for a 2D two-link robotic arm.
l1: length of the first link
l2: length of the second link
theta1: angle of the first link with the x-axis (radians)
theta2: angle of the second link relative to the first link (radians)
Returns (x, y) coordinates of the end-effector.
"""
x1 = l1 * np.cos(theta1)
y1 = l1 * np.sin(theta1)

x_ee = x1 + l2 * np.cos(theta1 + theta2)
y_ee = y1 + l2 * np.sin(theta1 + theta2)

return x_ee, y_ee

if __name__ == "__main__":
link1_length = 1.0
link2_length = 0.8

# Example: Varying joint angles
angle1 = np.deg2rad(30) # 30 degrees for first joint
angle2 = np.deg2rad(60) # 60 degrees relative for second joint

ee_x, ee_y = forward_kinematics_2d(link1_length, link2_length, angle1, angle2)
print(f"End-effector position: ({ee_x:.2f}, {ee_y:.2f})")

# Plotting the arm
plt.figure(figsize=(6, 6))
plt.plot([0, link1_length * np.cos(angle1)],
[0, link1_length * np.sin(angle1)], 'b-o', label='Link 1')
plt.plot([link1_length * np.cos(angle1), ee_x],
[link1_length * np.sin(angle1), ee_y], 'g-o', label='Link 2')
plt.plot(ee_x, ee_y, 'ro', markersize=8, label='End-effector')
plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('2D Two-Link Robotic Arm')
plt.grid(True)
plt.axvline(0, color='gray', linestyle='--')
plt.axhline(0, color='gray', linestyle='--')
plt.legend()
plt.gca().set_aspect('equal', adjustable='box')
plt.show()