- 3.0.2 core module.
KillIntegrationEventHandler.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 
21 template <size_t STATE_DIM>
22 class KillIntegrationEventHandler : public EventHandler<STATE_DIM>
23 {
24 public:
25  typedef Eigen::Matrix<double, STATE_DIM, 1> State_T;
26 
28 
31  KillIntegrationEventHandler() : killIntegration_(false) {}
34  virtual bool callOnSubsteps() override { return false; }
36  bool checkEvent(const State_T& state, const double& t) override { return killIntegration_; }
38 
43  void handleEvent(const State_T& state, const double& t) override
44  {
45  /* throw an exception which stops the integration */
46  throw std::runtime_error("Integration terminated due to external event specified by user.");
47  }
48 
50  void setEvent() { killIntegration_ = true; }
52  void resetEvent() { killIntegration_ = false; }
54  virtual void reset() override { resetEvent(); };
55 private:
56  bool killIntegration_;
57 };
58 
59 } // namespace core
60 } // namespace ct
void setEvent()
enables killing at next call
Definition: KillIntegrationEventHandler.h:50
virtual void reset() override
resets kill flag to false
Definition: KillIntegrationEventHandler.h:54
virtual bool callOnSubsteps() override
Definition: KillIntegrationEventHandler.h:34
Eigen::Matrix< double, STATE_DIM, 1 > State_T
Definition: KillIntegrationEventHandler.h:25
virtual ~KillIntegrationEventHandler()
default destructor
Definition: KillIntegrationEventHandler.h:33
bool checkEvent(const State_T &state, const double &t) override
checks the kill flag
Definition: KillIntegrationEventHandler.h:36
void resetEvent()
disable killing at next call
Definition: KillIntegrationEventHandler.h:52
void handleEvent(const State_T &state, const double &t) override
interrupts integration
Definition: KillIntegrationEventHandler.h:43
Event handler to kill integration.
Definition: KillIntegrationEventHandler.h:22
KillIntegrationEventHandler()
default constructor
Definition: KillIntegrationEventHandler.h:31
Interface for an event handler for an Integrator.
Definition: EventHandler.h:24