8000 comment out gravjac method · navrobot/robotics-toolbox-python@8858377 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8858377

Browse files
committed
comment out gravjac method
it's redundant and orphan code
1 parent eaf5b92 commit 8858377

File tree

2 files changed

+164
-42
lines changed

2 files changed

+164
-42
lines changed

roboticstoolbox/robot/Dynamics.py

Lines changed: 136 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -573,20 +573,144 @@ def itorque(self, qdd, q=None):
573573
else:
574574
return taui
575575

576-
def gravjac(self, q=None, grav=None):
577-
"""
578-
tauB = gravjac(q, grav) calculates the generalised joint force/torques
579-
due to gravity.
576+
# NOT CONVINCED WE NEED THIS, AND IT'S ORPHAN CODE
577+
# def gravjac(self, q, grav=None):
578+
# """
579+
# Compute gravity load and Jacobian
580+
581+
# :param q: The joint angles/configuration of the robot
582+
# :type q: float ndarray(n)
583+
# :param grav: The gravity vector (Optional, if not supplied will
584+
# use the stored gravity values).
585+
# :type grav: float ndarray(3,)
586+
587+
# :return tau: The generalised joint force/torques due to gravity
588+
# :rtype tau: float ndarray(n,)
589+
590+
# ``tauB = gravjac(q, grav)`` calculates the generalised joint force/torques
591+
# due to gravity and the Jacobian
592+
593+
# Trajectory operation:
594+
# If q is nxm where n is the number of robot joints then a
595+
# trajectory is assumed where each row of q corresponds to a robot
596+
# configuration. tau (nxm) is the generalised joint torque, each row
597+
# corresponding to an input pose, and jacob0 (6xnxm) where each
598+
# plane is a Jacobian corresponding to an input pose.
599+
600+
# :notes:
601+
# - The gravity vector is defined by the SerialLink property if not
602+
# explicitly given.
603+
# - Does not use inverse dynamics function RNE.
604+
# - Faster than computing gravity and Jacobian separately.
605+
606+
# Written by Bryan Moutrie
607+
608+
# :seealso: :func:`gravload`
609+
# """
610+
611+
# # TODO use np.cross instead
612+
# def _cross3(self, a, b):
613+
# c = np.zeros(3)
614+
# c[2] = a[0] * b[1] - a[1] * b[0]
615+
# c[0] = a[1] * b[2] - a[2] * b[1]
616+
# c[1] = a[2] * b[0] - a[0] * b[2]
617+
# return c
618+
619+
# def makeJ(O, A, e, r):
620+
# J[3:6,:] = A
621+
# for j in range(r):
622+
# if r[j]:
623+
# J[0:3,j] = cross3(A(:,j),e-O(:,j));
624+
# else:
625+
# J[:,j] = J[[4 5 6 1 2 3],j]; %J(1:3,:) = 0;
626+
627+
# if grav is None:
628+
# grav = np.copy(self.gravity)
629+
# else:
630+
# grav = getvector(grav, 3)
631+
632+
# try:
633+
# if q is not None:
634+
# q = getvector(q, self.n, 'col')
635+
# else:
636+
# q = np.copy(self.q)
637+
# q = getvector(q, self.n, 'col')
638+
639+
# poses = 1
640+
# except ValueError:
641+
# poses = q.shape[1]
642+
# verifymatrix(q, (self.n, poses))
643+
644+
# if not self.mdh:
645+
# baseAxis = self.base.a
646+
# baseOrigin = self.base.t
647+
648+
# tauB = np.zeros((self.n, poses))
649+
650+
# # Forces
651+
# force = np.zeros((3, self.n))
652+
653+
# for joint in range(self.n):
654+
# force[:, joint] = np.squeeze(self.links[joint].m * grav)
655+
656+
# # Centre of masses (local frames)
657+
# r = np.zeros((4, self.n))
658+
# for joint in range(self.n):
659+
# r[:, joint] = np.r_[np.squeeze(self.links[joint].r), 1]
660+
661+
# for pose in range(poses):
662+
# com_arr = np.zeros((3, self.n))
663+
664+
# T = self.fkine_all(q[:, p 57AE ose])
665+
666+
# jointOrigins = np.zeros((3, self.n))
667+
# jointAxes = np.zeros((3, self.n))
668+
# for i in range(self.n):
669+
# jointOrigins[:, i] = T[i].t
670+
# jointAxes[:, i] = T[i].a
671+
672+
# if not self.mdh:
673+
# jointOrigins = np.c_[
674+
# baseOrigin, jointOrigins[:, :-1]
675+
# ]
676+
# jointAxes = np.c_[
677+
# baseAxis, jointAxes[:, :-1]
678+
# ]
679+
680+
# # Backwards recursion
681+
# for joint in range(self.n - 1, -1, -1):
682+
# # C.o.M. in world frame, homog
683+
# com = T[joint].A @ r[:, joint]
684+
685+
# # Add it to the distal others
686+
# com_arr[:, joint] = com[0:3]
687+
688+
# t = np.zeros(3)
689+
690+
# # for all links distal to it
691+
# for link in range(joint, self.n):
692+
# if not self.links[joint].sigma:
693+
# # Revolute joint
694+
# d = com_arr[:, link] - jointOrigins[:, joint]
695+
# t = t + self._cross3(d, force[:, link])
696+
# # Though r x F would give the applied torque
697+
# # and not the reaction torque, the gravity
698+
# # vector is nominally in the positive z
699+
# # direction, not negative, hence the force is
700+
# # the reaction force
701+
# else:
702+
# # Prismatic joint
703+
# # Force on prismatic joint
704+
# t = t + force[:, link]
705+
706+
# tauB[joint, pose] = t.T @ jointAxes[:, joint]
707+
708+
# if poses == 1:
709+
# return tauB[:, 0]
710+
# else:
711+
# return tauB
580712

