Skip to content

Commit 49a92d4

Browse files
committed
Merge branch 'master' into toc
2 parents 2085832 + 2102165 commit 49a92d4

File tree

5 files changed

+128
-52
lines changed

5 files changed

+128
-52
lines changed

.github/workflows/TagBot.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

Project.toml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "TrajectoryOptimization"
22
uuid = "c79d492b-0548-5874-b488-5a62c1d9d0ca"
3-
version = "0.1.2"
3+
version = "0.2.0"
44

55
[deps]
66
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
@@ -11,3 +11,36 @@ RobotDynamics = "38ceca67-d8d3-44e8-9852-78a5596522e1"
1111
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1212
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1313
UnsafeArrays = "c4a57d5a-5b31-53a6-b365-19f8c011fbd6"
14+
15+
[compat]
16+
BenchmarkTools = "0.4"
17+
Combinatorics = "1"
18+
CoordinateTransformations = "0.5,0.6"
19+
Distributions = "0.23"
20+
DocStringExtensions = "0.8"
21+
Documenter = "0.24"
22+
FFMPEG = "0.3"
23+
Formatting = "0.4"
24+
ForwardDiff = "0.10"
25+
Interpolations = "0.12"
26+
Ipopt = "0.6.0"
27+
IterTools = "1"
28+
MathOptInterface = "0.9"
29+
Parameters = "0.12"
30+
Quaternions = "0.4"
31+
RecipesBase = "1"
32+
Rotations = "0.13,1.0"
33+
StaticArrays = "0.12.3"
34+
StatsBase = "0.33"
35+
UnsafeArrays = "1"
36+
julia = "1.1.0"
37+
38+
[extras]
39+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
40+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
41+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
42+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
43+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
44+
45+
[targets]
46+
test = ["LinearAlgebra", "SparseArrays", "Random", "Test", "Logging", "ForwardDiff"]

