Skip to content

Commit

Permalink
warm start solver; make solver faster
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-levy committed Jan 4, 2023
1 parent 3149406 commit 326a5cb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RosSockets"
uuid = "f2b1035b-1fed-4502-a057-be66ed18c291"
authors = ["Jacob Levy"]
version = "0.2.1"
version = "0.2.2"

[deps]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Expand Down
8 changes: 7 additions & 1 deletion examples/optimal_feedback_control_example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function run_example()
timestep = 0.1 # duration of each timestep (sec)
model = initialize_model(goal_state, timestep)

# begin without warm start so that first solve is cold
warm_start = false

# initialize a plotter to display trajectory solution real-time
display(plot(xlims=(-1,4),ylims=(-1,4),size=(600,600)))

Expand All @@ -45,8 +48,11 @@ function run_example()
feedback_state = receive_feedback_data(feedback_connection, timeout)

# compute control commands and send them
commands, trajectory = solve!(model,feedback_state)
commands, trajectory = solve!(model,feedback_state,warm_start)
send_control_commands(robot_connection, commands)

# future calls to solve! will be warm started
warm_start = true

# plot solution trajectory
display(plot(trajectory[:,1],trajectory[:,2],
Expand Down
10 changes: 9 additions & 1 deletion examples/utils/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function initialize_model(goal_state, timestep)

model = Model(Ipopt.Optimizer)
set_optimizer_attribute(model, "max_iter", 100)
set_optimizer_attribute(model, "print_level", 1)
set_optimizer_attribute(model, "mu_strategy", "adaptive")

@variables(model, begin
x[1:T]
Expand Down Expand Up @@ -62,10 +64,16 @@ function initialize_model(goal_state, timestep)
return model
end

function solve!(model, feedback_state::FeedbackData)
function solve!(model, feedback_state::FeedbackData, warm_start=false)

state = to_state_vec(feedback_state)

if warm_start
x = all_variables(model)
x_solution = value.(x)
set_start_value.(x, x_solution)
end

fix(model[:x][1], state[1])
fix(model[:y][1], state[2])
fix(model[:v][1], state[3])
Expand Down

0 comments on commit 326a5cb

Please sign in to comment.