- 3.0.2 core module.
SubstepRecorder.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
9 
10 namespace ct {
11 namespace core {
12 
14 
19 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
20 class SubstepRecorder : public EventHandler<STATE_DIM, SCALAR>
21 {
22 public:
23  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 
26 
28  bool activated = true,
29  std::shared_ptr<ct::core::StateVectorArray<STATE_DIM, SCALAR>> states =
32  std::shared_ptr<ct::core::ControlVectorArray<CONTROL_DIM, SCALAR>> controls =
35  std::shared_ptr<ct::core::tpl::TimeArray<SCALAR>> times = std::shared_ptr<ct::core::tpl::TimeArray<SCALAR>>(
37  : activated_(activated), system_(system), states_(states), controls_(controls), times_(times)
38  {
39  }
40 
42  virtual ~SubstepRecorder() {}
43  virtual bool callOnSubsteps() override { return true; }
45  {
46  system_ = system;
47  }
48 
50  virtual bool checkEvent(const state_t& state, const SCALAR& t) override { return activated_; }
52  virtual void handleEvent(const state_t& state, const SCALAR& t) override
53  {
54  states_->push_back(state);
55  controls_->push_back(system_->getLastControlAction());
56  times_->push_back(t);
57  }
58 
59  void setEnable(bool activated) { activated_ = activated; }
61  virtual void reset() override
62  {
63  states_ = std::shared_ptr<ct::core::StateVectorArray<STATE_DIM, SCALAR>>(
65  controls_ = std::shared_ptr<ct::core::ControlVectorArray<CONTROL_DIM, SCALAR>>(
67  times_ = std::shared_ptr<ct::core::tpl::TimeArray<SCALAR>>(new ct::core::tpl::TimeArray<SCALAR>);
68  };
69 
70  const std::shared_ptr<ct::core::StateVectorArray<STATE_DIM, SCALAR>>& getSubstates() const { return states_; }
71  const std::shared_ptr<ct::core::ControlVectorArray<CONTROL_DIM, SCALAR>>& getSubcontrols() const
72  {
73  return controls_;
74  }
75 
76 private:
77  bool activated_;
78 
79  std::shared_ptr<ct::core::ControlledSystem<STATE_DIM, CONTROL_DIM, SCALAR>> system_;
80 
81  std::shared_ptr<ct::core::StateVectorArray<STATE_DIM, SCALAR>> states_;
82  std::shared_ptr<ct::core::ControlVectorArray<CONTROL_DIM, SCALAR>>
83  controls_;
84  std::shared_ptr<ct::core::tpl::TimeArray<SCALAR>> times_;
85 };
86 }
87 }
virtual ~SubstepRecorder()
default destructor
Definition: SubstepRecorder.h:42
An discrete array (vector) of a particular data type.
Definition: DiscreteArray.h:22
const std::shared_ptr< ct::core::ControlVectorArray< CONTROL_DIM, SCALAR > > & getSubcontrols() const
Definition: SubstepRecorder.h:71
SubstepRecorder(std::shared_ptr< ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR >> system=nullptr, bool activated=true, std::shared_ptr< ct::core::StateVectorArray< STATE_DIM, SCALAR >> states=std::shared_ptr< ct::core::StateVectorArray< STATE_DIM, SCALAR >>(new ct::core::StateVectorArray< STATE_DIM, SCALAR >), std::shared_ptr< ct::core::ControlVectorArray< CONTROL_DIM, SCALAR >> controls=std::shared_ptr< ct::core::ControlVectorArray< CONTROL_DIM, SCALAR >>(new ct::core::ControlVectorArray< CONTROL_DIM, SCALAR >), std::shared_ptr< ct::core::tpl::TimeArray< SCALAR >> times=std::shared_ptr< ct::core::tpl::TimeArray< SCALAR >>(new ct::core::tpl::TimeArray< SCALAR >))
Definition: SubstepRecorder.h:27
const std::shared_ptr< ct::core::StateVectorArray< STATE_DIM, SCALAR > > & getSubstates() const
Definition: SubstepRecorder.h:70
void setControlledSystem(const std::shared_ptr< ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR >> &system)
Definition: SubstepRecorder.h:44
virtual void reset() override
resets kill flag to false
Definition: SubstepRecorder.h:61
virtual bool callOnSubsteps() override
Definition: SubstepRecorder.h:43
Event handler to record substeps.
Definition: SubstepRecorder.h:20
virtual void handleEvent(const state_t &state, const SCALAR &t) override
records the state
Definition: SubstepRecorder.h:52
void setEnable(bool activated)
Definition: SubstepRecorder.h:59
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Definition: StateVector.h:12
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef StateVector< STATE_DIM, SCALAR > state_t
Definition: SubstepRecorder.h:25
An array in time.
Definition: TimeArray.h:22
Interface for an event handler for an Integrator.
Definition: EventHandler.h:24
virtual bool checkEvent(const state_t &state, const SCALAR &t) override
checks the kill flag
Definition: SubstepRecorder.h:50
A general, non-linear dynamic system with a control input.
Definition: ControlledSystem.h:46