@@ -85,59 +85,6 @@ class CustomController : public ct::core::Controller<state_dim, control_dim>
85
85
};
86
86
87
87
88
- /* !
89
- * Implementation of the "DisturbedSystem" which is going to be used for handed over to the Kalman Filter
90
- * for dynamics prediction and computing derivatives.
91
- * @note this system is not used for simulation, but for filtering.
92
- */
93
- template <size_t state_dim, size_t dist_dim, size_t control_dim, typename SCALAR = double >
94
- class CustomDisturbedSystem : public ct ::optcon::DisturbedSystem<state_dim, dist_dim, control_dim, SCALAR>
95
- {
96
- public:
97
- EIGEN_MAKE_ALIGNED_OPERATOR_NEW
98
-
99
- // ! constructor
100
- CustomDisturbedSystem (std::shared_ptr<ct::core::ControlledSystem<state_dim, control_dim, SCALAR>> sys)
101
- : ct::optcon::DisturbedSystem<state_dim, dist_dim, control_dim, SCALAR>(sys->getController ()), system_(sys)
102
- {
103
- }
104
-
105
- // ! copy constructor
106
- CustomDisturbedSystem (const CustomDisturbedSystem& other)
107
- : ct::optcon::DisturbedSystem<state_dim, dist_dim, control_dim, SCALAR>(*this ), system_(other.system_->clone ())
108
- {
109
- }
110
-
111
- // ! deep cloning
112
- CustomDisturbedSystem* clone () const override { return new CustomDisturbedSystem (*this ); }
113
-
114
- /* !
115
- * Override the computeControlledDynamics() with a custom update rule.
116
- */
117
- void computeControlledDynamics (const ct::core::StateVector<state_dim + dist_dim, SCALAR>& state,
118
- const SCALAR& t,
119
- const ct::core::ControlVector<control_dim, SCALAR>& control,
120
- ct::core::StateVector<state_dim + dist_dim, SCALAR>& derivative) override
121
- {
122
- derivative.setZero ();
123
- ct::core::StateVector<state_dim, SCALAR> tempDerivative;
124
-
125
- // the control consists of actual commanded control plus the estimated input disturbance,
126
- // which is the augmented part of the state vector
127
- ct::core::ControlVector<control_dim, SCALAR> disturbed_control = control + state.template tail <dist_dim>();
128
-
129
- // the dynamics of the augmented system
130
- system_->computeControlledDynamics (state.head (state_dim), t, disturbed_control, tempDerivative);
131
- derivative.template head <state_dim>() = tempDerivative;
132
- }
133
-
134
-
135
- private:
136
- // the nominal system (the one we are trying to control)
137
- std::shared_ptr<ct::core::ControlledSystem<state_dim, control_dim, SCALAR>> system_;
138
- };
139
-
140
-
141
88
int main (int argc, char ** argv)
142
89
{
143
90
// file with weights and settings
@@ -215,8 +162,8 @@ int main(int argc, char** argv)
215
162
std::shared_ptr<CustomController> controller_nominal (
216
163
new CustomController (uff_magnitude, uff_frequency, kp, kd, 0.0 , 0.0 ));
217
164
218
- std::shared_ptr<CustomDisturbedSystem <state_dim, dist_dim, control_dim>> customdisturbedSystem (
219
- new CustomDisturbedSystem <state_dim, dist_dim , control_dim>(oscillator_obs));
165
+ std::shared_ptr<ct::optcon::InputDisturbedSystem <state_dim, control_dim>> inputDisturbedSystem (
166
+ new ct::optcon::InputDisturbedSystem <state_dim, control_dim>(oscillator_obs));
220
167
221
168
// Observation matrix for the state
222
169
ct::core::OutputStateMatrix<output_dim, state_dim> C;
@@ -240,12 +187,12 @@ int main(int argc, char** argv)
240
187
241
188
// create a sensitivity approximator to obtain discrete-time dynamics matrices
242
189
std::shared_ptr<ct::core::SystemLinearizer<state_dim + dist_dim, control_dim>> linearizer (
243
- new ct::core::SystemLinearizer<state_dim + dist_dim, control_dim>(customdisturbedSystem ));
190
+ new ct::core::SystemLinearizer<state_dim + dist_dim, control_dim>(inputDisturbedSystem ));
244
191
ct::core::SensitivityApproximation<state_dim + dist_dim, control_dim> sensApprox (dt, linearizer);
245
192
246
193
// set up the system model
247
194
std::shared_ptr<ct::optcon::CTSystemModel<state_dim + dist_dim, control_dim>> sysModel (
248
- new ct::optcon::CTSystemModel<state_dim + dist_dim, control_dim>(customdisturbedSystem , sensApprox, dFdv));
195
+ new ct::optcon::CTSystemModel<state_dim + dist_dim, control_dim>(inputDisturbedSystem , sensApprox, dFdv));
249
196
250
197
// set up the measurement model
251
198
std::shared_ptr<ct::optcon::LinearMeasurementModel<output_dim, state_dim + dist_dim>> measModel (
@@ -273,7 +220,8 @@ int main(int argc, char** argv)
273
220
274
221
275
222
// set up Extended Kalman Filter
276
- ct::optcon::ExtendedKalmanFilter<state_dim + dist_dim, control_dim, output_dim> ekf (sysModel, measModel, Qaug, R, x0aug, Qaug);
223
+ ct::optcon::ExtendedKalmanFilter<state_dim + dist_dim, control_dim, output_dim> ekf (
224
+ sysModel, measModel, Qaug, R, x0aug, Qaug);
277
225
278
226
279
227
// run the filter over the simulated data
0 commit comments