trajopt | Trajectory Optimization
kandi X-RAY | trajopt Summary
kandi X-RAY | trajopt Summary
Trajectory Optimization
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of trajopt
trajopt Key Features
trajopt Examples and Code Snippets
Community Discussions
Trending Discussions on trajopt
QUESTION
I'm trying to implement direct collocation from scratch in a MathematicalProgram such that each constraint is a Python function, meaning that I can get the gradient of each constraint and cost with respect to their inputs. My goal is to use these gradients for a downstream task.
I'm converting the "Direct Collocation for the Pendulum" part of this notebook: https://github.com/RussTedrake/underactuated/blob/master/trajopt.ipynb to a MathematicalProgram. I've been able to convert the cost and constraints to lambdas instead of Formulas. For instance:
...ANSWER
Answered 2022-Feb-13 at 15:49It should definitely be possible to implement the DirectCollocation constraint in python. This notebook has a bunch of relevant examples of using python functions as constraints; it could help. But it should be a fairly straightforward port of the DirectCollocationConstraint::Eval you've found in C++.
But you can also always get the gradients from the constraints that are being added by DirectCollocation
. That class is just a helper class that makes it easier to set up the MathematicalProgram
for you. You can still get that program back out and evaluate any of the constraints individually if you like. I'm not convinced you get anything by reimplementing it yourself, and will certainly have worse performance in python.
QUESTION
Consider an existing Drake System
(for example MultibodyPlant
). Is there a way to wrap that System
inside a Diagram
in such a way as to convert some of the states of the internal System
to be inputs instead, i.e. set directly from input ports of the outer Diagram
?
The motivation would be essentially to make a change in modeling decisions. For example, a quadrotor is sometimes considered to have its angular rates and collective thrust as inputs, instead of the collective thrust and body moments (or similarly, individual rotor commands).
In a more complex system, perhaps I might assume I have instantaneous control over certain velocities (e.g. internal, fully-actuated joints with fast dynamics), but still want to model the entire multibody system's dynamics accounting for the current choice of velocity in terms of Coriolis terms etc.
What I'm getting at is actually very similar to the modeling choice for the elevator in the Flat-Plate Glider Model - but I'd like to avoid manually implementing a LeafSystem because my system has nontrivial multibody dynamics.
My sense is that this may not be possible since I don't know of any way for a Diagram
to interfere with the internal dynamics of a System
, so "deleting" a state and promoting it to an input seems impossible. But I thought there might be some clever method to do this.
Thanks in advance!
...ANSWER
Answered 2021-Aug-22 at 10:53I agree with your analysis. The simplest answer is "no" -- systems that declare state cannot be post-hoc exploded to have that state come from an input port. But for the specific examples that you mention, there are a few possibilities / related ideas.
The first is the notion of a prescribed motion constraint -- e.g. that one can set the positions/velocities of joints in a MultibodyPlant
directly. We don't implement that yet, unfortunately, but it is a reasonable request that we've discussed occasionally
(here is one example: https://github.com/RobotLocomotion/drake/issues/14694).
As you say, you could implement a PD controller just outside of the system to achieve the desired effect. The only real difference between this and the way that we would implement the prescribed motion constraint internally, is that we can choose the gains well and inform the solver about that constraint directly.
Another possibility is to implement a force element that works "inside" the plant and accepts an input port. This would allow you to apply forces to implement your modeling ideas even in ways that are not possible through the actuation_input_port
(e.g. not achievable by a declared actuator).
The glider example you link is a good one. In that case, I was very worried about having a model that avoided even declaring the velocity of the elevator as state (since our verification methods scale in complexity with the dimension of the state space). For now, that still requires writing a bespoke LeafSystem
implementation.
QUESTION
I'm trying to port trajectory optimization code originally written for TrajOpt into Drake. One of the nice things about TrajOpt is that it could solve SQP trajectory optimization problems with a constraint enforcing a minimum distance between the robot and surrounding obstacles, and it supported a pretty broad range of geometries (all the standard convex primitives plus simple convex meshes). For a number of reasons, TrajOpt is no longer the right choice for my project, so I'm porting my trajectory optimization code over to Drake. I think MinimumDistanceConstraint
is what I want to replicate this functionality, but it seems that Drake allows AutoDiffXd
signed distance queries only for spheres and half-spaces, not for more general convex shapes (like boxes or cylinders).
All of my other constraints support AutoDiff (I have some custom constraints for "probability of collision," but those provide an analytical derivative that can be used in an AutoDiff). In order to add a MinimumDistanceConstraint
that supports more general geometry, would I have to formulate the MathematicalProgram
entirely with doubles? Would that slow down the performance of the solver (e.g. by having to do finite differences instead of using the gradient information in AutoDiffXd
)?
In an ideal world, I'd like to avoid resorting to "bubble-wrapping" my robot and environment (replacing all the collision geometry with spheres), since the runtime of the custom constraints I'm using scales with the number of collide-able pairs in the scene (I'm currently using convex geometry to keep this number relatively low).
Any help would be appreciated!
...ANSWER
Answered 2020-May-22 at 14:51but it seems that Drake allows AutoDiffXd signed distance queries only for spheres and half-spaces, not for more general convex shapes (like boxes or cylinders)
- I think
MinimumDistanceConstraint
can handle more general geometries (including boxes and cylinders) forMultibodyPlant
andSceneGraph
. It calls FCL to compute the signed distance between these geometries (including witness points). It is true that these signed distance queries don't support AutodiffXd yet, but only double type. But as you will see later, you don't need the signed distance query with AutoDiffXd to compute the gradient of the distance. - You could try to construct MinimumDistanceConstraint for a
MultibodyPlant
with this API. Although you useMultibodyPlant
notMultibodyPlant
,MinimumDistanceConstraint
can still evaluate with AutodiffXd. Specifically, it computes the gradient of the signed distance here. To compute the gradient of the signed distance query, the signed distance query doesn't need to support AutoDiffXd. We can compute the gradient using the witness points and the normal vectors as
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install trajopt
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page