RASW is a Python library for simulating and controlling robotic arms. It provides both forward and inverse kinematics calculations for 2D robotic arms with multiple segments. Use RASW for robotics education, prototyping, or controlling physical robotic arm systems. The library offers a simple API with comprehensive math documentation.
RASW can be easily installed via pip:
pip install raswThat's it! After installation, you can use the CLI tool with:
rasw-cli --helpOr import the package in your Python code:
from RASW import calculate_fk, calculate_ik
# Example usage
joint_positions, _ = calculate_fk([10, 10], [45, 45])If you want to build from source:
-
Clone the repository
git clone https://github.com/Jasminestrone/RASW.git cd RASW -
Run the build script
# On Windows python build_package.py # On Mac/Linux python3 build_package.py
-
Install locally (the script will show the exact path to use)
# On Windows pip install dist\your_wheel_file.whl # On Mac/Linux pip install dist/*.whl
Windows
py -m ensurepip --default-pip
Mac/Linux
python3 -m ensurepip --default-pip
When you first import RASW after installation, it will automatically open the GitHub documentation page in your default web browser. If you want to disable this behavior, set the environment variable RASW_NO_BROWSER=1 before importing the package.
After installation, you can use the rasw-cli command:
# Get help
rasw-cli --help
# Show version
rasw-cli --version
# Forward Kinematics
rasw-cli fk --lengths 160 160 160 --angles 45 -30 60
# Inverse Kinematics
rasw-cli ik --position 200 150 --lengths 160 160You can also use RASW directly in your Python code:
from RASW import calculate_fk, calculate_ik
# Forward Kinematics example
arm_lengths = [160, 160, 160] # Three arm segments
joint_angles = [45, -30, 60] # Joint angles in degrees
joint_positions, error = calculate_fk(arm_lengths, joint_angles)
if not error:
base_pos = joint_positions[0]
end_effector_pos = joint_positions[-1]
print(f"End effector at: ({end_effector_pos[0]:.2f}, {end_effector_pos[1]:.2f})")
# Inverse Kinematics example
target_x, target_y = 200, 150
arm_lengths = [160, 160] # Two arm segments
joint_angles, error = calculate_ik(target_x, target_y, arm_lengths)
if not error:
shoulder_angle = joint_angles[0]
elbow_angle = joint_angles[1]
print(f"Shoulder angle: {shoulder_angle:.2f}°, Elbow angle: {elbow_angle:.2f}°")Math
Math for 2D inverse kinematics
Inverse kinematics desmos - https://www.desmos.com/calculator/uyuilbk8goThe elbow angle is found using the law of cosines where we do
Next we compute the shoulder angle in two steps:
- First we find the angle from the origin to the target point:
$$\alpha = \tan^{-1}\left(\frac{y}{x}\right)$$ - Then we find the angle between the first link and the line to the target:
$$\cos(\alpha) = \frac{L_1^2 + D^2 - L_2^2}{2L_1D}$$ $$\beta = \cos^{-1}(\cos(\beta))$$
Finally we get theta1 by subtracting alpha from the target angle:
We convert these angles from radians to degrees by doing:
Math for 2D forward kinematics
The forward kinematics calculation starts with the initial arm segments at the origin pointing along the x-axis, then applies sequential rotations to find each joint position.
For each arm segment (L1, L2, L3, L4), we:
-
Begin with a vector along the x-axis with magnitude equal to the link length:
$${arm_vector} = [L_i, 0]$$ -
Apply rotation matrices to transform each link vector: $$ R(\theta) = \begin{bmatrix} \cos(\theta) & -\sin(\theta) \ \sin(\theta) & \cos(\theta) \end{bmatrix} $$ For each joint, the rotation angle is cumulative from previous joints:
-
First joint rotates by
$\theta_1$ = l1_angle -
Second joint rotates by
$\theta_2$ = l1_angle + l2_angle -
Third joint rotates by
$\theta_3$ = l1_angle + l2_angle + l3_angle -
Fourth joint rotates by
$\theta_4$ = l1_angle + l2_angle + l3_angle + l4_angle
Each joint position is calculated by adding the rotated vector to the previous joint: $${joint_i_pos} = {joint_(i-1)pos} + R(\theta{\text{cum}}) \cdot {arm_i_vect}$$
This process is repeated sequentially until we reach the end effector position, which is the position after the last arm segment.
The rotation function rotate_vector(vector, angle) multiplies the vector by the rotation matrix to produce a new vector rotated by the specified angle:
This approach correctly implements forward kinematics for a 4-link planar arm by accumulating rotations and positions from the base to the end effector.