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 
45  void configure(const mc_rtc::Configuration &) override {}
46 
53  {
54  return *controller_;
55  }
56 
62  std::shared_ptr<mc_rtc::gui::StateBuilder> gui()
63  {
64  return controller_->gui();
65  }
66 
72  mc_rtc::Logger & logger()
73  {
74  return controller_->logger();
75  }
76 
83  {
84  return controller_->pendulum();
85  }
86 
93  {
94  return controller_->plan;
95  }
96 
100  bool run(mc_control::fsm::Controller &) override
101  {
102  if(checkTransitions())
103  {
104  return true;
105  }
106  runState();
107  return false;
108  }
109 
116  {
117  return controller_->stabilizer();
118  }
119 
123  void start(mc_control::fsm::Controller & controller) override
124  {
125  controller_ = &static_cast<Controller &>(controller);
126  start();
127  }
128 
132  void teardown(mc_control::fsm::Controller &) override
133  {
134  teardown();
135  }
136 
137  virtual bool checkTransitions() = 0;
138  virtual void runState() = 0;
139  virtual void start() = 0;
140  virtual void teardown() = 0;
141 
142 protected:
143  Controller * controller_ = nullptr;
144 };
145 
146 } // namespace lipm_walking
Pendulum & pendulum()
Get pendulum reference.
Definition: State.h:82
bool run(mc_control::fsm::Controller &) override
Main function.
Definition: State.h:100
Stabilizer & stabilizer()
This getter is only used for consistency with the rest of mc_rtc.
Definition: Controller.h:303
virtual void runState()=0
State of the inverted pendulum model.
Definition: Pendulum.h:40
EIGEN_MAKE_ALIGNED_OPERATOR_NEW void configure(const mc_rtc::Configuration &) override
No configuration by default.
Definition: State.h:45
virtual void teardown()=0
void teardown(mc_control::fsm::Controller &) override
Teardown function.
Definition: State.h:132
Controller * controller_
Definition: State.h:143
std::shared_ptr< mc_rtc::gui::StateBuilder > gui()
Get GUI handle.
Definition: State.h:62
Main controller class.
Definition: Controller.h:67
Stabilizer & stabilizer()
Get stabilizer.
Definition: State.h:115
FootstepPlan plan
Current footstep plan.
Definition: Controller.h:325
Convenience wrapper for FSM states.
Definition: State.h:38
Walking stabilization based on linear inverted pendulum tracking.
Definition: Stabilizer.h:58
mc_rtc::Logger & logger()
Get logger.
Definition: State.h:72
FootstepPlan & plan()
Get footstep plan.
Definition: State.h:92
Main controller namespace.
Definition: build.dox:1
virtual bool checkTransitions()=0
void start(mc_control::fsm::Controller &controller) override
Start function.
Definition: State.h:123
Controller & controller()
Get controller.
Definition: State.h:52
Pendulum & pendulum()
This getter is only used for consistency with the rest of mc_rtc.
Definition: Controller.h:263
Sequence of footsteps with gait parameters.
Definition: FootstepPlan.h:41
virtual void start()=0