- 3.0.2 core module.
MaxStepsEventHandler.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>
21 {
22 public:
24 
26 
29  MaxStepsEventHandler(const size_t& maxStepsPerSec = std::numeric_limits<size_t>::max())
30  : maxNumSteps_(maxStepsPerSec), stepsTaken_(0)
31  {
32  }
33 
35  virtual ~MaxStepsEventHandler() {}
36  virtual bool callOnSubsteps() override { return false; }
38  virtual void reset() override { stepsTaken_ = 0; };
40 
46  virtual bool checkEvent(const State_T& state, const double& t) override
47  {
48  stepsTaken_++;
49  return (stepsTaken_ > maxNumSteps_); // todo: fix this
50  }
51 
53  virtual void handleEvent(const State_T& state, const double& t) override
54  {
55  throw std::runtime_error("integration terminated: max number of steps reached.\n");
56  }
57 
59 
62  void setMaxNumSteps(size_t maxNumSteps) { maxNumSteps_ = maxNumSteps; }
63 private:
64  size_t maxNumSteps_;
65  size_t stepsTaken_;
66 };
67 
68 } // namespace core
69 } // namespace ct
virtual void handleEvent(const State_T &state, const double &t) override
throws a std::runtime_error to terminate the integration
Definition: MaxStepsEventHandler.h:53
MaxStepsEventHandler(const size_t &maxStepsPerSec=std::numeric_limits< size_t >::max())
default constructor
Definition: MaxStepsEventHandler.h:29
virtual ~MaxStepsEventHandler()
destructor
Definition: MaxStepsEventHandler.h:35
Event handler to kill a (variable step) Integrator after doing too many steps.
Definition: MaxStepsEventHandler.h:20
ct::core::StateVector< STATE_DIM > State_T
Definition: MaxStepsEventHandler.h:23
virtual void reset() override
resets the number of steps taken
Definition: MaxStepsEventHandler.h:38
virtual bool checkEvent(const State_T &state, const double &t) override
checks if number of steps is exceeded
Definition: MaxStepsEventHandler.h:46
void setMaxNumSteps(size_t maxNumSteps)
set maximum number of steps
Definition: MaxStepsEventHandler.h:62
Interface for an event handler for an Integrator.
Definition: EventHandler.h:24
virtual bool callOnSubsteps() override
Definition: MaxStepsEventHandler.h:36