Formulas: screws.symbolic¶
Symbolic twins of the chapter functions, in SymPy: the product of exponentials, the Jacobians, the adjoint and Newton-Euler dynamics as formulas in the joint variables.
import screws.symbolic as sym, or just screws.symbolic, imported on first use. Each
function has the name and the arguments of its numerical twin (sym.fk_space(M, S,
theta) beside screws.fk_space(M, S, theta), MR's names too: sym.FKinSpace) and
returns SymPy matrices; a vector is a column. Two differences:
- theta may be left out (or None): the joint variables are then the real symbols theta1 ... thetan, and dtheta, ddtheta in the dynamics thetadot1 ..., thetaddot1 ... (see joint_symbols).
- A Python float is read as sympy.nsimplify(x, rational=True) reads it: as the decimal it prints as (0.425 is 17/40, 0.1 + 0.2 is 3/10), so a Robot's float arrays give clean formulas. np.pi / 2 is read as 1.5707963267949, so write sympy.pi / 2 where pi/2 is meant: SymPy objects pass through untouched (a sympy.Float stays a float).
Results are simplified (sympy.simplify, entry by entry) unless simplify=False, or by the function given instead (simplify=sympy.trigsimp is sometimes quicker). The kinematics of a six-joint arm take seconds, its gravity forces half a minute, its mass matrix far longer; and a robot read from floats that carry round-off simplifies slowly or not at all, which is what Robot.symbolic(decimals=...) is for.
Not here, being numerical by nature: the logarithms, inverse kinematics, manipulability, projections and distances, time stepping and trajectories. MR chapters 3, 4, 5 and 8; notes 3.5-3.7, 4.1-4.2, 5.1, 8.3.
SymbolicRobot
dataclass
¶
A serial chain whose description may hold symbols: the symbolic twin of screws.Robot.
M: 4x4 home configuration of {b} in {s}. S: 6xn space-frame screw axes, one per column. link_frames, link_inertias: MR's M_{i-1,i} and G_i, or None. gravity: the gravity vector in {s}, (0, 0, -g) with g a positive symbol unless given. Every method takes the joint values as optional (theta1 ... thetan when left out) and simplify=.
Build one from a numerical robot with Robot.symbolic() (its floats read as decimals), or by hand with from_screw_axes. MR 4.1, 8.3; notes chapter 4.
Source code in screws/symbolic.py
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 | |
from_robot
classmethod
¶
from_robot(robot, *, decimals=None)
The symbolic twin of a screws.Robot, its floats read as decimals (see exact for decimals); Robot.symbolic calls this.
Warns when, without decimals, the kinematics hold a number below 1e-5 that is not zero: almost always the round-off of a URDF's pi/2, which the formulas then carry and which keeps simplify from cancelling anything.
Source code in screws/symbolic.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | |
from_screw_axes
classmethod
¶
from_screw_axes(
M,
axes,
*,
name="robot",
joint_types=None,
joint_names=None,
gravity=None,
)
Build a robot from M and a sequence of space-frame screw axes, one 6-vector per joint.
As Robot.from_screw_axes: joint types default to reading each axis (omega = 0 means prismatic). Notes 4.1.
Source code in screws/symbolic.py
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | |
fk ¶
fk(theta=None, *, simplify=True)
T_sb(theta), by the space form. Notes 4.1.
Source code in screws/symbolic.py
701 702 703 | |
jacobian_space ¶
jacobian_space(theta=None, *, simplify=True)
J_s(theta). MR 5.1.1; notes 5.1.
Source code in screws/symbolic.py
705 706 707 | |
jacobian_body ¶
jacobian_body(theta=None, *, simplify=True)
J_b(theta). MR 5.1.2; notes 5.1.
Source code in screws/symbolic.py
709 710 711 | |
inverse_dynamics ¶
inverse_dynamics(
theta=None,
dtheta=None,
ddtheta=None,
F_tip=None,
*,
simplify=True,
)
tau = M(theta) ddtheta + c(theta, dtheta) + g(theta) + J^T F_tip. MR 8.3.
Source code in screws/symbolic.py
723 724 725 726 727 728 729 | |
mass_matrix ¶
mass_matrix(theta=None, *, simplify=True)
M(theta). MR 8.3.
Source code in screws/symbolic.py
731 732 733 | |
velocity_quadratic_forces ¶
velocity_quadratic_forces(
theta=None, dtheta=None, *, simplify=True
)
c(theta, dtheta). MR 8.3.
Source code in screws/symbolic.py
735 736 737 | |
gravity_forces ¶
gravity_forces(theta=None, *, simplify=True)
g(theta), with this robot's gravity. MR 8.3.
Source code in screws/symbolic.py
739 740 741 | |
end_effector_forces ¶
end_effector_forces(
theta=None, F_tip=None, *, simplify=True
)
J^T(theta) F_tip; F_tip defaults to the symbols m_x ... f_z. MR 8.3.
Source code in screws/symbolic.py
743 744 745 | |
forward_dynamics ¶
forward_dynamics(
theta=None,
dtheta=None,
tau=None,
F_tip=None,
*,
simplify=True,
)
ddtheta from tau (tau1 ... taun when left out), with this robot's gravity. MR 8.5.
Source code in screws/symbolic.py
747 748 749 750 751 752 753 | |
with_inertias ¶
with_inertias(link_frames, link_inertias)
A copy carrying MR's M_{i-1,i} list and G_i list.
Source code in screws/symbolic.py
755 756 757 | |
with_gravity ¶
with_gravity(g)
A copy with a different gravity vector.
Source code in screws/symbolic.py
759 760 761 | |
exact ¶
exact(a, *, decimals=None)
a as an exact SymPy object: a scalar, or a Matrix for anything array-like.
A float is read by sympy.nsimplify(x, rational=True), as the decimal it prints as (0.1 is 1/10, 1/3 is 1/3, np.pi / 2 is 15707963267949/10000000000000). decimals=k rounds every float to k places first: a URDF that writes pi/2 as 1.5708 leaves cos 1.5708 = -3.7e-6 where 0 was meant, and decimals=4 drops it. SymPy objects are left as they are, so sympy.pi / 2 stays pi/2. A 1-D sequence becomes a column. Addition, not in the MR library.
Source code in screws/symbolic.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
joint_symbols ¶
joint_symbols(n, name='theta')
The real symbols name1 ... namen, a tuple: theta1 ... thetan by default.
SymPy prints a trailing "dot" or "ddot" as an accent, so joint_symbols(2, "thetadot") displays as theta-dot-1, theta-dot-2. Addition, not in the MR library.
Source code in screws/symbolic.py
146 147 148 149 150 151 152 | |
rot_inv ¶
rot_inv(R)
The inverse of a rotation matrix, its transpose. MR 3.2.1; notes 3.3.
Source code in screws/symbolic.py
158 159 160 | |
vec_to_so3 ¶
vec_to_so3(omega)
[omega], the 3x3 skew-symmetric matrix with [omega] y = omega x y. MR eq. 3.30; notes 3.5.
Source code in screws/symbolic.py
163 164 165 166 | |
so3_to_vec ¶
so3_to_vec(so3mat)
The 3-vector omega from its skew-symmetric matrix [omega]. MR 3.2.3.1; notes 3.5.
Source code in screws/symbolic.py
169 170 171 172 | |
exp3 ¶
exp3(so3mat, *, simplify=True)
e^{[omega] theta}: the rotation matrix from the so(3) matrix [omega] theta.
Rodrigues' formula, I + sin(theta) [omega] + (1 - cos theta) [omega]^2, written in [omega] theta itself so the angle need not be passed separately. MR eq. 3.51; notes 3.6.
Source code in screws/symbolic.py
207 208 209 210 211 212 213 214 215 216 217 218 | |
rot ¶
rot(omega_hat, theta, *, simplify=True)
Rot(omega_hat, theta): the rotation about the unit axis omega_hat by theta.
Addition, not in the MR library. MR 3.2.3.3; notes 3.6.
Source code in screws/symbolic.py
221 222 223 224 225 226 | |
rotation_from_rpy ¶
rotation_from_rpy(roll, pitch, yaw, *, simplify=True)
URDF fixed-axis roll-pitch-yaw: Rot(z, yaw) Rot(y, pitch) Rot(x, roll).
Addition, not in the MR library. MR Appendix B.1; notes 4.3.
Source code in screws/symbolic.py
229 230 231 232 233 234 235 | |
rp_to_transform ¶
rp_to_transform(R, p)
The homogeneous transformation T = (R, p). MR eq. 3.62; notes 3.4.
Source code in screws/symbolic.py
241 242 243 244 245 246 | |
transform_to_rp ¶
transform_to_rp(T)
(R, p) from the homogeneous transformation T. MR 3.3.1; notes 3.4.
Source code in screws/symbolic.py
249 250 251 252 | |
transform_inv ¶
transform_inv(T)
T^{-1} = (R^T, -R^T p). MR eq. 3.64; notes 3.4.
Source code in screws/symbolic.py
255 256 257 258 | |
trans ¶
trans(p)
Trans(p): the pure translation by p. Addition, not in the MR library. MR 3.3.1.
Source code in screws/symbolic.py
261 262 263 | |
vec_to_se3 ¶
vec_to_se3(V)
[V], the 4x4 se(3) matrix of the twist V = (omega, v). MR eq. 3.72; notes 3.5.
Source code in screws/symbolic.py
266 267 268 269 270 271 272 | |
se3_to_vec ¶
se3_to_vec(se3mat)
The twist V = (omega, v) from its se(3) matrix [V]. MR 3.3.2.1; notes 3.5.
Source code in screws/symbolic.py
275 276 277 278 | |
adjoint ¶
adjoint(T)
[Ad_T], the 6x6 matrix that changes the frame of a twist. MR definition 3.20; notes 3.5.
Source code in screws/symbolic.py
281 282 283 284 285 286 287 288 | |
screw_axis ¶
screw_axis(q, s_hat, h)
The screw axis S = (s_hat, -s_hat x q + h s_hat) through q, direction s_hat, pitch h.
Finite pitch only; use prismatic_axis for h = infinity. MR eq. 3.77; notes 3.5.
Source code in screws/symbolic.py
291 292 293 294 295 296 297 | |
revolute_axis ¶
revolute_axis(q, s_hat)
Zero-pitch screw axis (s_hat, -s_hat x q) through the point q.
Addition, not in the MR library; the joint-frame derivation of notes 4.1.
Source code in screws/symbolic.py
300 301 302 303 304 305 306 | |
prismatic_axis ¶
prismatic_axis(s_hat)
Infinite-pitch screw axis (0, s_hat). Addition, not in the MR library. MR 3.3.2.2.
Source code in screws/symbolic.py
309 310 311 | |
exp6 ¶
exp6(se3mat, *, simplify=True)
e^{[S] theta}: the homogeneous transformation from the se(3) matrix [S] theta.
MR proposition 3.25, (e^{[omega] theta}, G(theta) v), with G(theta) v written in [omega] theta and v theta; a pure translation when omega = 0. MR 3.3.3; notes 3.7.
Source code in screws/symbolic.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
fk_space ¶
fk_space(M, S, theta=None, *, simplify=True)
Space form of the product of exponentials: e^{[S1]t1} ... e^{[Sn]tn} M.
S is 6xn, one screw axis per column, in {s} at the home position; theta defaults to theta1 ... thetan. MR eq. 4.14; notes 4.1.
Source code in screws/symbolic.py
369 370 371 372 373 374 375 376 377 378 379 380 | |
fk_body ¶
fk_body(M, B, theta=None, *, simplify=True)
Body form of the product of exponentials: M e^{[B1]t1} ... e^{[Bn]tn}.
B is 6xn, one screw axis per column, in {b} at the home position. MR eq. 4.16; notes 4.2.
Source code in screws/symbolic.py
383 384 385 386 387 388 389 390 391 392 393 | |
joint_frames ¶
joint_frames(M_joints, S, theta=None, *, simplify=True)
Every joint frame T_{0i}(theta) = e^{[S1]t1} ... e^{[Si]ti} M_joints[i-1], i = 1..n.
Addition, not in the MR library; the space form truncated after each joint. Notes 4.1.
Source code in screws/symbolic.py
396 397 398 399 400 401 402 403 404 405 406 407 408 | |
jacobian_space ¶
jacobian_space(S, theta=None, *, simplify=True)
The space Jacobian J_s(theta), 6xn, column i = [Ad_{e^{[S1]t1}...e^{[S_{i-1}]t_{i-1}}}] S_i.
MR eq. 5.11; notes 5.1.
Source code in screws/symbolic.py
411 412 413 414 415 416 417 418 419 420 421 422 423 | |
jacobian_body ¶
jacobian_body(B, theta=None, *, simplify=True)
The body Jacobian J_b(theta), 6xn, column i = [Ad_{e^{-[Bn]tn}...e^{-[B_{i+1}]t_{i+1}}}] B_i.
MR eq. 5.18; notes 5.1.
Source code in screws/symbolic.py
426 427 428 429 430 431 432 433 434 435 436 437 438 | |
ad ¶
ad(V)
[ad_V], the 6x6 matrix of the Lie bracket: [V1, V2] = [ad_V1] V2. MR eq. 8.39; notes 8.2.
Source code in screws/symbolic.py
444 445 446 447 448 449 450 451 452 | |
inverse_dynamics ¶
inverse_dynamics(
theta,
dtheta,
ddtheta,
g,
F_tip,
link_frames,
link_inertias,
S,
*,
simplify=True,
)
Joint forces/torques tau = M(theta) ddtheta + c(theta, dtheta) + g(theta) + J^T F_tip.
Newton-Euler forward and backward iterations, as screws.inverse_dynamics. theta, dtheta and ddtheta may be None: theta_i, thetadot_i, thetaddot_i. F_tip None means zero. MR 8.3.2, algorithm on p. 296; notes 8.3.
Source code in screws/symbolic.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
mass_matrix ¶
mass_matrix(
theta, link_frames, link_inertias, S, *, simplify=True
)
M(theta), one inverse-dynamics call per unit joint acceleration. MR 8.3.3; notes 8.3.
Source code in screws/symbolic.py
500 501 502 503 504 505 506 507 508 509 510 511 512 | |
velocity_quadratic_forces ¶
velocity_quadratic_forces(
theta,
dtheta,
link_frames,
link_inertias,
S,
*,
simplify=True,
)
c(theta, dtheta), the Coriolis and centripetal joint forces. MR 8.3.3; notes 8.3.
Source code in screws/symbolic.py
515 516 517 518 519 520 521 522 | |
gravity_forces ¶
gravity_forces(
theta,
g,
link_frames,
link_inertias,
S,
*,
simplify=True,
)
g(theta), the joint forces that hold the chain against gravity g. MR 8.3.3; notes 8.3.
Source code in screws/symbolic.py
525 526 527 528 529 530 | |
end_effector_forces ¶
end_effector_forces(
theta,
F_tip,
link_frames,
link_inertias,
S,
*,
simplify=True,
)
J^T(theta) F_tip, the joint forces that create the end-effector wrench alone. MR 8.3.3.
F_tip may be None: the symbols m_x, m_y, m_z, f_x, f_y, f_z.
Source code in screws/symbolic.py
533 534 535 536 537 538 539 540 541 542 543 544 545 | |
forward_dynamics ¶
forward_dynamics(
theta,
dtheta,
tau,
g,
F_tip,
link_frames,
link_inertias,
S,
*,
simplify=True,
)
ddtheta = M(theta)^{-1} (tau - c - g - J^T F_tip). tau may be None: tau1 ... taun.
The symbolic inverse grows quickly; past two or three joints, expect to wait. MR 8.5.
Source code in screws/symbolic.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | |