Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dartpy] Add JacobianNode and operational space controller example #1323

Merged
merged 4 commits into from
May 19, 2019

Conversation

jslee02
Copy link
Member

@jslee02 jslee02 commented May 18, 2019

The operational space control now can be written as easy as a few lines of Python code:

class HelloWorldNode(dart.gui.osg.RealTimeWorldNode):
    def __init__(self, world, kr5, target_pose = [0.3, 0.3, 0.3]):
        super(HelloWorldNode, self).__init__(world)
        self.kr5 = kr5
        self.dofs = self.kr5.getNumDofs()
        self.ee = kr5.getBodyNode('palm')
        self.target_pose = target_pose
        self.Kp = np.eye(3) * 50.0
        self.Kd = np.eye(self.dofs) * 5.0

    def customPreStep(self):
        M = self.kr5.getMassMatrix()

        J = self.ee.getLinearJacobian()
        Jt = J.transpose();
        JJt = np.matmul(J, Jt)
        kI = 0.0025 * np.eye(3)
        invJ = np.matmul(Jt, np.linalg.inv(JJt + kI))

        dJ = self.ee.getLinearJacobianDeriv()
        dJt = dJ.transpose()
        dJdJt = np.matmul(dJ, dJt)
        invdJ = np.matmul(dJt, np.linalg.inv(dJdJt + kI))

        e = self.target_pose - self.ee.getTransform().translation()
        de = -self.ee.getLinearVelocity()

        cg = self.kr5.getCoriolisAndGravityForces()

        tmp1 = np.matmul(np.matmul(invJ, self.Kp), de)
        tmp2 = np.matmul(np.matmul(invdJ, self.Kp), e)

        forces1 = np.matmul(M, tmp1 + tmp2)
        forces2 = cg
        forces3 = np.matmul(np.matmul(np.matmul(self.Kd, invJ), self.Kp), e)

        forces = forces1 + forces2 + forces3

        self.kr5.setForces(forces)

Before creating a pull request

  • Document new methods and classes
  • Format new code files using clang-format

Before merging a pull request

  • Set version target by selecting a milestone on the right side
  • Summarize this change in CHANGELOG.md
  • Add unit test(s) for this change

@jslee02 jslee02 added this to the DART 6.9.0 milestone May 18, 2019
@jslee02 jslee02 marked this pull request as ready for review May 18, 2019 17:34
@codecov
Copy link

codecov bot commented May 18, 2019

Codecov Report

Merging #1323 into master will increase coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #1323      +/-   ##
==========================================
+ Coverage    57.1%   57.12%   +0.01%     
==========================================
  Files         366      366              
  Lines       27050    27050              
==========================================
+ Hits        15447    15452       +5     
+ Misses      11603    11598       -5
Impacted Files Coverage Δ
dart/dynamics/EulerJoint.cpp 70.73% <0%> (+3.04%) ⬆️

@jslee02 jslee02 merged commit 57cbef1 into master May 19, 2019
@jslee02 jslee02 deleted the dartpy/operational_space_control branch May 19, 2019 01:17
@jslee02 jslee02 changed the title pydart: Add JacobianNode and operational space controller example [dartpy] Add JacobianNode and operational space controller example May 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant