Getting started
In this section we will review how “moro” can be used to address some common exercises in robot kinematics.
Forward kinematics for RR manipulator
In the figure is shown a RR manipulator with references frames and its DH parameters table. Now, the goal is to calculate the forward kinematics using moro
, how this is done?
Well, the next lines of code can do this task:
>>>from moro import *
>>> rr = Robot((l1,0,0,t1),(l2,0,0,t2))
>>> T = rr.T
>>> print(T)
Matrix([[cos(theta_1 + theta_2), -sin(theta_1 + theta_2), 0, l_1*cos(theta_1) + l_2*cos(theta_1 + theta_2)], [sin(theta_1 + theta_2), cos(theta_1 + theta_2), 0, l_1*sin(theta_1) + l_2*sin(theta_1 + theta_2)], [0, 0, 1, 0], [0, 0, 0, 1]])
In T
is saved the \(T_2^0\) matrix calculated. What about the above code?
First line import the library
Second line create a
Robot
object using the DH parameters of the RR manipulator. The DH parameters are passed as tuples in the following order: \((a_i, \alpha_i, d_i, \theta_i)\)In the third line the
T
attribute fromrr
object is accessed and saved in T variable.The fourth line print the result.
As you can see, the matrix print in console is not so practical when symbolic variables are used. Alternatively, you can use the pprint
function and to obtain better results:
>>> pprint(T)
⎡cos(θ₁ + θ₂) -sin(θ₁ + θ₂) 0 l₁⋅cos(θ₁) + l₂⋅cos(θ₁ + θ₂)⎤
⎢ ⎥
⎢sin(θ₁ + θ₂) cos(θ₁ + θ₂) 0 l₁⋅sin(θ₁) + l₂⋅sin(θ₁ + θ₂)⎥
⎢ ⎥
⎢ 0 0 1 0 ⎥
⎢ ⎥
⎣ 0 0 0 1 ⎦
For best results (in printing aspects) we encourage you to use Jupyter Notebooks.
If you want to replace symbolic variables by numeric values, then you can use subs
method:
>>> T.subs({l1:100,l2:100,t1:0,t2:0})
⎡1 0 0 200⎤
⎢ ⎥
⎢0 1 0 0 ⎥
⎢ ⎥
⎢0 0 1 0 ⎥
⎢ ⎥
⎣0 0 0 1 ⎦
Calculating geometric jacobian for RR manipulator
>>> rr = Robot((l1,0,0,t1), (l2,0,0,t2))
>>> J = rr.J
>>> pprint(J)
⎡-l₁⋅sin(θ₁) - l₂⋅sin(θ₁ + θ₂) -l₂⋅sin(θ₁ + θ₂)⎤
⎢ ⎥
⎢l₁⋅cos(θ₁) + l₂⋅cos(θ₁ + θ₂) l₂⋅cos(θ₁ + θ₂) ⎥
⎢ ⎥
⎢ 0 0 ⎥
⎢ ⎥
⎢ 0 0 ⎥
⎢ ⎥
⎢ 0 0 ⎥
⎢ ⎥
⎣ 1 1 ⎦