In this lesson, you will learn to model systems of the form
where
Note: I will provide links to the documentaiton but it will take time to understand how to read the documentation, especially because we are using python but the documentation is auto-generated from C++ code. Almost everything in the C++ documentation has been ported to python using bindings, but not everything. If you need help seeing how something is done in Python, search the Drake github page. For your first pass through this tutorial, you may skip the documentation, but later on you should at least become familiar with all the functions you use in Drake so you know what else is available.
Specifically, you will simulate a double integrator with dynamics:
with
-
Change the initial conditions and constant input vector to something else.
-
Modify the system dynamics. For example, a block sliding across a plane is modeled with
$$F = ma$$ i.e.$$m \ddot{x} = u$$ . Change the block's mass and/or incorporate linear viscuous drag force (proportional to the velocity). -
Replace the
ConstantVectorSourcewith your own leaf system that outputs a sinusoid. Connect the output of this leaf system to the double integrator. Also, add another logger to visualize the input to the double integrator. Hint: here is some more starter code.
class Controller(LeafSystem):
def __init__(self):
LeafSystem.__init__(self)
self.DeclareVectorOutputPort("u", 1, self.MyOutput)
def MyOutput(self, context, output):
t = context.get_time()
u = 10*t # modify this line
output.SetFromVector([u])- Replace the LeafSystem controller which outputs a sinusoidal output with a built-in primitive block Sine. You will need to use
controller.GetOutputPort("y0")rather thancontroller.get_output_port()because theSineblock has three output ports instead of 1. (The correct output port cannot be assumed implicitly.) See the solution for details.