581-
tauB = gravjac() as above except uses the stored q and gravitational
582-
acceleration of the robot object.
583713

584-
Trajectory operation:
585-
If q is nxm where n is the number of robot joints then a
586-
trajectory is assumed where each row of q corresponds to a robot
587-
configuration. tau (nxm) is the generalised joint torque, each row
588-
corresponding to an input pose, and jacob0 (6xnxm) where each
589-
plane is a Jacobian corresponding to an input pose.
590714

591715
:param q: The joint angles/configuration of the robot (Optional,
592716
if not supplied will use the stored q values).

tests/test_SerialLink.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -645,36 +645,34 @@ def test_fkine_all(self):
645645
nt.assert_array_almost_equal(Tall[6].A, t6, decimal=4)
646646
nt.assert_array_almost_equal(Tall2[0].A, t0, decimal=4)
647647

648-
def test_gravjac(self):
649-
l0 = rp.RevoluteDH(d=2, B=3, G=2, Tc=[2, -1], alpha=0.4, a=0.2,
650-
r=[0.1, 0.2, 0.05], m=0.5)
651-
l1 = rp.PrismaticDH(theta=0.1, B=3, G=2, Tc=[2, -1], a=0.2,
652-
r=[0.1, 0.2, 0.05], m=0.5)
653-
654-
r0 = rp.SerialLink([l0, l0, l0, l0])
655-
r1 = rp.SerialLink([l0, l0, l0, l1])
656-
q = [0.3, 0.4, 0.2, 0.1]
657-
qT = np.c_[q, q]
658-
r0.q = q
659-
660-
grav = [0.3, 0.5, 0.7]
661-
662-
tauB = [0, 4.6280, 3.1524, 0.9324]
663-
tauB2 = [1.9412, 1.1374, 0.3494, -0.0001]
664-
tauB3 = [0, 3.2819, 2.0195, 1.9693]
665-
666-
res0 = r0.gravjac(qT)
667-
res1 = r0.gravjac(q)
668-
res2 = r0.gravjac(q, grav)
669-
res3 = r0.gravjac()
670-
res4 = r1.gravjac(q)
671-
672-
nt.assert_array_almost_equal(res0[:, 0], tauB, decimal=4)
673-
nt.assert_array_almost_equal(res0[:, 1], tauB, decimal=4)
674-
nt.assert_array_almost_equal(res1, tauB, decimal=4)
675-
nt.assert_array_almost_equal(res2, tauB2, decimal=4)
676-
nt.assert_array_almost_equal(res3, tauB, decimal=4)
677-
nt.assert_array_almost_equal(res4, tauB3, decimal=4)
648+
# def test_gravjac(self):
649+
# l0 = rp.RevoluteDH(d=2, B=3, G=2, Tc=[2, -1], alpha=0.4, a=0.2,
650+
# r=[0.1, 0.2, 0.05], m=0.5)
651+
# l1 = rp.PrismaticDH(theta=0.1, B=3, G=2, Tc=[2, -1], a=0.2,
652+
# r=[0.1, 0.2, 0.05], m=0.5)
653+
654+
# r0 = rp.DHRobot([l0, l0, l0, l0])
655+
# r1 = rp.DHRobot([l0, l0, l0, l1])
656+
# q = [0.3, 0.4, 0.2, 0.1]
657+
# qT = np.c_[q, q]
658+
659+
# grav = [0.3, 0.5, 0.7]
660+
661+
# tauB = [0, 4.6280, 3.1524, 0.9324]
662+
# tauB2 = [1.9412, 1.1374, 0.3494, -0.0001]
663+
# tauB3 = [0, 3.2819, 2.0195, 1.9693]
664+
665+
# res0 = r0.gravjac(qT)
666+
# res1 = r0.gravjac(q)
667+
# res2 = r0.gravjac(q, grav)
668+
# res4 = r1.gravjac(q)
669+
670+
# nt.assert_array_almost_equal(res0[:, 0], tauB, decimal=4)
671+
# nt.assert_array_almost_equal(res0[:, 1], tauB, decimal=4)
672+
# nt.assert_array_almost_equal(res1, tauB, decimal=4)
673+
# nt.assert_array_almost_equal(res2, tauB2, decimal=4)
674+
# nt.assert_array_almost_equal(res3, tauB, decimal=4)
675+
# nt.assert_array_almost_equal(res4, tauB3, decimal=4)
678676

679677
def test_ikcon(self):
680678
panda = rp.models.DH.Panda()

0 commit comments

Comments
 (0)
0