@@ -109,8 +109,7 @@ bool swSQP::solve(const std::vector<Eigen::VectorXd>& x0, const std::vector<Eige
109109 ddefect_dw[i] = _ocp->stage (i)->stage_ddefect_dw ();
110110 }
111111
112- Eigen::VectorXd dx0 (_A[0 ].cols ()); // initial delta state constraint (dx0 = 0)
113- dx0.setZero ();
112+ _dx0.setZero ();
114113
115114 for (unsigned int iter = 1 ; iter <= _opt.max_iters ; ++iter)
116115 {
@@ -122,22 +121,22 @@ bool swSQP::solve(const std::vector<Eigen::VectorXd>& x0, const std::vector<Eige
122121 auto iter_start = std::chrono::high_resolution_clock::now ();
123122
124123 // relinarize and update qp
125- _ocp->update (_x0_candidate, _u0_candidate);
126124 linearize ();
127125
128126 // solve
129- if (!_qp_solver->solve (dx0 ))
127+ if (!_qp_solver->solve (_dx0 ))
130128 {
131129 std::cout<< " nosolve" << std::endl;
132130 return false ;
133131 }
134132
135133 // first update
136134 step (_stats.alpha );
137- _ocp-> update (_x0_candidate, _u0_candidate);
135+
138136
139137 while (_opt.line_search_strategy !=0 && _stats.alpha >= _opt.alpha_min )
140138 {
139+ _ocp->update (_x0_candidate, _u0_candidate);
141140 if ((this ->*ls_function)())
142141 {
143142 _stats.line_search_accepted =true ;
@@ -146,10 +145,15 @@ bool swSQP::solve(const std::vector<Eigen::VectorXd>& x0, const std::vector<Eige
146145 _stats.alpha /= 2 .;
147146 _stats.line_search_iters ++;
148147 step (_stats.alpha );
149- _ocp->update (_x0_candidate, _u0_candidate);
150148
151149
152150 }
151+ if (_opt.line_search_strategy ==0 )
152+ _ocp->update (_x0_candidate, _u0_candidate);
153+
154+ _x0 = _x0_candidate;
155+ _u0 = _u0_candidate;
156+
153157
154158 // check break criteria on QP solution
155159 if (break_criteria ())
@@ -160,10 +164,7 @@ bool swSQP::solve(const std::vector<Eigen::VectorXd>& x0, const std::vector<Eige
160164 break ;
161165 }
162166
163- _x0 = _x0_candidate;
164- _u0 = _u0_candidate;
165167
166- _ocp->update (_x0, _u0); // TODO I am not sure about this update, maybe its not needed
167168 _prev_cost = _ocp->cost ();
168169 _prev_defect = _ocp->dynamics_defect ();
169170 _prev_viol = _ocp->constraint_violation ();
@@ -307,6 +308,7 @@ void swSQP::init()
307308
308309 _qp_solver->setStageDynamics (k, A, B, b);
309310 }
311+ _dx0.setZero (_A[0 ].cols ()); // initial delta state constraint (_dx0 = 0)
310312
311313 // --- Cost (always) ---
312314 _H.push_back (Eigen::MatrixXd (_ocp->stage (k)->stack ->getStack ()[0 ]->getA ().cols (), _ocp->stage (k)->stack ->getStack ()[0 ]->getA ().cols ()));
0 commit comments