Skip to content

Commit 14d44a1

Browse files
Modify CDDP to update reference states and update reference state accordingly (#66)
1 parent cb8d461 commit 14d44a1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

include/cddp-cpp/cddp_core/cddp_core.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,17 @@ class CDDP {
162162
* @brief Set the Reference state
163163
* @param reference_state Reference state
164164
*/
165-
void setReferenceState(const Eigen::VectorXd& reference_state) { reference_state_ = reference_state; }
165+
void setReferenceState(const Eigen::VectorXd& reference_state) {
166+
reference_state_ = reference_state;
167+
// Update the objective reference state
168+
objective_->setReferenceState(reference_state);
169+
}
170+
171+
void setReferenceStates(const std::vector<Eigen::VectorXd>& reference_states) {
172+
reference_states_ = reference_states;
173+
// Update the objective reference states
174+
objective_->setReferenceStates(reference_states);
175+
}
166176

167177
/**
168178
* @brief Set the time horizon for the problem
@@ -282,6 +292,7 @@ class CDDP {
282292
std::unique_ptr<LogBarrier> log_barrier_;
283293
Eigen::VectorXd initial_state_;
284294
Eigen::VectorXd reference_state_; // Desired reference state
295+
std::vector<Eigen::VectorXd> reference_states_; // Desired reference states (trajectory)
285296
int horizon_; // Time horizon for the problem
286297
double timestep_; // Time step for the problem
287298
CDDPOptions options_; // Options for the solver

tests/cddp_core/test_logcddp_core.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ TEST(CDDPTest, SolveLogCDDP) {
4646
0.0, 0.0, 10.0;
4747
Qf = 0.5 * Qf;
4848
Eigen::VectorXd goal_state(state_dim);
49-
goal_state << 2.0, 2.0, M_PI/2.0;
49+
goal_state << 3.0, 2.0, M_PI/2.0;
5050

5151
// Create an empty vector of Eigen::VectorXd
5252
std::vector<Eigen::VectorXd> empty_reference_states;
@@ -82,6 +82,10 @@ TEST(CDDPTest, SolveLogCDDP) {
8282
cddp_solver.setDynamicalSystem(std::move(system));
8383
cddp_solver.setObjective(std::move(objective));
8484

85+
// Update goal state (for test)
86+
goal_state << 2.0, 2.0, M_PI/2.0;
87+
cddp_solver.setReferenceState(goal_state);
88+
8589
// Define control box constraints
8690
Eigen::VectorXd control_lower_bound(control_dim);
8791
control_lower_bound << -1.0, -M_PI;

0 commit comments

Comments
 (0)