0

This code should be simple enough. But I can't get it right. And, I don't find answer from previous similar questions. Is it a pydrake issue or just I don't use it in the right way?

TypeError: set_value(): incompatible function arguments. The following argument types are supported:
    1. (self: pydrake.common.value.Value[QueryObject_[float]], arg0: pydrake.geometry.QueryObject_[float]) -> None
Invoked with: <pydrake.common.value.Value[QueryObject_[float]] object at 0x1298c2c30>, (0, 0)
from pydrake.all import *
from underactuated import ManipulatorDynamics


x= [1,2,3,4]
u= [1,1]

plant = MultibodyPlant(time_step=0)
parser = Parser(plant)
parser.AddModelFromFile(FindResource("models/double_pendulum.urdf"))
plant.Finalize()

context = plant.CreateDefaultContext()
context.SetContinuousState(x)
plant.get_actuation_input_port(0).FixValue(context,u)
Eric Cousineau
  • 1,944
  • 14
  • 23
Wc Chang
  • 97
  • 6
  • I can't replicate your error. The code you have (with two fixes: 1) importing `FindResource`, and 2) removing the `0` argument from `get_actuation_input_port`) works fine for me. – Russ Tedrake Oct 31 '20 at 13:50
  • Same as Russ's result. I also tried out a different model (Drake only), using the example [in this nobook](http://manipulation.csail.mit.edu/robot.html#example1) to provision Drake on Colab, and then executing this modified version of your code with Russ's fixes (though keeping the model instance): [github gist](https://gist.github.com/EricCousineau-TRI/51a2a453b78b085cdce16af102fc40d0) FWIW Your error message indicates you were using a `QueryObject`-valued port to generate that message, like `MultibodyPlant.get_geometry_query_input_port`. – Eric Cousineau Oct 31 '20 at 20:18
  • I can get it right without 0 in port(), that is plant_ad.get_actuation_input_port().FixValue(context, u). But it don't work if u is type of autodiff. ( initializeAutoDiff(u) ). Is it possible to fix it? – Wc Chang Nov 01 '20 at 11:13
  • I think I figured out how to solve your autodiff problem. You will need to call `plant_ad.get_actuation_input_port().FixValue(context_ad, BasicVector_[AutoDiffXd](xu_ad[4:]))`. Notice that the second argument of `FixValue` is a `BasicVector` object, not a numpy array. I will update the code in https://stackoverflow.com/questions/64565023/how-to-get-a-dynamic-which-we-can-be-applied-gradient-in-the-next-step-re-open – Hongkai Dai Nov 02 '20 at 21:26
  • This code can work! I learn a lot from them, thank you so much! – Wc Chang Nov 03 '20 at 09:50

1 Answers1

0

Turns out there was a real bug here. It's fixed in https://github.com/robotlocomotion/drake/pull/14343

You should be able to call plant.get_actuation_input_port(0).FixValue(context,u) without having to go through BasicVector.

Russ Tedrake
  • 4,703
  • 1
  • 7
  • 10