Inverse Kinematics of a 2-Link Arm
~18 mincode completion
Implement ik_2link(l1, l2, x, y, elbow_up) returning the array [q1, q2] in radians.
Examples
Fully stretched along x: both joints zero
- Input
- ik_2link(1, 1, 2, 0, True)
- Output
- [0, 0]
Target (1, 1), elbow up: q1 = 0, q2 = pi/2
- Input
- ik_2link(1, 1, 1, 1, True)
- Output
- [0, 1.5708]
Same target, elbow down: q1 = pi/2, q2 = -pi/2
- Input
- ik_2link(1, 1, 1, 1, False)
- Output
- [1.5708, -1.5708]
Hints
Hint 1
bounds an array in one call.
Hint 2
Reach for atan2 rather than acos for q1.
Requirements
elbow_up: True for sin(q2) >= 0, False for sin(q2) <= 0Return array [q1, q2] in radians
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Try similar problems(4)
MediumMediumMediumMedium
Forward Kinematics of a DH Chain
Pro
Industrial Robotics: Kinematics and Control · ~16 min
Rotation Matrix to a Unit Quaternion
Pro
Industrial Robotics: Kinematics and Control · ~14 min
Damped Least-Squares Velocity Step
Pro
Industrial Robotics: Kinematics and Control · ~16 min
Rotation from Axis and Angle
Pro
Industrial Robotics: Kinematics and Control · ~16 min
Where this shows up
~18 min
••••••••••••
6 employers weight this skill
4 autonomy companies, 2 defense companies. Top match scores 92.
Python
import numpy as np
def ik_2link(l1, l2, x, y, elbow_up):
"""
Closed-form inverse kinematics of a planar two-link arm.
Args:
l1, l2: link lengths
x, y: target position (reachable)
elbow_up: True for sin(q2) >= 0, False for sin(q2) <= 0
Returns:
array [q1, q2] in radians
"""
# YOUR CODE HERE
pass