Princeton Intro to Robotics (Fall 2026) | Lecture 6: Trajectory Optimization — Transcript
Full transcript
- 0:10All right, I think we'll go ahead and
- 0:11get started. So, we're going to continue
- 0:13our discussion of motion planning and
- 0:15control,
- 0:16which is still the the first kind of
- 0:18technical module that we're covering in
- 0:19this course.
- 0:21So, in the last lecture we started
- 0:22talking about how to do motion planning
- 0:25while taking into account some dynamics
- 0:27of the drone.
- 0:28The idea was that not all continuous
- 0:30paths in configuration space are
- 0:33physically executable by the robot.
- 0:35You need some way of handling the
- 0:38dynamics, taking into account the
- 0:40dynamics that your particular system
- 0:42has.
- 0:43So, two lectures ago we talked a bit
- 0:44about how we can describe dynamics using
- 0:47equations of motion. These are
- 0:49differential equations that come from
- 0:50Newton's laws that describe the dynamics
- 0:52of your system.
- 0:53And then in the last lecture we started
- 0:55thinking about a particular class of
- 0:57mechanical systems
- 0:59known as differentially flat systems.
- 1:01Where the main idea is that differential
- 1:04flatness gives you the ability to
- 1:06control
- 1:07flat outputs. So, flat outputs are some
- 1:09function of the state and potentially
- 1:11control inputs.
- 1:13And if I
- 1:15kind of
- 1:16specify some trajectory in flat output
- 1:18space for my system to follow,
- 1:20then I can find control inputs that are
- 1:23going to make the the system actually
- 1:25follow any arbitrary trajectory that I
- 1:28specify.
- 1:29And moreover, we can also recover the
- 1:31full state of the the system at every
- 1:34point in time. There were some caveats
- 1:36here, some assumptions on the smoothness
- 1:38of the trajectory.
- 1:39So, for the
- 1:41planar quadrotor, the flat outputs
- 1:43correspond to the center of mass
- 1:44location, so X and Y.
- 1:46And differential flatness for the planar
- 1:48quadrotor says that if I specify some
- 1:51smooth trajectory for the center of mass
- 1:53location of the drone, then I can
- 1:55compute control inputs Uh, will make the
- 1:59the center of mass follow the trajectory
- 2:01I specified, and I can recover
- 2:03everything else. So, the orientation,
- 2:06um, the velocities and the orientation
- 2:08rates as well.
- 2:09And then we looked at a couple of, uh,
- 2:11examples of of differential flatness.
- 2:13Uh, I mentioned that, uh, not every
- 2:15system is known to be differentially
- 2:17flat, but it's a pretty broad and kind
- 2:19of powerful, uh, set of, uh, systems uh,
- 2:22that we know, uh, we as in kind of the
- 2:24community as a whole, uh, knows is
- 2:26differentially flat. And I showed this
- 2:28one example in particular, which is a a
- 2:30fixed-wing airplane, uh, which can take
- 2:33off and land vertically and transition
- 2:35to forward flight.
- 2:36And this system is is known to be
- 2:38differentially flat. The 3D quadrotor is
- 2:40flat. There's a couple of examples that
- 2:42you'll see in the assignment uh, that
- 2:44goes out tomorrow as well.
- 2:46Uh, okay, but I guess there are a couple
- 2:48of, uh, issues here with with
- 2:49differential flatness.
- 2:51So, the first one is what if we want to
- 2:53control states that are not in my flat
- 2:56outputs? So, for the planar quadrotor,
- 2:59suppose I really want to control the
- 3:01orientation, like maybe my drone has to
- 3:03go through some small slit,
- 3:06uh, in which case the orientation as
- 3:08it's going through that slit, like
- 3:09through the those obstacles, has to be
- 3:11some kind of particular value or
- 3:13particular range of values, then
- 3:16differential flatness is not sufficient,
- 3:18uh, because flatness doesn't give me the
- 3:20authority to control the orientation of
- 3:23the planar quadrotor.
- 3:24So, that's that's one limitation with,
- 3:26uh, with flatness.
- 3:28Uh, the other limitation, uh, is we
- 3:30might just not know if our system is
- 3:33differentially flat.
- 3:34Uh, if you build a new robot,
- 3:37um, yeah, you might not know if it is
- 3:39flat and it might not be differentially
- 3:41flat. Like there are examples where,
- 3:43um,
- 3:44at least for kind of non-trivial
- 3:45definitions of flatness, uh, your
- 3:47robotic system is is not differentially
- 3:49flat. Question.
- 3:58Yes. So, for the planar quadrotor, the
- 4:00flat outputs are X and Y.
- 4:02So, the theta, like the orientation, is
- 4:05something that's that's not captured by
- 4:07by the flat outputs.
- 4:08So, flatness is just saying that you can
- 4:11arbitrarily control the flat outputs,
- 4:14right? So, if I want to control the the
- 4:17orientation of the drone,
- 4:19like if I want to specify some
- 4:20constraints on the orientation, then
- 4:23that's not something that differential
- 4:25flatness is giving me. For the 3D
- 4:27quadrotor, I had mentioned that the flat
- 4:29outputs are X, Y, Z, and yaw. So, if I
- 4:32want to control roll and pitch at some
- 4:34particular location, let's say in the
- 4:36environment, differential flatness does
- 4:38not give me that authority.
- 4:46Right, exactly. So, if you want to use
- 4:49differential flatness
- 4:50to do obstacle avoidance,
- 4:53because you can only control X, Y in the
- 4:55planar case or X, Y, Z and yaw in the
- 4:59in the 3D case, you basically have to
- 5:02approximate your system as a as a
- 5:04sphere, because the other angles, like
- 5:06the roll and pitch angles, could be just
- 5:08doing completely arbitrary things. You
- 5:09have no
- 5:10control over them, at least from
- 5:13differential flatness.
- 5:15Okay, yeah. Any other questions on the
- 5:17setup?
- 5:19Okay, so the the goal today is to
- 5:22think of a a more general set of
- 5:24techniques for handling dynamics
- 5:27when we're doing motion planning.
- 5:29So, one idea is is maybe we can somehow
- 5:32modify the RRT algorithm, which we
- 5:35discussed a couple of lectures ago, to
- 5:37take into account the dynamics of our
- 5:39robot.
- 5:40So, I'll I'll present a couple of ideas
- 5:42for doing this. So, starting with the
- 5:44RRT algorithm, which doesn't take into
- 5:46account dynamics, and then modifying it
- 5:48to account for for dynamics.
- 5:50So, here's one idea. So, let's say we've
- 5:53modeled our robotic system, and these
- 5:56are the the differential equations that
- 5:58describe the dynamics. So, X dot equals
- 6:00f of X, U.
- 6:02One idea is to construct the RRT in
- 6:05state space
- 6:07instead of configuration space.
- 6:09So maybe this is how how it could work.
- 6:11So we start by initializing the tree the
- 6:15RRT
- 6:16with just one vertex. Let's say this is
- 6:18the the starting state. So the state
- 6:21here is now the full state of the system
- 6:23not just the configurations.
- 6:26So we we start our our tree with this as
- 6:29the only vertex in the tree.
- 6:31And then we iterate. So in each
- 6:32iteration we sample some random state X
- 6:36rand
- 6:37from the existing tree. So this is
- 6:39slightly different from the RRT
- 6:41algorithm we originally described. In
- 6:43the original version we were
- 6:45randomly sampling some configuration
- 6:48not from the tree but just from the
- 6:49space of all configurations. Here I'm
- 6:51saying let's sample from the the
- 6:53existing tree. Is there a question?
- 6:56Okay.
- 6:57Okay. So in the next next step let's say
- 7:00we randomly sample some control input as
- 7:03well. Just some random control input for
- 7:05the let's say for the drone.
- 7:08And then you do this extension. So from
- 7:10the random state that you sample from
- 7:13your existing tree
- 7:15you apply this random control input for
- 7:18some short time duration. So zero to to
- 7:22delta T.
- 7:23And then you integrate your system. So
- 7:25you we're assuming that we know what the
- 7:27dynamics are. So you can predict the
- 7:29trajectory of the system if you start
- 7:32from state X rand. You apply control
- 7:35input U rand for some short duration of
- 7:37time.
- 7:38Given the equations of motion you can
- 7:39predict exactly where you're going to
- 7:42end up at the end of delta T.
- 7:45So yeah, I guess what's what's happening
- 7:46here is we're just integrating the the
- 7:48equations of motion.
- 7:50So X rand plus the integral of the
- 7:53dynamics DT.
- 7:56And then we can kind of proceed as usual
- 7:58with the RRT algorithm. So this is our
- 8:00extended state. We can check whether
- 8:03this state XS is in collision with any
- 8:06obstacles or not. Uh if it's not in
- 8:09collision with with any obstacles, we
- 8:11add it to the tree. If it is in
- 8:13collision, then we throw it away and we
- 8:15iterate.
- 8:16So, all right. So, I guess this is one
- 8:18kind of attempt at taking into account
- 8:20the the dynamics of your system uh when
- 8:23you're building the the RRT. Uh the
- 8:26high-level idea is instead of building
- 8:27the tree in configuration space,
- 8:29uh build it in state space and then kind
- 8:31of modify things accordingly.
- 8:34All right. I guess any intuitions on on
- 8:36um
- 8:37whether this is a good algorithm? Like,
- 8:40what do you think is going to happen
- 8:42if we try this out? Like, will it will
- 8:43it work well? Is this something that we
- 8:44might actually want to use in practice
- 8:47to do planning
- 8:48while taking into account dynamics?
- 8:52Yep.
- 8:53>> I guess it doesn't make sense to work
- 8:55out.
- 8:55>> Good. Yeah. So, that that's exactly
- 8:57right. I guess you have some intuition
- 8:58for for why?
- 9:00>> Uh random point
- 9:01in the existing tree.
- 9:03>> Yep.
- 9:04Perfect. Yeah. So, that that's exactly
- 9:06the right intuition.
- 9:07So, theoretically, you can actually show
- 9:09that this algorithm is probabilistically
- 9:11complete. So, if you allow the number of
- 9:15iterations to go to infinity, if there
- 9:17is some way to get from start to to goal
- 9:19or at least close to goal, uh then this
- 9:22algorithm will
- 9:23uh the probability that the algorithm
- 9:25finds the trajectory is going to
- 9:26approach one as the number of iterations
- 9:28goes to infinity.
- 9:30Uh unfortunately, in practice, this is a
- 9:31completely useless algorithm. You
- 9:33basically just end up with this kind of
- 9:35muddled uh mess. Like as you suggested,
- 9:37you you you don't get any exploration.
- 9:39You're always sampling points from the
- 9:41existing tree. Uh if I have this kind of
- 9:44jumble of points to begin with, uh if I
- 9:46sample within this jumble, I'm just
- 9:48going to get something in the jumble and
- 9:50then I'll extend and I'll just get more
- 9:51jumble. Like, there's no way to to
- 9:53really explore the the state space uh
- 9:56using the the algorithm uh that I
- 9:57described.
- 9:59Um so, here's another idea, slightly uh
- 10:03maybe so more sophisticated idea uh to
- 10:06to take into account dynamics as we're
- 10:07building the RRT.
- 10:09Again, we're going to keep the the
- 10:11general structure of the RRT algorithm
- 10:13the same as what we originally
- 10:15introduced.
- 10:16Um but just change the the way the
- 10:19extension of the tree is happening. So,
- 10:21in the original RRT algorithm, uh we
- 10:23have some existing tree.
- 10:25We sample some random configuration. We
- 10:28find the closest point in the existing
- 10:30tree to that newly sampled point. Uh and
- 10:32then we extend with just a line segment.
- 10:35Uh and the problem there was that we're
- 10:36not taking into account the dynamics in
- 10:39that extension operation. Like it's just
- 10:41a line segment. Uh there's no accounting
- 10:43for the specific motions that are
- 10:45actually physically feasible for your
- 10:47robot.
- 10:49Uh so, what we're going to do instead is
- 10:50solve what's known as a a boundary value
- 10:53problem
- 10:54uh for connecting the nearest point on
- 10:56the tree
- 10:57uh
- 10:59to extend it uh to this new point XS.
- 11:02Um so, yeah. I guess here's a a sketch
- 11:04of what uh what this looks like. So,
- 11:06let's say we built our tree up to some
- 11:09uh number of iterations.
- 11:10We randomly sample some state, which I'm
- 11:12calling X rand over here.
- 11:15We find the nearest
- 11:17uh state in the existing tree, which is
- 11:20X near.
- 11:21XS is the the extension going from X
- 11:24near to X rand.
- 11:25So, in the original RRT algorithm, we
- 11:27would just connect X near and X XS uh
- 11:30with a line segment. Uh but here we want
- 11:33to actually account for the the dynamics
- 11:35of the system. Like we want to find some
- 11:37control inputs that will make the the
- 11:39system go from X near uh to XS.
- 11:44Okay.
- 11:45So, all right. I guess maybe questions
- 11:48on on that general approach. So, the the
- 11:50basic structure of the RRT algorithm is
- 11:52identical to the original version that
- 11:54we introduced. Uh the only change is
- 11:57instead of of a line segment connecting
- 12:00XS to X near,
- 12:02uh we're going to to find control inputs
- 12:05that uh such that when your system
- 12:08executes control inputs, uh your robot
- 12:11actually goes from X near to X S. Yeah,
- 12:13I guess questions on on that
- 12:15modification uh, compared to the the
- 12:17original RT algorithm.
- 12:22Okay.
- 12:23So,
- 12:25I guess that the hard part here, uh, is
- 12:27the boundary value problem. So, I
- 12:28haven't told you actually how to do
- 12:30this. Like I've just said we want to
- 12:31find some way of of uh, computing
- 12:33control inputs that go from X near to to
- 12:35X S. Uh, the question now becomes how do
- 12:37we uh, how do we find these control
- 12:40inputs?
- 12:42This problem is also known as trajectory
- 12:44optimization uh, in in this literature
- 12:47on motion planning with with dynamics
- 12:48constraints.
- 12:50Uh, and you can tackle this problem,
- 12:52this boundary value problem or
- 12:53trajectory optimization problem uh,
- 12:55using techniques from non-linear uh,
- 12:57optimization.
- 12:59Uh, maybe just a quick show of hands.
- 13:01How many people have seen some
- 13:03optimization before? Like maybe if
- 13:05you've taken uh, off 363 or something
- 13:08like that. Okay, I guess a few people.
- 13:11Yeah.
- 13:11Uh, sounds good. So, I'll give you a uh,
- 13:14just a kind of quick uh, overview of a
- 13:17specific case in which this optimization
- 13:19problem is actually quite
- 13:21computationally straightforward uh, to
- 13:24tackle. Uh, and then I'll briefly
- 13:26describe the the general version.
- 13:29Um, so the special version the special
- 13:31case is going to be
- 13:33uh, trajectory optimization with linear
- 13:35dynamics uh, and I'll I'll switch to the
- 13:37the blackboard actually for for this
- 13:39part.
- 13:47So, again just for visualization I'm
- 13:49going to draw things in 2D.
- 13:54Uh, but really the the tree is being
- 13:56built in the state space. So, for the
- 13:58planar quadrotor the state space is
- 14:00six-dimensional. For the 3D quadrotor
- 14:03the state space is is 12-dimensional.
- 14:05Let's say we're starting off
- 14:08at some start state X A.
- 14:13We want to get to some some goal state,
- 14:15XB.
- 14:17The RT algorithm, you randomly sample
- 14:21some
- 14:22state, which I'm calling X rand.
- 14:26Um you find the nearest point in the
- 14:29tree. So, initially, your tree is just
- 14:31this, the starting state.
- 14:34You connect the
- 14:35uh
- 14:36the initial state or the closest state
- 14:38uh to to the randomly randomly sampled
- 14:41state with a line segment.
- 14:43Uh and then in the original RT
- 14:45algorithm, the one which is in
- 14:46configuration space, uh which ignores
- 14:48the dynamics of the robot, you just
- 14:50extend, right? This is just a line
- 14:51segment uh going from the the closest
- 14:54point to X rand.
- 14:57So, what we're doing instead is trying
- 14:59to find some control inputs uh that will
- 15:02make the the the system that you have go
- 15:05from here to to here.
- 15:08Uh and this is XS.
- 15:11So, that's the the only change. It might
- 15:13be that the line segment is actually
- 15:14physically
- 15:16feasible, like it's executable by a
- 15:17robot, in which case this kind of curve
- 15:19will just be the line segment. Uh but
- 15:22there might be cases, as we discussed
- 15:23previously, where the system cannot
- 15:26follow a line segment. So, for the
- 15:28drone, if you want to translate
- 15:29horizontally, uh there's no way to to do
- 15:32that.
- 15:33Uh the other example we had was of a
- 15:35car.
- 15:37So, this is a top view of a
- 15:40a car, let's say.
- 15:42Um this is forwards.
- 15:44This is the initial state, XA.
- 15:51And then this is the
- 15:53the state that we want to get to. Let's
- 15:55call this XS.
- 15:59There's no way to to just horizontally
- 16:00translate your vehicle, unless it's a
- 16:03omnidirectional vehicle.
- 16:04So, you need to do something, right? You
- 16:05need to maybe go
- 16:07forwards this way
- 16:10and then back up. That could be one
- 16:12option.
- 16:13Uh or maybe you you go this way and then
- 16:15go forwards. There might be many many
- 16:17ways uh of going from here to here, but
- 16:20just translating horizontally is not a a
- 16:23feasible trajectory given the dynamics
- 16:26of the the system.
- 16:28Uh so, this this problem is the is the
- 16:30one that we want to solve. So, let's say
- 16:31we want to go from some state XA
- 16:35to some other state.
- 16:37Can we find some sequence of control
- 16:39inputs that will make the system
- 16:41actually do that? All right, so I guess
- 16:42that that's the the setup. That's what I
- 16:44mean by the boundary value problem or
- 16:47trajectory optimization. I just want to
- 16:49make sure that idea is clear before
- 16:51actually telling you how to solve it.
- 16:52Questions on that?
- 16:56All right.
- 16:56So, I mentioned that there's a a special
- 16:58case in which this trajectory
- 17:00optimization problem is actually quite
- 17:02computationally straightforward
- 17:04uh to to try to tackle.
- 17:07Uh and that's the case where we have
- 17:10linear dynamics.
- 17:21So, I'll start off with a a concrete
- 17:23example, uh and then I'll I'll tell you
- 17:25about the the kind of general case.
- 17:28So, for the planar quadrotor,
- 17:34we had written down the dynamics, I
- 17:36guess a couple of lectures ago now.
- 17:38Uh I'll just write down the dynamics
- 17:40again. So, X is the state, X dot equals
- 17:43the time derivative
- 17:47of X, Y, theta.
- 17:51Um and then VX,
- 17:54VY,
- 17:56uh and then omega.
- 18:01And by definition, VX, VY, omega, VX is
- 18:04X dot.
- 18:05Uh VY is Y dot.
- 18:07Uh and omega is theta dot.
- 18:13Uh and this was equal to
- 18:16uh so, X dot, the time derivative of X
- 18:18is VX.
- 18:20The time derivative of Y is VY.
- 18:23The time derivative of theta is omega.
- 18:27Uh and then the time derivative of VX
- 18:30is the time derivative of X dot, so it's
- 18:32X double dot. Uh and that's the part
- 18:34that comes from Newton's second law.
- 18:36So, this was negative U1
- 18:41over M sin theta.
- 18:46And then we had U1
- 18:48over M cosine theta
- 18:52minus G.
- 18:55Uh and then the last one was U2 divided
- 18:57by I.
- 19:03And the control inputs, again just a
- 19:05reminder, U1 was defined as F1 plus F2.
- 19:11So, the summation of the two thrust
- 19:13forces.
- 19:19So, F1 is the left one, left thrust. F2
- 19:23is the the right one.
- 19:25Uh and then U2
- 19:28we defined as F2
- 19:30minus F1
- 19:33multiplied by L, where L is this arm
- 19:36length.
- 19:39Uh right, so this is just from uh from a
- 19:41previous lecture, uh writing down the
- 19:43dynamics of the the planar quadrotor.
- 19:45Uh again in this first-order form. Uh
- 19:47so, these equations have the form X dot
- 19:49equals
- 19:51F, which is some function of the state
- 19:54and our control inputs. So, the it's a
- 19:55six-dimensional state over here.
- 19:59Okay.
- 20:00So, if you look at these dynamics, these
- 20:02dynamics are non-linear. Uh there are
- 20:05some trigonometric terms.
- 20:08Uh actually, let me just write write
- 20:09down that general form again. So, X dot
- 20:11equals
- 20:12some function of X U.
- 20:16Uh let's say X is
- 20:21So, X is the state.
- 20:23uh in this case it's R
- 20:26I'll call it N. N is six for the planar
- 20:28quadrotor.
- 20:30Uh and then
- 20:32the control input
- 20:34is RM.
- 20:36So, M is uh two. So, two control inputs
- 20:39for the planar quadrotor. N is six uh
- 20:42six-dimensional state space.
- 20:45Uh and yeah, I guess when I say uh that
- 20:47the dynamics are are nonlinear, uh what
- 20:49I mean is that F is a nonlinear function
- 20:52of uh the state and or the the control
- 20:55input.
- 20:57So, what we want to do is is uh
- 20:59approximate the dynamics with something
- 21:01that's linear.
- 21:03Uh and that's going to make this
- 21:04trajectory optimization problem uh much
- 21:06much uh simpler.
- 21:08Uh yeah, I guess thoughts on
- 21:10on uh on how do we do this? Um yeah, I
- 21:13guess how do we take this
- 21:15nonlinear uh function, nonlinear
- 21:17dynamics and approximate it with
- 21:19something that's linear?
- 21:21Go ahead.
- 21:23Good. Yeah, so just a a first-order
- 21:25Taylor approximation.
- 21:27Uh so, we need to find some state and
- 21:29control input uh about which we we do
- 21:32the the expansion, the Taylor expansion.
- 21:34So, some kind of nominal or reference
- 21:36state and and control input.
- 21:38Um the specific reference state and
- 21:41control input you use to linearize, like
- 21:43to do the Taylor approximation, uh
- 21:45depends on the specific system and and
- 21:47and so on.
- 21:48Uh just to make things concrete for the
- 21:50planar quadrotor,
- 21:52I'll define a nominal
- 21:56state. By nominal, I mean like some like
- 21:58reference state
- 22:00um about which we're going to do the the
- 22:02Taylor approximation. So, nominal state,
- 22:03I'll call it X0.
- 22:07Um and yeah, I guess maybe what what
- 22:09would be a reasonable
- 22:11state to do the Taylor approximation
- 22:14about for the for the planar quad?
- 22:20Depends on on the specific application,
- 22:22but but yeah, maybe um
- 22:25if you were to to just kind of for this
- 22:28lecture the actual optimization problem,
- 22:29let's say
- 22:30uh yeah, what might be a reasonable
- 22:34state to to do the Taylor approximation
- 22:36about?
- 22:40That's
- 22:43Yep, at the back here.
- 22:45Uh yeah, all zeros works.
- 22:52So
- 22:53uh this is basically saying uh so the
- 22:56state again is is this vector XY theta
- 22:58VX VY omega.
- 23:00Uh
- 23:01so these three components being zero
- 23:03means we're Taylor approximating about X
- 23:05equals zero, Y equals zero, theta equals
- 23:06zero. That's the configuration where the
- 23:08drone is just at the origin uh and has a
- 23:11horizontal orientation.
- 23:13Uh and then these are the the time
- 23:14derivatives. Uh so basically this is
- 23:16saying like the drone is just steady uh
- 23:18at at the origin
- 23:20uh and and in a horizontal
- 23:22configuration.
- 23:24Um we can also define some reference
- 23:26control input.
- 23:34So I'll call this U0.
- 23:38And then again maybe we can think about
- 23:40this. What might be a reasonable given
- 23:42that we've committed to this
- 23:44reference state
- 23:46uh what might be a reasonable control
- 23:48input
- 23:49uh
- 23:50as um
- 23:51yeah, I guess a nominal control input or
- 23:53reference control input
- 23:54to do the Taylor approximation about?
- 23:58Good, yeah. So
- 24:00uh
- 24:01basically the the control input that
- 24:02will cancel gravity, right? Uh
- 24:04So if I want to stay at this state, like
- 24:07if I'm at the if my drone is at the
- 24:08origin, has no velocities, if I want to
- 24:11stay at that state, uh all I need to do
- 24:13is cancel gravity.
- 24:15Um so I can
- 24:17um
- 24:18just figure out what that control input
- 24:19is. So I define U1 and U2 as
- 24:22up there. So U1 is the total thrust F1
- 24:24plus F2. Uh Uh is the the total moment.
- 24:28Uh so U1 just needs to be mg.
- 24:33So this is going to to cancel out
- 24:35gravity.
- 24:36Uh and then U2 I can pick to just be
- 24:38zero.
- 24:40So no difference between F2 and and F1.
- 24:43So we're just applying enough thrust to
- 24:45cancel out gravity. There's no moment,
- 24:47so the drone is just going to stay
- 24:50at the origin uh if it starts off at the
- 24:53at the origin. Question?
- 24:58Um yes, so my definition for the control
- 25:01input vector
- 25:03is like up here. So U is really
- 25:07uh U1 U2.
- 25:12Right. Um
- 25:13I guess if the the U vector was F1 F2,
- 25:17uh then what you're saying would be
- 25:18correct. Uh but just the way I've
- 25:20defined it, uh U is U1 U2. U1 is the
- 25:23total thrust. Uh U2 is the total moment.
- 25:25Yeah.
- 25:27Uh there's no fundamental reason to to
- 25:29do it uh this way. It just makes the
- 25:30equations slightly more compact. Like
- 25:33here I would have had to write F2 minus
- 25:34F1 times L. Uh so it's just slightly
- 25:36slightly more compact notation.
- 25:39Uh but yeah, that that's the only only
- 25:40reason. So total thrust cancels gravity,
- 25:43uh no net torque.
- 25:46Okay.
- 25:47So one thing to to note, I kind of
- 25:49mentioned this intuitively, like this is
- 25:51canceling out gravity. So if my drone
- 25:54starts off at this state, then it's
- 25:56going to remain there.
- 25:58Uh and we can we can see that. So
- 26:01uh if I calculate
- 26:05f of x0 u0,
- 26:15um so I just plug in x equals x0 u
- 26:18equals the u0 up there.
- 26:20Uh we can see so the first three
- 26:23components of the state are just going
- 26:24to be zero.
- 26:27Uh because vx vy omega, uh these are
- 26:30zero over here.
- 26:33Uh and then if I take theta equal zero
- 26:36then sine of theta is zero. So this
- 26:38component is going to be zero.
- 26:41Uh
- 26:42and then cosine of zero is one.
- 26:46So I have U1 divided by M minus G. U1
- 26:49we're taking to be mg.
- 26:51So it's mg
- 26:53over M minus G
- 26:56uh which is equal to zero.
- 26:58Uh and then U2 is equal to to zero.
- 27:04Right, so at the nominal
- 27:07state, if I apply the nominal control
- 27:10input, uh then I'm just going to stay
- 27:11there. Uh and this Yeah, hopefully this
- 27:13makes sense intuitively. All it's saying
- 27:15is if your drone is hovering perfectly,
- 27:17uh it has no velocities, it's kind of
- 27:19exactly at the origin, and you're
- 27:21canceling out gravity exactly, then
- 27:23nothing is going to happen. So X dot is
- 27:24just going to be equal to zero.
- 27:26Uh and that's what we have uh over here.
- 27:29All right, questions on this?
- 27:33Okay.
- 27:38All right, so how do we do the the
- 27:40Taylor approximation?
- 27:42Uh so our function is a function of two
- 27:44variables. So F is a function of X and a
- 27:46function of U.
- 27:48Uh let me just write it again. So X dot
- 27:51is a function F of the state and the
- 27:54control input.
- 27:57Uh and by Taylor's theorem, Taylor
- 27:59approximation uh theorem, we can
- 28:01approximate this to first order
- 28:04as F
- 28:06of X0 U0.
- 28:09So the function evaluated at the nominal
- 28:11state and the control input
- 28:14plus
- 28:16um
- 28:17Let me stick to the notation here. So
- 28:19partial derivatives
- 28:23with respect to X
- 28:26uh evaluated at X equals
- 28:30X0 U equals U0
- 28:35times the the state minus the reference
- 28:38state.
- 28:41And then plus
- 28:46the partials with respect to the control
- 28:48input
- 28:49again evaluated at the nominal state and
- 28:52control input.
- 28:57Uh and then u minus u 0.
- 29:02Right, so this is just uh
- 29:03the Taylor series approximation to the
- 29:05first order.
- 29:07Um yeah, any questions on this?
- 29:10Hopefully everyone has seen this.
- 29:13Okay, I don't see anyone nodding.
- 29:16Uh maybe a quick show of hands if you
- 29:18have seen it.
- 29:19Okay, most of you, good. All right.
- 29:22Uh okay, so yeah, I guess this is uh the
- 29:24the sort of general um
- 29:27expression uh Taylor approximation to to
- 29:29first order.
- 29:30Um we have to compute these matrices. So
- 29:33this this matrix over here, this is a
- 29:35matrix, this is a a matrix.
- 29:37Uh so yeah, let's let me just go ahead
- 29:39and and do that.
- 29:52All right, so let's Oh, and actually I
- 29:53should have mentioned this term over
- 29:55here, we computed up there.
- 29:57Uh this is just zero. So we need to
- 29:59calculate
- 30:00this matrix times x minus x 0 uh plus
- 30:04this matrix u minus u 0.
- 30:07Uh and I'm just going to give these
- 30:08names, so I'll call this A
- 30:11and I'll call this B.
- 30:14So A is going to be
- 30:17uh n by n matrix.
- 30:22Uh and then B is going to be
- 30:28uh n by m
- 30:30matrix to make the dimensions work out.
- 30:34So let's start by calculating A
- 30:39for the planar quadrotor.
- 30:44Um
- 30:45So, let me Maybe let me just write down
- 30:47the general expression and then we'll
- 30:49plug in some values.
- 30:51So, the the first row is going to be DF.
- 30:55Uh So, the partial of F with respect to
- 31:00uh X and actually the the first
- 31:01component of of F.
- 31:05So, the first component of F is is up
- 31:07there, so VX.
- 31:13And then partial of VX
- 31:17partial Y
- 31:19uh partial VX
- 31:22partial theta. Maybe I'll write down the
- 31:25the full first row just to be concrete.
- 31:28So, partial VX partial X
- 31:32dot, which is VX
- 31:34partial V
- 31:36um X
- 31:40partial VY
- 31:42and the last one partial VX partial
- 31:46uh omega.
- 31:49So, that's the the full first row.
- 31:52Uh and then the the second row is going
- 31:54to be the partial of the second
- 31:56component of F, which is VY up there.
- 32:02And then partial X and then same same
- 32:04thing over here, partial VY
- 32:07um
- 32:09partial Y
- 32:12I won't write the full thing, but just
- 32:13just enough terms to make sure it's
- 32:15clear.
- 32:18theta and so on.
- 32:23Right. So, basically each row over here,
- 32:25we're fixing uh the thing that we're
- 32:27taking the partial with respect to.
- 32:29Um so, in the first row, it's going to
- 32:31be the first component of F,
- 32:33which is the the first row up there,
- 32:35which is VX. In the second row, it's
- 32:37going to be all VY's. and the third row
- 32:39it's going to be all uh omegas uh and
- 32:42and so on.
- 32:43Right, that's the the full expression.
- 32:47So, if we think about this matrix, let's
- 32:49just look at the the first row.
- 32:51I guess what is that first row going to
- 32:53to be?
- 32:55Uh is it going to be all zeros? Is it
- 32:57going to be some
- 32:59non-zero things uh in each element?
- 33:04Can people see it?
- 33:11Yep, go ahead.
- 33:16Yep.
- 33:19Perfect, yeah. So, we're taking
- 33:20partials. So, the partial of V X with
- 33:22respect to X is zero. V X Yeah, there's
- 33:25no explicit dependence on on X.
- 33:27Uh same thing with Y, same thing with
- 33:29theta. The only
- 33:32non-trivial like non-zero
- 33:35element is this one. So, the partial of
- 33:36V X with respect to itself is going to
- 33:39be
- 33:40one.
- 33:41And then everything else is is zero.
- 33:44Uh and then you can see it's kind of a
- 33:45similar pattern for the next two rows.
- 33:48So, for the second row,
- 33:50everything is going to be zero uh except
- 33:52there's going to be a partial V Y uh
- 33:55and partial
- 33:57Yeah, this one over here, partial V Y V
- 34:00Y.
- 34:03That's going to be one.
- 34:05Uh and then in the third row, you're
- 34:07going to have a
- 34:08partial omega partial omega.
- 34:12And that's going to be one.
- 34:14So, the first three rows are actually
- 34:16pretty straightforward.
- 34:25Let me write it down. So, A, the first
- 34:27three rows
- 34:28So, 0 0 0
- 34:311 0 0
- 34:34and then 0 0 0 0 1 0
- 34:39and then all zeros except for the last
- 34:41one.
- 34:45All right. Questions on on that?
- 34:50Okay.
- 34:51Um yeah, I guess it turns out that
- 34:52basically all the the other elements are
- 34:55also equal to to zero except for
- 34:58for one. So,
- 35:00uh
- 35:01yeah, let me put all the zeros. This
- 35:02element over here is going to be
- 35:04non-zero.
- 35:06Uh but everything else
- 35:08yeah, if you go through
- 35:10the partials are zero.
- 35:18And yeah, maybe we can just calculate
- 35:20this one. So, this is the fourth row.
- 35:22So, we're going to take the partial
- 35:25with respect to the fourth
- 35:27element of F.
- 35:38So, partial of
- 35:40uh with respect to
- 35:42uh the fourth element of F, so that's
- 35:43negative U1
- 35:49over M sin theta.
- 35:52Uh
- 35:53and then it's the third column. So, it's
- 35:56the partial with respect to the third
- 35:57element in the state, which is theta.
- 36:02Okay, so this partial
- 36:06is negative
- 36:08uh U1
- 36:10over M
- 36:12cosine theta.
- 36:16And then we're evaluating it
- 36:18at the nominal state and the nominal
- 36:21control input.
- 36:26Uh so, the nominal state has theta
- 36:28equals zero.
- 36:30So, cosine of zero is one.
- 36:35And then
- 36:36U1
- 36:38uh this I I think I just erased it, but
- 36:41U1 was just canceling out gravity. Uh
- 36:43so, it was just mg.
- 36:44Uh so, this is mg over here.
- 36:48Uh so, this is just negative g.
- 36:54Uh so, that's that turns out to be the
- 36:56only non-zero element here. So, this is
- 36:58negative g.
- 37:02Okay. Yeah, I guess questions on on
- 37:04this.
- 37:07All right.
- 37:09Yeah, question.
- 37:11Yeah.
- 37:15Yeah, so I haven't uh
- 37:18uh sort of said it kind of
- 37:20what what I said was like we're doing
- 37:21the Taylor approximation just to get a
- 37:23first-order approximation of the
- 37:24dynamics, which is then going to help us
- 37:26solve the trajectory optimization. Uh
- 37:27but I haven't actually told you like why
- 37:29it's easy. Like I'm just that's just a
- 37:31claim. Once we Taylor approximate to
- 37:33first order, uh then I'll talk about how
- 37:35to actually solve the trajectory
- 37:36optimization problem.
- 37:38Yeah, other questions?
- 37:42Okay.
- 37:43All right, people are like super quiet,
- 37:44which makes me nervous usually. Uh
- 37:46>> [laughter]
- 37:48>> Uh yeah, I guess is it clear or or not?
- 37:51Yeah,
- 37:51I guess I see some some thumbs up. Okay.
- 37:54Uh yeah, do ask questions. I guess the
- 37:55whole point of this is to to answer
- 37:57questions if you have them.
- 37:59Okay. So, this was the A matrix. Um so,
- 38:02let me just quickly go through the B
- 38:04matrix as well.
- 38:06So, the B matrix is this one, the
- 38:07partial
- 38:09of f with respect to the control inputs.
- 38:25So, again, I won't go through all the
- 38:27the elements. Um
- 38:30but let me just write down. So, partial
- 38:32of f with respect to u1.
- 38:36And sorry, f here is the the first
- 38:38element,
- 38:40uh which is vx.
- 38:43And then partial vx with respect to U 2
- 38:49partial V
- 38:51Y with respect to U 1
- 38:57V Y
- 38:59U 2
- 39:00Uh and so on.
- 39:06Uh yeah, so it's going to be a a 6 by 2.
- 39:09So, N by
- 39:10M
- 39:13N is the number of states and M is the
- 39:14number of control inputs. So, 6 by 2 for
- 39:16the planar quadrotor.
- 39:20Uh and again, most of the the elements
- 39:22turn out to be
- 39:24zero.
- 39:25Like if you look at this one for
- 39:27instance,
- 39:29uh there's no explicit dependence of
- 39:32U 1 uh or of V X on on U 1. This is
- 39:36going to be zero. This is going to be
- 39:37zero. So, yeah, all basically turns out
- 39:39to be zero
- 39:40except for two elements.
- 39:43Zero, zero. I think the first four rows
- 39:46are all zero.
- 39:52Uh
- 39:53and then one of the the elements is this
- 39:56one that's not zero. And then this is
- 39:57zero.
- 39:59This is zero. And then this one is not
- 40:01zero.
- 40:06Okay.
- 40:10All right. So, let's calculate one of
- 40:12them.
- 40:25Uh and yeah, maybe let's do let's do
- 40:27this one over here.
- 40:31Uh this element right here. So, it's the
- 40:33fifth row and then the first column.
- 40:37Um and yeah, maybe let's do this as an
- 40:40exercise. Uh
- 40:41yeah, maybe let's come back and and
- 40:43discuss. Uh yeah, I guess anyone want to
- 40:45just volunteer to to to
- 40:47your work.
- 40:50Go ahead. Yeah.
- 40:58Yeah.
- 41:04Okay, maybe just let's write down what
- 41:06the partials are. So, it's the partial
- 41:08of something with respect to something.
- 41:13Uh V Y
- 41:15Uh
- 41:16is that right? So,
- 41:18let's see.
- 41:19Uh
- 41:20It's not quite V Y.
- 41:22Uh so, V Y is the fifth component of the
- 41:24state, right? Uh
- 41:26So, it's like the derivative of V Y.
- 41:30Yeah, which is this this thing over
- 41:31here.
- 41:32Um
- 41:34So, yeah, the derivative of V Y
- 41:39to U 1. Yeah, okay, good. So, the
- 41:40derivative of V Y, which is just the
- 41:42fifth component of this right-hand side,
- 41:45is U 1.
- 41:52Good. Yeah.
- 41:56Yep.
- 41:57Yeah.
- 42:00Yeah.
- 42:07Yeah, good. So, cosine theta
- 42:11divided by M.
- 42:21Yep.
- 42:23Good. Yeah.
- 42:25Yeah, perfect. Okay.
- 42:27Good. Yeah, so this was this was one of
- 42:28the non-zero ones. It's 1 over M.
- 42:33Over here. Uh and then yeah, I don't
- 42:35know if someone worked out the other one
- 42:36as well.
- 42:38Uh does someone else want to give a
- 42:40shot?
- 42:41Yeah, go ahead at the front.
- 42:46Yeah, so partial So, it's the sixth
- 42:49Yeah, U 2 over I.
- 42:53with respect to U2.
- 42:59Yep, good. So, just one over I.
- 43:03All right, perfect. So, yeah, this is
- 43:04the the other
- 43:07non-zero term. Everything else you can
- 43:09check is is just equal to to zero.
- 43:11Uh all right. So, we've done what we set
- 43:14out to to do.
- 43:15Uh so, we wanted to approximate our
- 43:17dynamics uh using
- 43:20a linear approximation. So, just a
- 43:22first-order Taylor approximation.
- 43:36Uh so, our linearized dynamics
- 43:42This is not going to be a perfect
- 43:44approximation, but kind of good enough
- 43:45if you're close to the the nominal
- 43:47state, close to the nominal control
- 43:48input.
- 43:50The linear linearized dynamics
- 43:55are X dot
- 43:58equals this A matrix that we calculated
- 44:02X minus X0
- 44:05uh plus B
- 44:07U minus U0.
- 44:17Okay. So, I guess as we saw, uh it's a
- 44:20little bit tedious to do this by hand.
- 44:21Like, it's good to understand the
- 44:22process. Like, it's good to know that
- 44:24it's just a Taylor approximation. It's
- 44:26good to you kind of go through it once
- 44:27or twice by hand and just see exactly
- 44:29how it works. Uh in the next assignment
- 44:31that goes out tomorrow, uh you'll see
- 44:33how we can do this in Python. So, it's
- 44:35uh yeah, just a few lines of Python code
- 44:37uh that that does the first-order Taylor
- 44:39approximation.
- 44:40Um and especially for more complicated
- 44:43systems, like for the full 3D quadrotor,
- 44:46uh we don't want to compute partial
- 44:47derivatives by hand, like plug in values
- 44:49and so on. Uh it's We can do it, but
- 44:51it's just super tedious.
- 44:52Uh so, you'll see some Python code that
- 44:54uh that does that for you and that's
- 44:56quite convenient.
- 44:57But okay, I guess going back to to the
- 45:00question that someone asked, like what
- 45:01is the point of this? Why are we
- 45:03approximating our nice dynamics for the
- 45:06planar quadrotor with these like linear
- 45:10dynamics approximations?
- 45:12So, I promised that the trajectory
- 45:13optimization problem
- 45:15for
- 45:17a system that has linear dynamics is
- 45:18computationally efficient.
- 45:21So, I want to just go through that.
- 45:24So, I want to write down some
- 45:27So, the trajectory optimization problem
- 45:34assuming linear dynamics.
- 45:41So, again the problem set up for
- 45:43trajectory optimization is we're given
- 45:44some starting state.
- 45:47We're given some end state.
- 45:50I'll call it X, let's say XA, XB.
- 45:56And we want to find some control inputs
- 45:58that will take the the drone or whatever
- 46:00system you have from the starting state
- 46:03to this goal state XB. So, that's the
- 46:05the problem.
- 46:07So, the way we're going to formulate
- 46:09this trajectory optimization problem is
- 46:11as a
- 46:14as a search problem or an optimization
- 46:16problem. So, we want to find
- 46:18um
- 46:21Yeah, let's let's say
- 46:23Actually, I guess sorry, just one more
- 46:25thing before that.
- 46:26So, it's going to be helpful to
- 46:29just do one more approximation here,
- 46:30which is this is a continuous time
- 46:33differential equation. We're going to to
- 46:35discretize time
- 46:37and that's going to make the the problem
- 46:39a bit easier to to solve.
- 46:41So, X
- 46:44Let's say T plus delta T.
- 46:49So, the state at some time T
- 46:52plus some small
- 46:54delta T, some small time delta T
- 46:56is approximately going to be equal to
- 46:59from this equation
- 47:00the the A matrix
- 47:04X at time T minus X zero
- 47:09uh plus B
- 47:14uh
- 47:15at time T
- 47:18minus U zero
- 47:20uh and then this thing
- 47:22multiplied by delta T.
- 47:28Plus the state
- 47:33at time T. So, this is our Euler
- 47:34discretization.
- 47:45We're taking this continuous time
- 47:46differential equation and turning it
- 47:48into a difference equation
- 47:50uh just by Euler integrating. So, the
- 47:53state at some T plus delta T
- 47:55uh is the state at T
- 47:57plus the time derivative X dot, which is
- 48:00this thing, uh multiplied by by delta T.
- 48:03Right? So, just Euler integration.
- 48:05Um so, yeah, I guess with this
- 48:07discretized version of the problem
- 48:09we can state our trajectory optimization
- 48:11problem
- 48:13uh as trying to find
- 48:16states
- 48:18and control inputs at different times
- 48:22where T goes from let's say zero
- 48:27delta T
- 48:29two delta T
- 48:31uh up to some capital T, which is our
- 48:34time horizon. So, let's say I I specify
- 48:375 seconds or 10 seconds, like the amount
- 48:39of time
- 48:40uh the maximum amount of time I'm
- 48:42willing to wait
- 48:43uh for my system to go from
- 48:45XA to XB. Uh that's what this capital T
- 48:48is.
- 48:50So, we want to find these variables,
- 48:52states and control inputs.
- 48:54Um
- 48:55we want to also have some
- 48:59objective, like something we were we're
- 49:00trying to to optimize.
- 49:02So, let's say we want to minimize
- 49:11uh
- 49:11the control effort.
- 49:14So, the total amount of
- 49:17control inputs that I need to apply. So,
- 49:18going from T zero to capital T.
- 49:24The control input at time T
- 49:27uh the magnitude squared.
- 49:30Like this is saying like be as lazy as
- 49:31possible. Uh like apply as little
- 49:33control input uh as possible.
- 49:36Uh and then we need we have some
- 49:37constraints.
- 49:44Uh things that XT and UT need to
- 49:47satisfy.
- 49:49So, because this is a a boundary value
- 49:50problem,
- 49:52uh the state
- 49:56at time zero should be XA.
- 50:01Uh the state at let's say capital T
- 50:05should be XB.
- 50:09This is saying the Yeah, the state
- 50:11starts off where you want it to start
- 50:12off. The state ends up where you want it
- 50:14to to end up.
- 50:16And we also have
- 50:19uh the dynamics. So, your states and
- 50:21control inputs need to satisfy
- 50:24these like linear approximated dynamics
- 50:26that we have. So, X
- 50:29uh
- 50:31T plus delta T
- 50:35is equal to
- 50:37X
- 50:38at time T
- 50:40plus A
- 50:45XT minus X0
- 50:47plus B
- 50:50uh
- 50:53UT minus U0.
- 50:58See
- 50:59the parentheses right here.
- 51:01Uh delta T
- 51:04Uh and this is for T going from
- 51:07zero to capital T for all time.
- 51:12Uh and then we might have some obstacle
- 51:14constraints. So, I'll just write this as
- 51:16some matrix C
- 51:19times X
- 51:22T is less than or equal to
- 51:26D.
- 51:27Uh I guess this should be explicit here.
- 51:28So, C is some
- 51:31matrix. Maybe I'll write it over here.
- 51:38Uh so, C let's say is
- 51:43Um yeah, I guess what should it be? So,
- 51:45it's
- 51:46K by N, let's say. So,
- 51:50and then D is
- 51:54K by 1.
- 51:59Okay, let me just pause for a for a
- 52:01minute and just explain what what's
- 52:02going on over here.
- 52:04Uh so, we're we're kind of formulating
- 52:06this optimization problem. So, we're
- 52:07trying to find states and control
- 52:09inputs.
- 52:11Um the objective, the thing we're trying
- 52:13to minimize, is just control effort.
- 52:15Like just be as lazy as possible, apply
- 52:17as few as little control input as
- 52:19possible.
- 52:21Uh and then these are the the
- 52:22constraints. So, the first two
- 52:23constraints are just saying start off at
- 52:25the start state that we want, XA.
- 52:28End up at the end state that we want,
- 52:29which is XB.
- 52:31Uh along the way, satisfy the dynamics
- 52:35um of your system, these linear
- 52:38approximated dynamics.
- 52:41Uh and this last constraint is saying uh
- 52:43is just a a kind of boundedness
- 52:45constraint on the state. So, it's saying
- 52:47like keep the state uh within some
- 52:49region that's specified by these this
- 52:51linear inequality.
- 52:54Um
- 52:55Okay, so I guess why is this Maybe
- 52:57before describing why this is special, I
- 53:00just want to make sure that this
- 53:01formulation is clear. Like what are we
- 53:02trying to find?
- 53:03Uh what does this mean? Like what are
- 53:05the constraints? What what are the uh
- 53:07the objective? Yeah, questions on the
- 53:09formulation itself?
- 53:13Yeah, question.
- 53:16Yeah, so the last constraint is
- 53:20saying that the state needs to be in
- 53:23some region
- 53:25for all time.
- 53:29Uh so this these this is like a set of
- 53:31linear constraints.
- 53:32>> constraints
- 53:33>> Uh so each row over here is going to
- 53:37basically say like
- 53:39your state needs to be
- 53:41on this side of some hyperplane.
- 53:45Uh and then
- 53:46yeah, another
- 53:48constraint says your state needs to be
- 53:50over here. Maybe you have another
- 53:52constraint over here
- 53:53that says the state needs to be uh on
- 53:56this side. Uh this is just like bounding
- 53:58the the state.
- 54:00Uh
- 54:00and yeah, one way to think about it is
- 54:02like imagine that you had an obstacle
- 54:03here.
- 54:05You had some obstacle over here. You had
- 54:06some obstacle over here.
- 54:08Uh you're just approximating the region
- 54:11that's collision-free uh with a
- 54:12polytope, so a sequence of um linear
- 54:15constraints.
- 54:16Uh and just saying that the the state
- 54:18needs to be in this free space defined
- 54:20by a polytope for for all time.
- 54:24So this is not a kind of fully general
- 54:26formulation. Uh like if I had some
- 54:29obstacles
- 54:31like maybe over here and and over here
- 54:34uh and my state needed to do something
- 54:36like this. I'll I'll show a a video in
- 54:37just a minute.
- 54:39Um then maybe there's no kind of clean
- 54:41way of of capturing the free space
- 54:44uh with a a set of inequalities, um but
- 54:48this is just a set of constraints that
- 54:50we can add. Like if you can approximate
- 54:52the free space
- 54:53uh the collision-free space uh with with
- 54:55these kind of inequalities
- 54:57uh then we can just throw that into the
- 54:59the problem. Yeah, I guess does that
- 55:00make sense? Okay.
- 55:01Yeah, other questions on the
- 55:02formulation?
- 55:06Okay. So the the key kind of uh
- 55:08observation over here for for this
- 55:10optimization problem
- 55:12uh is one that the objective, the thing
- 55:16we're trying to minimize,
- 55:18is convex and quadratic. So, it's a
- 55:20quadratic function of the control input
- 55:22and the state.
- 55:24Um so, convex means it sort of looks
- 55:26like a a bowl.
- 55:27Uh and then the constraints are all
- 55:29linear in the state and the control
- 55:32input. So, there are linear constraints.
- 55:34Like each each constraint over here
- 55:36uh just has the state and control input
- 55:39appearing linearly. Like there are no
- 55:41nonlinearities. If you maybe if you just
- 55:43started it and then kind of convince
- 55:44yourself.
- 55:45Um and yeah, this kind of optimization
- 55:48problem, so it's called a convex
- 55:52QP, quadratic program.
- 56:01Uh is something that there are extremely
- 56:03extremely efficient uh computational
- 56:05methods for solving.
- 56:07Uh you can solve uh
- 56:08these kinds of problems with like
- 56:10thousands of of variables like very very
- 56:12easily, like milliseconds uh
- 56:14computational times. I won't go into the
- 56:15the methods
- 56:16for how to solve this. Uh again, if
- 56:17you're interested in this kind of thing,
- 56:19uh we have entire courses like our 363
- 56:22uh devoted to this.
- 56:23Uh but the main point I want to make is
- 56:24just this observation that one, this
- 56:27captures the trajectory optimization
- 56:29problem for the linear systems.
- 56:31Uh
- 56:32two, just the meaning of all this stuff.
- 56:35Right? Like what what is it What are we
- 56:37What is it that we're trying to find?
- 56:38What are we trying to minimize? What are
- 56:40the constraints that these variables
- 56:41need to to satisfy?
- 56:43Uh and then yeah, I guess the last thing
- 56:44is just the claim that you can solve
- 56:45these extremely efficiently. Like for
- 56:47the planar quadrotor, it might even be
- 56:49microseconds uh if you're um have a fast
- 56:52implementation. Question?
- 56:54>> I still don't understand
- 56:56the expression
- 56:57>> Say that again. Still don't understand
- 56:58what?
- 56:59>> I still don't understand the expression
- 57:00that
- 57:03>> Oh yeah. So, this expression over here,
- 57:07uh Uh, this is the summation over time
- 57:11uh, of the control inputs that your
- 57:13system is applying squared.
- 57:15Um, so if we try to minimize this, like
- 57:17basically it's saying
- 57:19uh, for the planar quadrotor
- 57:22at each time compute the total thrust
- 57:25and the total torque.
- 57:27Uh, just uh, uh, square them and and sum
- 57:30them up uh, and then add over time and
- 57:32just minimize that. So just basically
- 57:33minimize the total thrust and torque
- 57:36that the drone is applying.
- 57:38Uh, so yeah, it's just like as kind of
- 57:40efficient or lazy as possible.
- 57:46Subject to to these constraints. Yeah,
- 57:48does that make sense? Okay, good.
- 57:50All right, so I guess first just a a
- 57:51couple of uh, visualizations uh, just to
- 57:55um, just to connect back to uh, to what
- 57:57I uh, claimed on the on the on the
- 57:59board.
- 58:00Uh, so I mentioned this is a a quadratic
- 58:02program and you can um, visualize what
- 58:04what these things look like. For
- 58:06visualization purposes, I'm going to
- 58:07draw pictures in 2D, but you can imagine
- 58:09that uh, this is really in a
- 58:10high-dimensional space uh, that these
- 58:12functions and constraints are are
- 58:13living.
- 58:15So without any constraints, if I'm just
- 58:17trying to minimize some quadratic
- 58:19function of some decision variables like
- 58:21X1 and X2, like let's say I have some
- 58:23quadratic function of of X1 X2
- 58:25uh, I can visualize this using level
- 58:28sets. So each uh, kind of oval here,
- 58:30ellipsoid or ellipse
- 58:32uh, is one of the the level sets of the
- 58:34uh, the function.
- 58:36Uh, and if I'm trying to minimize this
- 58:37function
- 58:38without any constraints, then for the
- 58:40specific function that I've drawn, uh,
- 58:42it's kind of at that point uh, 4,3,
- 58:44let's say.
- 58:46Uh,
- 58:47so this kind of problem is like almost
- 58:48trivial to solve. Like you can just do
- 58:50gradient descent, like just uh, randomly
- 58:52initialize X1 X2 uh, compute the
- 58:55gradient, the negative of the gradient,
- 58:56take a little step uh, and keep going
- 58:58until convergence.
- 59:00Uh, it gets much more interesting uh,
- 59:02when you start adding constraints.
- 59:04So now suppose I say that
- 59:07I have two constraints. So X1 and X2
- 59:10must satisfy this linear constraint,
- 59:13which is written up there. So, 2 x 2 - x
- 59:151 is less than or equal to 4.
- 59:18Uh that's saying that your x 1 x 2 needs
- 59:20to be on this side of this line over
- 59:22here.
- 59:24Uh and then I have another constraint, x
- 59:251 + x 2 is less than or equal to 4. So,
- 59:28I have this line over here. Uh and this
- 59:30constraint is saying that x 1 and x 2
- 59:32must satisfy
- 59:34the constraint and that you're on on
- 59:35this side.
- 59:37Uh and both of these must be satisfied.
- 59:39Uh which means that your x 1 and x 2
- 59:41must lie in this green region, shaded
- 59:44region over here.
- 59:46Um so, yeah, I guess this is sort of a
- 59:48visualization of what a convex quadratic
- 59:50program looks like. We're trying to
- 59:52minimize some quadratic function
- 59:55uh
- 59:55of some decision variables, like things
- 59:57that we're trying to find.
- 59:59Uh and we have these constraints
- 1:00:01uh which are linear. Uh and subject to
- 1:00:04these constraints, like in this kind of
- 1:00:06shaded region, I will minimize my
- 1:00:08function.
- 1:00:09Um and yeah, I guess my my claim, uh if
- 1:00:12you haven't seen some convex
- 1:00:13optimization before, is that these kinds
- 1:00:15of problems are are extremely extremely
- 1:00:16efficient to solve. Uh in the notes, I I
- 1:00:19pointed to a a couple of software
- 1:00:20packages, uh things like Mosek, Gurobi,
- 1:00:23CPLEX. There's a whole bunch of them.
- 1:00:25You can just kind of write simple uh
- 1:00:27Python code uh to to solve these
- 1:00:29optimization problems.
- 1:00:31Um
- 1:00:32So, I guess that's the the story for
- 1:00:34linear systems. If you have a linear
- 1:00:36system,
- 1:00:37uh if the thing that you're trying to
- 1:00:39minimize, the control effort, is
- 1:00:41quadratic, uh and if your constraints
- 1:00:43are all linear, then it's super super
- 1:00:45efficient.
- 1:00:47Uh
- 1:00:47but of course, our systems are never
- 1:00:50kind of exactly linear. Our constraints
- 1:00:52are never quite linear, either. Um
- 1:00:55So, we need some way of of handling the
- 1:00:56the general uh problem as well. So, how
- 1:00:58do we solve these trajectory
- 1:01:00optimization problems uh when your
- 1:01:01system is is non-linear?
- 1:01:03Uh I won't go into the the details of
- 1:01:05this. I just want to kind of sketch out
- 1:01:07uh what the the approach uh looks like.
- 1:01:10Uh and have a a visualization uh over
- 1:01:12here. So, this is white coded with with
- 1:01:14Claude. Uh but hopefully gives you a
- 1:01:16clear picture of uh of the way the the
- 1:01:18algorithm works.
- 1:01:20Uh it's the same setup as before, so we
- 1:01:22have some start state XA. Uh we have
- 1:01:25some goal state XB.
- 1:01:28Uh and we want to avoid these obstacles.
- 1:01:30So, we want to find some control inputs
- 1:01:32that that avoid the obstacles.
- 1:01:34Uh basically, the way
- 1:01:36these kinds of problems are solved is
- 1:01:39like iterative approximation with
- 1:01:41quadratic programs.
- 1:01:43Uh initially, in the the very first
- 1:01:44iteration,
- 1:01:46you just guess some solution.
- 1:01:48So, we'll go back to the the start. So,
- 1:01:49you just guess like a line. Like this
- 1:01:51violates the constraints. Like it goes
- 1:01:53through the obstacles.
- 1:01:54Uh but you can come up with some linear
- 1:01:56approximation of the dynamics along that
- 1:01:58line.
- 1:01:59Uh
- 1:02:00so, now you have
- 1:02:01at least the dynamics part is is linear.
- 1:02:04Uh you can approximate the
- 1:02:06obstacle constraints as being linear as
- 1:02:09well.
- 1:02:10Uh or you can just relax them. Like
- 1:02:12initially, like kind of just don't
- 1:02:13bother too much about imposing the the
- 1:02:15obstacle constraints.
- 1:02:16Uh you find some trajectory,
- 1:02:18uh and then you crank up the penalty for
- 1:02:21violating the constraints from the
- 1:02:23obstacles. Uh and then you
- 1:02:25re-approximate the dynamics about the
- 1:02:28the latest trajectory that you found.
- 1:02:30Uh solve the problem as a quadratic
- 1:02:32program, kind of keep going, uh and uh
- 1:02:35and hopefully, you'll converge to to
- 1:02:36something that's feasible, like
- 1:02:38something that doesn't collide.
- 1:02:39Question?
- 1:02:40>> Is there a heuristic in there
- 1:02:41where you know how to do the
- 1:02:42down the short path or something like
- 1:02:44that, or is it really just based on the
- 1:02:45control
- 1:02:46like minimizing the control
- 1:02:47>> Yeah, so this particular one is is just
- 1:02:49control input, uh but you can throw in
- 1:02:52other objectives as well. Like minimum
- 1:02:53path length is a reasonable one. Uh
- 1:02:55minimum time is a is another reasonable
- 1:02:57one.
- 1:02:58Uh yeah, it kind of depends on on
- 1:03:00exactly what you care about.
- 1:03:02If you do minimum time, uh what you end
- 1:03:04up with is what's known as bang-bang
- 1:03:06control. Like this is the the technical
- 1:03:07term for it. Like where you just like
- 1:03:10max out the control input, stay there,
- 1:03:12uh and then kind of go to the other
- 1:03:14extreme. Uh Uh, and usually, this is not
- 1:03:17uh, extremely friendly when you're
- 1:03:19implementing stuff on a physical system
- 1:03:21like just maxing the the kind of control
- 1:03:23inputs back and forth.
- 1:03:25Um, so in practice you might have some
- 1:03:27minimal time penalty, maybe some control
- 1:03:31effort penalty, maybe some path length
- 1:03:32penalty, and you throw all of those
- 1:03:34together.
- 1:03:35Uh, that's your objective, and then you
- 1:03:36have constraints in the form of
- 1:03:37obstacles. Yeah.
- 1:03:40Cool. All right. So again, just, uh, to
- 1:03:42iterate, the part that I went through
- 1:03:44carefully is the linear part. If your
- 1:03:46dynamics are linear, if your constraints
- 1:03:48are linear,
- 1:03:49uh, then you can solve these problems
- 1:03:51extremely efficiently,
- 1:03:53um, and pretty much exactly
- 1:03:55up to like very small numerical errors.
- 1:03:58Uh, but if your obstacle constraints are
- 1:04:00not linear, if your dynamics are not
- 1:04:01linear, then you iteratively
- 1:04:03approximate, uh, using quadratic
- 1:04:05programs.
- 1:04:06Uh, this is called sequential quadratic
- 1:04:08programming.
- 1:04:09Uh, there's no guarantee that you're
- 1:04:10going to find some collision-free path.
- 1:04:13Uh, and especially as the number of
- 1:04:15obstacles gets larger,
- 1:04:17uh, as the geometry of the environment
- 1:04:19gets more complicated, um, the
- 1:04:21likelihood that you're going to find
- 1:04:23some solution with sequential quadratic
- 1:04:25programming becomes,
- 1:04:27uh, lower.
- 1:04:28Uh, but yeah, I guess this is why we
- 1:04:30combine it with the RRT algorithm.
- 1:04:32Um, so if you do this trajectory
- 1:04:34optimization just for the extension
- 1:04:37operation in the RRT,
- 1:04:39uh, usually that extension is over a a
- 1:04:40short time duration,
- 1:04:42uh, for which we can solve these
- 1:04:44trajectory optimization problems pretty
- 1:04:45efficiently.
- 1:04:47Um, and yeah, I guess that that's the
- 1:04:49the kind of fully general approach. Like
- 1:04:51build your RRT, every time you extend
- 1:04:53the tree, solve one of these little
- 1:04:55optimization problems, uh, and then at
- 1:04:56the end, uh, hopefully you get some, uh,
- 1:04:59path that's dynamically feasible for
- 1:05:01your system, uh, that goes from, uh, A
- 1:05:03to B.
- 1:05:05Okay.
- 1:05:06I'll show some examples, but yeah, I
- 1:05:08guess any questions on the,
- 1:05:10the math or formulation.
- 1:05:15Okay.
- 1:05:16All right. So this is going to be a
- 1:05:17super biased, uh,
- 1:05:19set of examples. These are all from my
- 1:05:20own work.
- 1:05:23Uh but yeah, hopefully it gives you a
- 1:05:24clear picture.
- 1:05:27Let me
- 1:05:32Let me just describe the the system over
- 1:05:34here. Uh this is what's known as a
- 1:05:36acrobot. Uh this is a a system that I
- 1:05:39worked quite a lot with during my my
- 1:05:40PhD.
- 1:05:41Uh it's a double pendulum, so a classic
- 1:05:43kind of example of a chaotic system. So,
- 1:05:45two degrees of freedom, one at the
- 1:05:47shoulder, one at the elbow.
- 1:05:49Uh but the important thing here is that
- 1:05:51it's under actuated. So, there's only
- 1:05:53one motor uh that's controlling the
- 1:05:56elbow joint. So, there's no motor at the
- 1:05:58the shoulder joint, just a motor at the
- 1:06:00the elbow joint.
- 1:06:01Uh it's sort of meant to
- 1:06:03model an acrobat, so a human acrobat
- 1:06:06like hanging from a bar. Uh you don't
- 1:06:08have much torque at the wrist, uh but
- 1:06:11you have a lot of torque at the hip. Uh
- 1:06:12so, that that's kind of what what this
- 1:06:13system is.
- 1:06:14Uh it's also a very simple model for a
- 1:06:17walking robot. Uh so, if you imagine
- 1:06:19it's also Yeah, called the compass gait
- 1:06:21walker. So, like a drawing compass, uh
- 1:06:23one end is like fixed to the ground, uh
- 1:06:25the other end is the the swing leg.
- 1:06:28Um so, you don't have any torque at the
- 1:06:30ground. You have a little bit of torque
- 1:06:32from your ankle, but not that much. But,
- 1:06:33you have a lot of torque at the hip. So,
- 1:06:35that's what uh this system is supposed
- 1:06:36to model.
- 1:06:38Uh and the goal here is to start from
- 1:06:40the bottom state, so the pendulum kind
- 1:06:43of hanging downwards, and you want to
- 1:06:44find some control inputs that'll make it
- 1:06:46go all the way to the top and then
- 1:06:48balance at the at the top. Uh so, this
- 1:06:50was This trajectory was found using
- 1:06:52sequential quadratic programming,
- 1:06:55uh and this is what it looks like.
- 1:07:07Yeah, you can see it doesn't quite
- 1:07:09stabilize itself at the top. Like,
- 1:07:11there's a bunch of friction, so it it
- 1:07:12keeps going back and forth, back and
- 1:07:14forth. Uh I'll say more about uh that
- 1:07:16those errors uh a a bit later, but here
- 1:07:19I I want to just focus on the planning
- 1:07:20part. So, the planning problem, there's
- 1:07:22no obstacles, like just go from uh
- 1:07:24initial state, which is downright, to
- 1:07:27the final state, which is upright, while
- 1:07:29obeying the dynamics of the system.
- 1:07:32Uh here's another, maybe more exciting,
- 1:07:34example.
- 1:07:36Uh this is for a airplane, a fixed-wing
- 1:07:38airplane.
- 1:07:40It gets shot off a launcher.
- 1:07:42Uh and then it needs to avoid these
- 1:07:44obstacles, which are less than a
- 1:07:46wingspan away from each other. So, it
- 1:07:48needs to do this like knife edge
- 1:07:50maneuver uh goes through the obstacles.
- 1:07:53Uh and then the room was very small, so
- 1:07:55it just crashes into a net
- 1:07:57at the end.
- 1:08:03Uh so, here the the problem is more
- 1:08:05interesting. Uh obviously, there's
- 1:08:06non-trivial dynamics. So, the first step
- 1:08:08here was just to model the dynamics of
- 1:08:10the system, like the aerodynamics,
- 1:08:12and so on.
- 1:08:13Uh and then there's obstacles as well.
- 1:08:15So, you need to find some trajectory
- 1:08:17that obeys the dynamics of the system
- 1:08:19and avoids the the
- 1:08:21uh PVC pipes.
- 1:08:24Uh and again, we're using the the same
- 1:08:26methods that I talked about today. So,
- 1:08:28sequential quadratic programming uh to
- 1:08:30to solve for that trajectory.
- 1:08:34Um and then yeah, maybe final uh video
- 1:08:36over here. Uh
- 1:08:41Let me Yeah, let me just play it uh play
- 1:08:43it back. So, I guess what video is going
- 1:08:45to What this video is going to show is
- 1:08:46like real-time planning.
- 1:08:48Um so, if you don't have the ability to
- 1:08:50solve trajectory optimization problems
- 1:08:53uh at run time. So, if your robot sees
- 1:08:56some obstacles, ideally, you'd want it
- 1:08:57to just plan some trajectory.
- 1:08:59Uh but if it's going really fast, you
- 1:09:00might just not have enough time to to
- 1:09:02plan in real time. Uh so, how do you
- 1:09:04solve that problem?
- 1:09:06Uh let me just play the clip, and then
- 1:09:07I'll I'll explain it.
- 1:09:11Yeah, I guess that was me in my PhD
- 1:09:13days.
- 1:09:37>> So yeah, we compute these funnels that
- 1:09:39the plane is is uh
- 1:09:42guaranteed to stay within.
- 1:09:57Yeah, and the basic idea is like you
- 1:09:58have a a whole family of these funnels
- 1:10:01like corresponding to different
- 1:10:02trajectories and control inputs
- 1:10:04precomputed offline. So before the the
- 1:10:06drone starts flying, uh you just compute
- 1:10:08all of these trajectories, these funnels
- 1:10:10that are associated with them.
- 1:10:12Uh and then at runtime, all you need to
- 1:10:13do is collision checking. Like you just
- 1:10:15search through this kind of library of
- 1:10:17funnels uh and then find something that
- 1:10:19doesn't collide with the obstacles.
- 1:10:41Yeah, I guess last one I was bored one
- 1:10:42day, so I put uh MIT with PVC pipes.
- 1:10:54All right. So yeah, I guess all the all
- 1:10:56the videos I I showed uh the
- 1:10:58trajectories are computed using
- 1:11:00sequential quadratic programming, these
- 1:11:01like trajectory optimization techniques.
- 1:11:03Um what I didn't talk about is the
- 1:11:06control part. So when you actually try
- 1:11:08to execute one of these trajectories on
- 1:11:10your real system, you're not going to
- 1:11:12follow it exactly, right? Your dynamics
- 1:11:14are not going to be perfect. Uh maybe
- 1:11:16there's unmodeled aerodynamics, maybe
- 1:11:18there's a wind gust or something that
- 1:11:20blows you off the trajectory that you
- 1:11:21planned. Uh so the thing that we're
- 1:11:23going to start talking about from the
- 1:11:24next lecture is how do we make those
- 1:11:27corrections? If you're following some
- 1:11:29trajectory uh but there's a disturbance
- 1:11:31or there's some imperfection, how do you
- 1:11:33apply some control inputs that kind of
- 1:11:35take you back? So, that's going to be
- 1:11:36the the next topic. All right, I guess
- 1:11:38any final questions?
- 1:11:41All right, I'll see you next time.
- 1:11:47>> [music]
About this transcript
This page contains the full transcript of Princeton Intro to Robotics (Fall 2026) | Lecture 6: Trajectory Optimization by Introduction to Robotics @ Princeton, generated from the public captions YouTube serves with the video. The transcript has 10,277 words across 1,792 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.