TypeError: set_actuation_vector(): incompatible function arguments ; Pydrake

40 views Asked by At

Used AddMultibodyPlantSceneGraph, import lines shown below, when running, passes assertion checks but gets error :

TypeError: set_actuation_vector(): incompatible function arguments. The following argument types are supported:
    1. (self: pydrake.multibody.tree.JointActuator, u_instance: numpy.ndarray[numpy.float64[m, 1]], u: Optional[numpy.ndarray[numpy.float64[m, 1], flags.writeable]]) -> None

Invoked with: <JointActuator name='joint_RW_J_Pitch' index=0 model_instance=2>, array([0.])
from pydrake.all import (
    AddMultibodyPlantSceneGraph,
    Simulator,
    StartMeshcat,
    DiagramBuilder,
)
from pydrake.multibody.tree import JointIndex, JointActuatorIndex, JointActuator

    plant, scene_graph = AddMultibodyPlantSceneGraph(builder, time_step=0.0)
    parser.package_map().Add("URDF_LargeWings", os.path.join(project_dir))
    parser.AddModelFromFile(os.path.join(project_dir, "urdf", "URDF_LargeWings.sdf"))
    plant.Finalize()

    rw_passive = plant.GetJointActuatorByName("joint_RW_J_Pitch")
    lw_passive = plant.GetJointActuatorByName("joint_LW_J_Pitch")
    assert isinstance(rw_passive, JointActuator)
    assert rw_passive.joint().num_velocities() == 1
    u_inst = np.array([[0.0]])
    rw_passive.set_actuation_vector(u_inst)

The joint itself is defined in the sdf as a revolute joint so the assertion matches up. Actuation vector should be 1x1. I've tried with different arrays like np.array([[0.0]]). Checked the types too, u_inst.dtype is float64, array shape is (1,1).

Let me know if more information or source files are needed, my SDF also includes meshfiles.

1

There are 1 answers

0
jwnimmer-tri On BEST ANSWER

The function JointActuator.set_actuation_vector has two arguments, u_instance and u. The type signature is a little bit misleading -- it marks u as Optional[] but the details say RuntimeError if u is nullptr so its not actually optional. In short, the problem with the code is that its only passing 1 argument instead of 2.