This is a simple simulation of a three-link planar serial manipulator.
Please take a look at this Demo Video
- Clone the project
git clone https://github.com/sanjeevg15/robolink.git
- Install the dependencies
pip install -r requirements.txt
- If the above fails, please try installing the dependencies manually
pip install numpy
pip install pygame
Run the serial_manipulator_sim.py file
python main.py
Options:
python main.py --allow_negative_y
to allow target locations for the end-effector to be below the x-axis.
python main.py --optimization_algorithm box-search
for box optimization using box-search (default and preferred).
python main.py --optimization_algorithm gradient-descent
for gradient descent.
python main.py --wait_time 10
for specifying wait time (in miliseconds) between frames. (default: 250)
python main.py --num_points 10
for specifying the number of points to use for the box-search. (default: 100) \
The project is organized as follows:
- The main file is serial_manipulator_sim.py
- optim.py contains the optimization code
- utils.py contains utility/helper functions
- readme.md contains the documentation
We are required to solve the Inverse Kinematics Problem for a planar three link serial manipulator. Since the end-effector has two degrees of freedom and we have three joint angles in our control, it is a redundant manipulator. For any point in R^2, there are infinitely many points in the joint space that can be used to reach that point. Hence, we are asked to choose that configuration which minimizes the maximum change in any joint angle
We formulate this as a constrained optimization problem where the objective function is the maximum change in any joint angle and the constraints are:
- The position of the end-effector should be equal to the target position.
- The links should always lie completely above the x-axis.
In general, to solve such a an optimization problem (over three variables corresponding to the three joint angles), containing both equality as well as inequality constraints, we can use the Sequqntial Quadratic Programing Approach. However, this particular problem can be simplified to an unconstrained optimization over a single variable as follows:
- Let x be the first joint angle (i.e. A-B)
- This determines the position of the point B.
- Now consider the 2-link manipulator B-C-D.
- This manipulator has at most two solutions to the inverse kinematics problem which can be obtained analytically.
- Hence, for every value of x, we can obtain all possible solutions for the last two joint angles.
- For each of these solutions, we then calculate the maximum change in any joint angle.
- Thus, we have converted the original problem into an unconstrained optimization problem over a single variable.
- Constraints for the links to be above the x-axis:
- Since we can bound x to be in the range[0, pi], we can be certain that all configurations will have point B above the x-axis
- Point target point D has to be above the x-axis, otherwise the target point cannot be reached without some part of the link C-D being below the x-axis.
- Thus, the only point that can potentially be below the x-axis in some configurations is point C.
- These configurations can be avoided by simply returning a high value for the cost function at these configurations
- To obtain the optimal x, I use two approaches:
- Box-search: In the case of this univariate optimization problem, this is simply a sweep over equally spaced points within the variable bounds.
- Gradient Descent: Gradient calculation is done numerically. However, this method requires hyper-parameter tuning and the time to convergence can vary greatly depending on the learning rate.
- Both these implementations can be found in the optim.py file.