@@ -42,12 +42,43 @@ create_max_altitude_rocket_ocp()
4242 };
4343
4444
45+ problem.cost_control_gradient = [=]( const StageCostFunction&, const State&, const Control& control, size_t ) {
46+ Eigen::VectorXd gradient ( 1 );
47+ gradient ( 0 ) = w_thrust * control ( 0 );
48+ return gradient;
49+ };
50+
51+ problem.cost_control_hessian = [=]( const StageCostFunction&, const State&, const Control&, size_t ) {
52+ Eigen::MatrixXd hessian ( 1 , 1 );
53+ hessian ( 0 , 0 ) = w_thrust;
54+ return hessian;
55+ };
56+
57+ problem.cost_state_gradient = []( const StageCostFunction&, const State& state, const Control&, size_t ) {
58+ return Eigen::VectorXd::Zero ( state.size () );
59+ };
60+
61+ problem.cost_state_hessian = []( const StageCostFunction&, const State& state, const Control&, size_t ) {
62+ return Eigen::MatrixXd::Zero ( state.size (), state.size () );
63+ };
64+
4565 problem.terminal_cost = [=]( const State& state ) {
4666 const double altitude = state ( 0 );
4767 const double velocity_error = state ( 1 ) - desired_terminal_vel;
48- const double alt_sign = altitude >= 0.0 ? 1.0 : -1.0 ;
49- return -w_terminal_altitude * altitude * altitude * alt_sign + 0.5 * w_terminal_velocity * velocity_error * velocity_error
50- + state ( 2 ) * state ( 2 ) * 1e2 ;
68+ return -w_terminal_altitude * altitude + 0.5 * w_terminal_velocity * velocity_error * velocity_error;
69+ };
70+
71+ problem.terminal_cost_gradient = [=]( const TerminalCostFunction&, const State& state ) {
72+ Eigen::VectorXd gradient = Eigen::VectorXd::Zero ( state.size () );
73+ gradient ( 0 ) = -w_terminal_altitude;
74+ gradient ( 1 ) = w_terminal_velocity * ( state ( 1 ) - desired_terminal_vel );
75+ return gradient;
76+ };
77+
78+ problem.terminal_cost_hessian = [=]( const TerminalCostFunction&, const State& state ) {
79+ Eigen::MatrixXd hessian = Eigen::MatrixXd::Zero ( state.size (), state.size () );
80+ hessian ( 1 , 1 ) = w_terminal_velocity;
81+ return hessian;
5182 };
5283
5384
0 commit comments