dart
Controller.hpp
1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef EXAMPLES_ATLASSIMBICON_CONTROLLER_HPP_
34 #define EXAMPLES_ATLASSIMBICON_CONTROLLER_HPP_
35 
36 #include <vector>
37 
38 #include <Eigen/Dense>
39 
40 #include <dart/dart.hpp>
41 
42 class StateMachine;
43 
49 {
50 public:
52  Controller(
53  dart::dynamics::SkeletonPtr _atlasRobot,
54  dart::dynamics::ConstraintSolver* _collisionSolver);
55 
57  virtual ~Controller();
58 
61  virtual void update();
62 
64  dart::dynamics::SkeletonPtr getAtlasRobot();
65 
68 
70  void changeStateMachine(StateMachine* _stateMachine, double _currentTime);
71 
73  void changeStateMachine(const std::string& _name, double _currentTime);
74 
76  void changeStateMachine(std::size_t _idx, double _currentTime);
77 
80  bool isAllowingControl() const;
81 
83  void keyboard(unsigned char _key, int _x, int _y, double _currentTime);
84 
86  void printDebugInfo() const;
87 
89  void harnessPelvis();
90 
92  void unharnessPelvis();
93 
95  void harnessLeftFoot();
96 
98  void unharnessLeftFoot();
99 
101  void harnessRightFoot();
102 
104  void unharnessRightFoot();
105 
107  void resetRobot();
108 
110  void setVerbosity(bool verbosity);
111 
112 protected:
114  dart::dynamics::SkeletonPtr mAtlasRobot;
115 
118 
120  std::vector<StateMachine*> mStateMachines;
121 
124 
127 
130 
133 
135  std::size_t mCoronalLeftHip;
136 
138  std::size_t mCoronalRightHip;
139 
141  std::size_t mSagitalLeftHip;
142 
144  std::size_t mSagitalRightHip;
145 
148 
151 
152 private:
154  bool _containStateMachine(const StateMachine* _stateMachine) const;
155 
158  bool _containStateMachine(const std::string& _name) const;
159 
161  StateMachine* _findStateMachine(const std::string& _name) const;
162 
164  void _buildStateMachines();
165 
167  StateMachine* _createStandingStateMachine();
168 
170  StateMachine* _createWalkingInPlaceStateMachine();
171 
173  StateMachine* _createWalkingStateMachine();
174 
176  StateMachine* _createRunningStateMachine();
177 
179  void _setJointDamping();
180 
182  dart::dynamics::BodyNode* _getLeftFoot() const;
183 
185  dart::dynamics::BodyNode* _getRightFoot() const;
186 
188  dart::dynamics::WeldJointConstraintPtr mWeldJointConstraintPelvis;
189 
191  dart::dynamics::WeldJointConstraintPtr mWeldJointConstraintLeftFoot;
192 
194  dart::dynamics::WeldJointConstraintPtr mWeldJointConstraintRightFoot;
195 
198 
200  bool mVerbosity;
201 };
202 
203 #endif // EXAMPLES_ATLASSIMBICON_CONTROLLER_HPP_
std::size_t mCoronalLeftHip
Index for coronal left hip.
Definition: Controller.hpp:135
virtual void update()
Called before every simulation time step in MyWindow class.
Definition: Controller.cpp:91
Implementation of Simbicon (Simple biped locomotion control) for Atlas robot.
Definition: Controller.hpp:48
dart::dynamics::ConstraintSolver * mConstratinSolver
Conllision detector.
Definition: Controller.hpp:117
void keyboard(unsigned char _key, int _x, int _y, double _currentTime)
Keyboard control.
Definition: Controller.cpp:176
StateMachine * getCurrentState()
Get current state machine.
Definition: Controller.cpp:107
virtual ~Controller()
Destructor.
Definition: Controller.cpp:80
StateMachine for Atlas robot.
Definition: StateMachine.hpp:46
bool mPelvisHarnessOn
Flag for pelvis harnessing.
Definition: Controller.hpp:126
void unharnessLeftFoot()
Harness the robot.
Definition: Controller.cpp:291
Controller(dart::dynamics::SkeletonPtr _atlasRobot, dart::dynamics::ConstraintSolver *_collisionSolver)
Constructor.
bool isAllowingControl() const
Get true iff this controller is currently allowing to control the Atlas robot.
Definition: Controller.cpp:162
ConstraintSolver manages constraints and computes constraint impulses.
Definition: ConstraintSolver.hpp:56
void setVerbosity(bool verbosity)
Set the verbosity.
Definition: Controller.cpp:340
dart::dynamics::SkeletonPtr mAtlasRobot
Atlas robot skeleton.
Definition: Controller.hpp:114
double mMaxPelvisHeight
Upper bound for emergency stop.
Definition: Controller.hpp:150
void harnessPelvis()
Harness the robot.
Definition: Controller.cpp:249
void unharnessPelvis()
Unharness the robot.
Definition: Controller.cpp:264
void harnessRightFoot()
Harness the robot.
Definition: Controller.cpp:304
void harnessLeftFoot()
Harness the robot.
Definition: Controller.cpp:277
void unharnessRightFoot()
Harness the robot.
Definition: Controller.cpp:318
std::size_t mCoronalRightHip
Index for coronal right hip.
Definition: Controller.hpp:138
std::size_t mSagitalRightHip
Index for sagital right hip.
Definition: Controller.hpp:144
StateMachine * mCurrentStateMachine
Current state machine.
Definition: Controller.hpp:123
BodyNode class represents a single node of the skeleton.
Definition: BodyNode.hpp:74
std::vector< StateMachine * > mStateMachines
List of state machines.
Definition: Controller.hpp:120
std::size_t mSagitalLeftHip
Index for sagital left hip.
Definition: Controller.hpp:141
double mMinPelvisHeight
Lower bound for emergency stop.
Definition: Controller.hpp:147
void printDebugInfo() const
Print debug information.
Definition: Controller.cpp:224
void changeStateMachine(StateMachine *_stateMachine, double _currentTime)
Change state to _stateMachine.
Definition: Controller.cpp:113
bool mLeftFootHarnessOn
Flag for left foot harnessing.
Definition: Controller.hpp:129
The Configuration struct represents the joint configuration of a Skeleton.
Definition: Skeleton.hpp:94
void resetRobot()
Reset the robot.
Definition: Controller.cpp:331
bool mRightFootHarnessOn
Flag for right foot harnessing.
Definition: Controller.hpp:132