README.md

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,59 +16,67 @@ A library of solvers for trajectory optimization problems written in Julia. Curr
1616
Direct Collocation (DIRCOL)
1717
* Interfaces to Nonlinear Programming solvers (e.g., [Ipopt](https://github.com/coin-or/Ipopt), [SNOPT](https://ccom.ucsd.edu/~optimizers/solvers/snopt/)) via [MathOptInterface](https://github.com/JuliaOpt/MathOptInterface.jl)
1818

19-
All methods utilize Julia's extensive autodifferentiation capabilities via [ForwardDiff.jl](http://www.juliadiff.org/ForwardDiff.jl/) so that the user does not need to specify derivatives of dynamics, cost, or constraint functions. Dynamics can be computed directly from a URDF file via [RigidBodyDynamics.jl](https://github.com/JuliaRobotics/RigidBodyDynamics.jl).
19+
All methods utilize Julia's extensive autodifferentiation capabilities via [ForwardDiff.jl](http://www.juliadiff.org/ForwardDiff.jl/) so that the user does not need to specify derivatives of dynamics, cost, or constraint functions.
2020

2121
## Installation
2222
To install TrajectoryOptimization.jl, run the following from the Julia REPL:
2323
```julia
2424
Pkg.add("TrajectoryOptimization")
2525
```
2626

27+
# What's New
28+
`TrajectoryOptimization.jl` underwent significant changes between versions `v0.1` and `v0.2`. The new code is significantly faster (up to 100x faster). The core part of the ALTRO solver (everything except the projected newton phase) is completely allocation-free once the solver has been initialized. Most of the API has changed significantly. See the documentation for more information on the new API.
29+
2730
## Quick Start
28-
To run a simple example of a constrained 1D block move:
31+
To run a simple example of a constrained 1D block move (see script in `/examples/quickstart.jl`):
2932
```julia
30-
using TrajectoryOptimization, LinearAlgebra
33+
using TrajectoryOptimization
34+
using StaticArrays
35+
using LinearAlgebra
36+
const TO = TrajectoryOptimization
3137

32-
function dynamics!(ẋ,x,u) # inplace dynamics
33-
ẋ[1] = x[2]
34-
ẋ[2] = u[1]
38+
struct DoubleIntegrator{T} <: AbstractModel
39+
mass::T
3540
end
3641

37-
n = 2 # number of states
38-
m = 1 # number of controls
39-
model = Model(dynamics!,n,m) # create model
40-
model_d = rk3(model) # create discrete model w/ rk3 integration
41-
42-
x0 = [0.; 0.] # initial state
43-
xf = [1.; 0.] # goal state
44-
45-
N = 21 # number of knot points
46-
dt = 0.1 # time step
47-
48-
U0 = [0.01*rand(m) for k = 1:N-1]; # initial control trajectory
49-
50-
Q = 1.0*Diagonal(I,n)
51-
Qf = 1.0*Diagonal(I,n)
52-
R = 1.0e-1*Diagonal(I,m)
53-
obj = LQRObjective(Q,R,Qf,xf,N) # objective
54-
55-
bnd = BoundConstraint(n,m,u_max=1.5, u_min=-1.5) # control limits
56-
goal = goal_constraint(xf) # terminal constraint
57-
58-
constraints = Constraints(N) # define constraints at each time step
59-
for k = 1:N-1
60-
constraints[k] += bnd
42+
function TO.dynamics(model::DoubleIntegrator, x, u)
43+
SA[x[2], u[1] / model.mass]
6144
end
62-
constraints[N] += goal
6345

64-
prob = Problem(model_d, obj, constraints=constraints, x0=x0, xf=xf, N=N, dt=dt) # construct problem
65-
initial_controls!(prob,U0) # initialize problem with controls
66-
67-
solver = solve!(prob, ALTROSolverOptions{Float64}())
46+
Base.size(::DoubleIntegrator) = 2,1
47+
48+
# Model and discretization
49+
model = DoubleIntegrator(1.0)
50+
n,m = size(model)
51+
tf = 3.0 # sec
52+
N = 21 # number of knot points
53+
54+
# Objective
55+
x0 = SA[0,0.] # initial state
56+
xf = SA[1,0.] # final state
57+
58+
Q = Diagonal(@SVector ones(n))
59+
R = Diagonal(@SVector ones(m))
60+
obj = LQRObjective(Q, R, N*Q, xf, N)
61+
62+
# Constraints
63+
cons = TO.ConstraintSet(n,m,N)
64+
add_constraint!(cons, GoalConstraint(xf), N:N)
65+
add_constraint!(cons, BoundConstraint(n,m, u_min=-10, u_max=10), 1:N-1)
66+
67+
# Create and solve problem
68+
prob = Problem(model, obj, xf, tf, x0=x0, constraints=cons)
69+
solver = ALTROSolver(prob)
70+
cost(solver) # initial cost
71+
solve!(solver) # solve with ALTRO
72+
max_violation(solver) # max constraint violation
73+
cost(solver) # final cost
74+
iterations(solver) # total number of iterations
75+
76+
# Get the state and control trajectories
77+
X = states(solver)
78+
U = controls(solver)
6879
```
6980

7081
## Examples
71-
Notebooks with more detailed examples can be found [here](https://github.com/RoboticExplorationLab/TrajectoryOptimization.jl/tree/master/examples), including all the examples from our [IROS 2019 paper](https://github.com/RoboticExplorationLab/TrajectoryOptimization.jl/tree/master/examples/IROS_2019).
72-
73-
## Documentation
74-
Detailed documentation for getting started with the package can be found [here](https://roboticexplorationlab.github.io/TrajectoryOptimization.jl/dev/).
82+
Notebooks with more detailed examples can be found [here](https://github.com/RoboticExplorationLab/TrajectoryOptimization.jl/tree/master/examples), including all the examples from our [IROS 2019 paper](https://rexlab.stanford.edu/papers/altro-iros.pdf).

examples/quickstart.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using TrajectoryOptimization
2+
using StaticArrays
3+
using LinearAlgebra
4+
const TO = TrajectoryOptimization
5+
6+
struct DoubleIntegrator{T} <: AbstractModel
7+
mass::T
8+
end
9+
10+
function TO.dynamics(model::DoubleIntegrator, x, u)
11+
SA[x[2], u[1] / model.mass]
12+
end
13+
14+
Base.size(::DoubleIntegrator) = 2,1
15+
16+
# Model and discretization
17+
model = DoubleIntegrator(1.0)
18+
n,m = size(model)
19+
tf = 3.0 # sec
20+
N = 21 # number of knot points
21+
22+
# Objective
23+
x0 = SA[0,0.] # initial state
24+
xf = SA[1,0.] # final state
25+
26+
Q = Diagonal(@SVector ones(n))
27+
R = Diagonal(@SVector ones(m))
28+
obj = LQRObjective(Q, R, N*Q, xf, N)
29+
30+
# Constraints
31+
cons = TO.ConstraintSet(n,m,N)
32+
add_constraint!(cons, GoalConstraint(xf), N:N)
33+
add_constraint!(cons, BoundConstraint(n,m, u_min=-10, u_max=10), 1:N-1)
34+
35+
# Create and solve problem
36+
prob = Problem(model, obj, xf, tf, x0=x0, constraints=cons)
37+
solver = ALTROSolver(prob)
38+
cost(solver) # initial cost
39+
solve!(solver) # solve with ALTRO
40+
max_violation(solver) # max constraint violation
41+
cost(solver) # final cost
42+
iterations(solver) # total number of iterations
43+
44+
# Get the state and control trajectories
45+
X = states(solver)
46+
U = controls(solver)

test/old/models_test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ cartpole = Dynamics.Cartpole()
4343
# Quadrotor
4444
quad = Dynamics.Quadrotor2()
4545
@test size(quad) == (13,4)
46-
@test num_allocs(cartpole) == 0
46+
@test num_allocs(quad) == 0
4747

4848

4949
# Infeasible

0 commit comments

Comments
 (0)