State.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019, CNRS-UM LIRMM
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 
31 
32 namespace lipm_walking
33 {
34 
38 struct State : mc_control::fsm::State
39 {
40  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
41 
48  {
49  return *controller_;
50  }
51 
57  std::shared_ptr<mc_rtc::gui::StateBuilder> gui()
58  {
59  return controller_->gui();
60  }
61 
67  mc_rtc::Logger & logger()
68  {
69  return controller_->logger();
70  }
71 
78  {
79  return controller_->pendulum();
80  }
81 
88  {
89  return controller_->plan;
90  }
91 
95  bool run(mc_control::fsm::Controller &) override
96  {
97  if(checkTransitions())
98  {
99  return true;
100  }
101  runState();
102  return false;
103  }
104 
110  std::shared_ptr<mc_tasks::lipm_stabilizer::StabilizerTask> stabilizer()
111  {
112  return controller_->stabilizer();
113  }
114 
118  void start(mc_control::fsm::Controller & controller) override
119  {
120  controller_ = &static_cast<Controller &>(controller);
121  start();
122  }
123 
127  void teardown(mc_control::fsm::Controller &) override
128  {
129  teardown();
130  }
131 
132  virtual bool checkTransitions() = 0;
133  virtual void runState() = 0;
134  virtual void start() = 0;
135  virtual void teardown() = 0;
136 
137 protected:
138  Controller * controller_ = nullptr;
139 };
140 
141 } // namespace lipm_walking
mc_planning::Pendulum Pendulum
Definition: Preview.cpp:37
std::shared_ptr< mc_tasks::lipm_stabilizer::StabilizerTask > stabilizer()
Definition: Controller.h:279
mc_planning::Pendulum & pendulum()
Definition: Controller.h:247
virtual bool checkTransitions()=0
virtual void teardown()=0
mc_rtc::Logger & logger()
Definition: State.h:67
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Controller & controller()
Definition: State.h:47
std::shared_ptr< mc_tasks::lipm_stabilizer::StabilizerTask > stabilizer()
Definition: State.h:110
void teardown(mc_control::fsm::Controller &) override
Definition: State.h:127
bool run(mc_control::fsm::Controller &) override
Definition: State.h:95
Controller * controller_
Definition: State.h:138
virtual void runState()=0
void start(mc_control::fsm::Controller &controller) override
Definition: State.h:118
std::shared_ptr< mc_rtc::gui::StateBuilder > gui()
Definition: State.h:57
virtual void start()=0
FootstepPlan & plan()
Definition: State.h:87
mc_planning::Pendulum & pendulum()
Definition: State.h:77