Initial.cpp
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 #include "Initial.h"
29 
30 namespace lipm_walking
31 {
32 
34 {
35  auto & ctl = controller();
36 
37  postureTaskIsActive_ = true;
38  postureTaskWasActive_ = true;
39  startStandingButton_ = false;
40  startStanding_ = false;
41 
42  ctl.internalReset();
43 
44  logger().addLogEntry("walking_phase", []() { return -2.; });
45 
46  if(gui())
47  {
48  gui()->removeElement({"Walking", "Main"}, "Pause walking");
49  }
50 
51  runState(); // don't wait till next cycle to update reference and tasks
52 }
53 
55 {
56  logger().removeLogEntry("walking_phase");
57 
58  if(gui())
59  {
61  }
62 }
63 
65 {
66  auto & ctl = controller();
67  postureTaskIsActive_ = (ctl.postureTask->speed().norm() > 1e-2);
68  if(postureTaskIsActive_)
69  {
71  postureTaskWasActive_ = true;
72  }
73  else if(postureTaskWasActive_)
74  {
75  ctl.internalReset();
76  postureTaskWasActive_ = false;
77  }
78  else
79  {
81  }
82 }
83 
85 {
86  if(startStanding_ && !postureTaskIsActive_)
87  {
88  output("Standing");
89  return true;
90  }
91  return false;
92 }
93 
95 {
96  if(!startStandingButton_ && gui())
97  {
98  using namespace mc_rtc::gui;
99  gui()->addElement({"Walking", "Main"}, Button("Start standing", [this]() { startStanding_ = true; }));
100  startStandingButton_ = true;
101  }
102 }
103 
105 {
106  if(startStandingButton_ && gui())
107  {
108  gui()->removeElement({"Walking", "Main"}, "Start standing");
109  startStandingButton_ = false;
110  }
111 }
112 
113 } // namespace lipm_walking
114 
115 EXPORT_SINGLE_STATE("Initial", lipm_walking::states::Initial)
void start() override
Start state.
Definition: Initial.cpp:33
void runState() override
Main state function, called if no transition at this cycle.
Definition: Initial.cpp:64
std::shared_ptr< mc_rtc::gui::StateBuilder > gui()
Get GUI handle.
Definition: State.h:62
void hideStartStandingButton()
Remove "Start standing" transition button from GUI.
Definition: Initial.cpp:104
mc_rtc::Logger & logger()
Get logger.
Definition: State.h:72
void teardown() override
Teardown state.
Definition: Initial.cpp:54
void showStartStandingButton()
Add "Start standing" transition button to GUI.
Definition: Initial.cpp:94
Main controller namespace.
Definition: build.dox:1
bool checkTransitions() override
Check transitions at beginning of control cycle.
Definition: Initial.cpp:84
Controller & controller()
Get controller.
Definition: State.h:52
Hold posture and check contacts.
Definition: Initial.h:48