-1

I'm trying to use FirstOrderTaylorExpansion to get linearized dynamics for Direct Shooting.

My current code is this: enter image description here

Cropped line:

coeffs = FirstOrderTaylorApproximation(system, context, [drone.get_actuation_input_port(),input_port_index], [drone.get_state_output_port(), output_port_index])

I also tried FirstOrderTaylorApproximation(system, context, input_port_index, output_port_index)

The error I keep getting is: enter image description here

Update: Issue resolved from Russ's previous answer! The new issue I am getting is enter image description here. I'm not sure how to choose a new subsystem context, and I tried using that function with an input of context (as defined in my code), but it did not work.

ishicode
  • 1
  • 1
  • BTW see https://stackoverflow.com/help/how-to-ask where it says: **DO NOT post images of code, data, error messages, etc** -- copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. That's why you are being downvoted. – jwnimmer-tri May 14 '23 at 20:05

2 Answers2

0
coeffs = FirstOrderTaylorApproximation(system, context, [drone.get_actuation_input_port(),input_port_index], [drone.get_state_output_port(), output_port_index])

should be

coeffs = FirstOrderTaylorApproximation(system, context, drone.get_actuation_input_port().get_index(), drone.get_state_output_port().get_index())

I think you were interpreting the Union[..] in the error message as a request for a list of both objects... it was asking for one or the other of those objects.

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

Regarding your second (updated) question. I'm not exactly sure from your screen shot where the drone object is coming from. I guess you are using the MakeMultibodyQuadrotor from the course notes.

In that case I would expect the workflow to look more like the MultibodyQuadrotorLQR example in that same notebook. The workflow for you would look more like:

    quadrotor, mbp = MakeMultibodyQuadrotor()
    context = quadrotor.CreateDefaultContext()
    quadrotor.get_input_port().FixValue(context, nominal_input)
    controller = FirstOrderTaylorApproximation(quadrotor, context)

Since the quadrotor diagram only exports one input port (and no output ports), you don't even need to pass that in to FirstOrderTaylorApproximation.

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