Search code examples
drake

How to add JointActuator for PlanarJoint?


I am working on a simple 2D peg-in-hole example in which I want to directly control the peg (which is just a box) in 2D. In order to do that, I add a planar joint to attach the peg to the world as in the Manipulation course's example.

planar_joint_frame = plant.AddFrame(FixedOffsetFrame("planar_joint_frame", plant.world_frame(),RigidTransform(RotationMatrix.MakeXRotation(np.pi/2))))                                                     
peg_planar_joint_frame = plant.AddFrame(FixedOffsetFrame("peg_planar_joint_frame", peg.body_frame(),RigidTransform(RotationMatrix.MakeXRotation(np.pi/2), [0, 0, 0.025])))                                              
peg_planar_joint = plant.AddJoint(PlanarJoint("peg_planar_joint", planar_joint_frame,peg_planar_joint_frame, damping=[0, 0, 0]))    

Then I want to add actuator to the peg_planar_joint so that I can directly apply planar force fx, fy and torque tau_z.

plant.AddJointActuator("peg_planar_joint", peg_planar_joint)

However, I encounter the following error

SystemExit: Failure at bazel-out/k8-opt/bin/multibody/plant/_virtual_includes/multibody_plant_core/drake/multibody/plant/multibody_plant.h:1131 in AddJointActuator(): condition 'joint.num_velocities() == 1' failed.

It seems that JointActuator can only be added to PrismaticJoint or RevoluteJoint that is with 1 degree of freedom. So my question is can I add JointActuator seperately to the x, y and RotZ of PlanarJoint? If not, what is the workaround method? Thank you!


Solution

  • Right now you have to add the prismatic and revolute joint's yourself to add actuators. Here is a snippet from https://github.com/RussTedrake/manipulation/blob/f868cd684a35ada15d6063c70daf1c9d61000941/force.ipynb

        # Add a planar joint the old fashioned way (so that I can have three actuators):
        gripper_false_body1 = plant.AddRigidBody(
            "false_body1", gripper,
            SpatialInertia(0, [0, 0, 0], UnitInertia(0, 0, 0)))
        gripper_false_body2 = plant.AddRigidBody(
            "false_body2", gripper,
            SpatialInertia(0, [0, 0, 0], UnitInertia(0, 0, 0)))
        gripper_x = plant.AddJoint(
            PrismaticJoint("gripper_x", plant.world_frame(),
                           plant.GetFrameByName("false_body1"), [1, 0, 0], -.3, .3))
        plant.AddJointActuator("gripper_x", gripper_x)
        gripper_z = plant.AddJoint(
            PrismaticJoint("gripper_z", plant.GetFrameByName("false_body1"),
                           plant.GetFrameByName("false_body2"), [0, 0, 1], 0.0,
                           0.5))
        gripper_z.set_default_translation(0.3)
        plant.AddJointActuator("gripper_z", gripper_z)
        gripper_frame = plant.AddFrame(
            FixedOffsetFrame(
                "gripper_frame", plant.GetFrameByName("body", gripper),
                RigidTransform(RotationMatrix.MakeXRotation(np.pi / 2))))
        gripper_theta = plant.AddJoint(
            RevoluteJoint("gripper_theta", plant.GetFrameByName("false_body2"),
                          gripper_frame, [0, -1, 0], -np.pi, np.pi))
        plant.AddJointActuator("gripper_theta", gripper_theta)