NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
standing_demo_fsm.h
1 // Motion demonstration on a standing robot, copied from standing_demo
2 // Authors: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 // Sebastian Schüller <schuell1@cs.uni-bonn.de>
4 
5 // Ensure header is only included once
6 #ifndef STANDING_DEMO_FSM_H
7 #define STANDING_DEMO_FSM_H
8 
9 // Includes
11 #include <limb_control/PlayCommandsSrv.h>
12 #include <ros/time.h>
13 
14 // Standing demo namespace
15 namespace standing_demo
16 {
17  // Namespaces
18  using namespace statecontroller;
19 
20  // Class forward-declarations
21  class StandingDemo;
22 
23  // State controller
24  class StandingDemoSC;
25 
26  // States
27  class InitDemoState;
28  class WaitForStandingState;
29  class WaitForTimeState;
30  class WaitForMotionPlayerState;
31  class PlanDemoActionState;
32 
33  // State IDs
34  enum SDSCStateID
35  {
36  INIT_DEMO, // Initialise the standing demo
37  WAIT_FOR_STANDING, // Wait until the robot enters the standing state
38  WAIT_FOR_TIME, // Wait for a given number of seconds, or until a certain absolute time has been reached
39  WAIT_FOR_MOTION_PLAYER, // Wait for the motion player to finish whatever it's doing
40  WAIT_FOR_LIMB_CONTROL, // Wait for limb control to finish doing whatever it's doing
41  PLAN_DEMO_ACTION, // Plan a sequence of states that comprises a demo action
42  RETURN_TO_STANDING, // Return to the standing pose in terms of the head, arm, knee and ankle servos
43  START_MOTION_PLAYBACK, // Start the playback of a motion using the motion player
44  STOP_MOTION_PLAYBACK, // Wait for motion playback using the motion player to cease
45  START_HEAD_IDLING, // Start the head idling background behaviour
46  STOP_HEAD_IDLING // Stop the head idling background behaviour
47  };
48 
49  // Standing demo state controller
50  class StandingDemoSC : public StateController
51  {
52  public:
53  // Constructors
54  StandingDemoSC(StandingDemo* SD);
55 
56  // Pointer to main standing demo object
57  StandingDemo* const m_SD;
58 
59  // State controller callbacks
60  virtual bool preStepCallback();
61  virtual void preActivateCallback(bool willCallActivate);
62  virtual void preExecuteCallback();
63 
64  // Get functions
65  inline const ros::Time& now() const { return m_curStepTime; }
66 
67  protected:
68  // Background motion enable/disable functions
69  void enableHeadIdle();
70  void disableHeadIdle();
71 
72  // Background motion handlers
73  void handleLegDangle();
74  void handleHeadIdle();
75 
76  // Head idle variables
77  bool m_headIdleEnabled;
78 
79  // Internal variables
80  ros::Time m_curStepTime;
81  };
82 
83  // Init demo state
84  class InitDemoState : public GenState<StandingDemoSC>
85  {
86  public:
87  // Constructor
88  InitDemoState(StandingDemoSC *sc) : GenState(sc, INIT_DEMO, "INIT_DEMO") {}
89 
90  protected:
91  // State callbacks
92  virtual action_t execute(cycle_t cyc);
93  };
94 
95  // Wait for standing state
96  class WaitForStandingState : public GenState<StandingDemoSC>
97  {
98  public:
99  // Constructor
100  WaitForStandingState(StandingDemoSC *sc) : GenState(sc, WAIT_FOR_STANDING, "WAIT_FOR_STANDING") {}
101 
102  protected:
103  // State callbacks
104  virtual action_t execute(cycle_t cyc);
105  };
106 
107  // Wait for time state
108  class WaitForTimeState : public GenState<StandingDemoSC>
109  {
110  public:
111  // Constants
112  static const ros::Time NullROSTime;
113 
114  // Constructor
115  WaitForTimeState(StandingDemoSC* sc, double waitTime, ros::Time endTime = NullROSTime) : GenState(sc, WAIT_FOR_TIME, "WAIT_FOR_TIME"), m_waitTime(waitTime), m_endTime(endTime) {}
116 
117  protected:
118  // State callbacks
119  virtual void activate(cycle_t cyc);
120  virtual action_t execute(cycle_t cyc);
121 
122  // State parameters
123  double m_waitTime;
124  ros::Time m_endTime;
125  };
126 
127  // Wait for motion player state
128  class WaitForMotionPlayerState : public GenState<StandingDemoSC>
129  {
130  public:
131  // Constructor
132  WaitForMotionPlayerState(StandingDemoSC *sc) : GenState(sc, WAIT_FOR_MOTION_PLAYER, "WAIT_FOR_MOTION_PLAYER") {}
133 
134  protected:
135  // State callbacks
136  virtual action_t execute(cycle_t cyc);
137  };
138 
139  // Wait for limb control state
140  class WaitForLimbControlState : public GenState<StandingDemoSC>
141  {
142  public:
143  // Constructor
144  WaitForLimbControlState(StandingDemoSC *sc) : GenState(sc, WAIT_FOR_LIMB_CONTROL, "WAIT_FOR_LIMB_CONTROL") {}
145 
146  protected:
147  // State callbacks
148  virtual action_t execute(cycle_t cyc);
149 
150  // State variables
151  const limb_control::PlayCommandsRequest PCmdReqNull;
152  };
153 
154  // Plan action state
155  class PlanDemoActionState : public GenState<StandingDemoSC>
156  {
157  public:
158  // Constructor
159  PlanDemoActionState(StandingDemoSC* sc) : GenState(sc, PLAN_DEMO_ACTION, "PLAN_DEMO_ACTION") {}
160 
161  protected:
162  // State callbacks
163  virtual action_t execute(cycle_t cyc);
164  };
165 
166  // Return to standing state
167  class ReturnToStandingState : public GenState<StandingDemoSC>
168  {
169  public:
170  // Constructor
171  ReturnToStandingState(StandingDemoSC* sc) : GenState(sc, RETURN_TO_STANDING, "RETURN_TO_STANDING") {}
172 
173  protected:
174  // State callbacks
175  virtual void activate(cycle_t cyc);
176  virtual action_t execute(cycle_t cyc);
177 
178  // State variables
179  limb_control::PlayCommandsRequest PCmdReq;
180  };
181 
182  // Start motion playback state
183  class StartMotionPlaybackState : public GenState<StandingDemoSC>
184  {
185  public:
186  // Constructor
187  StartMotionPlaybackState(StandingDemoSC *sc, int motion) : GenState(sc, START_MOTION_PLAYBACK, "START_MOTION_PLAYBACK"), m_motion(motion) {}
188 
189  protected:
190  // State callbacks
191  virtual void activate(cycle_t cyc);
192  virtual action_t execute(cycle_t cyc);
193 
194  // State parameters
195  const int m_motion;
196  };
197 
198  // Stop motion playback state
199  class StopMotionPlaybackState : public GenState<StandingDemoSC>
200  {
201  public:
202  // Constructor
203  StopMotionPlaybackState(StandingDemoSC *sc) : GenState(sc, STOP_MOTION_PLAYBACK, "STOP_MOTION_PLAYBACK") {}
204 
205  protected:
206  // State callbacks
207  virtual action_t execute(cycle_t cyc);
208  };
209 
210  // Start head idling state
211  class StartHeadIdlingState : public GenState<StandingDemoSC>
212  {
213  public:
214  // Constructor
215  StartHeadIdlingState(StandingDemoSC *sc) : GenState(sc, START_HEAD_IDLING, "START_HEAD_IDLING") {}
216 
217  protected:
218  // State callbacks
219  virtual void activate(cycle_t cyc);
220  virtual action_t execute(cycle_t cyc);
221  };
222 
223  // Stop head idling state
224  class StopHeadIdlingState : public GenState<StandingDemoSC>
225  {
226  public:
227  // Constructor
228  StopHeadIdlingState(StandingDemoSC *sc) : GenState(sc, STOP_HEAD_IDLING, "STOP_HEAD_IDLING") {}
229 
230  protected:
231  // State callbacks
232  virtual void activate(cycle_t cyc);
233  virtual action_t execute(cycle_t cyc);
234  };
235 }
236 
237 #endif
Implements the State Controller Library.
Base class for all state controllers.
Definition: state_controller.h:593
unsigned int cycle_t
Used to count the number of executed state controller cycles.
Definition: state_controller.h:415
bool action_t
Used to represent the state transition actions (HOLD_THIS_STATE and PROCEED_NEXT_STATE) ...
Definition: state_controller.h:416
Specialises the State class using templates to take care of the most common overloads.
Definition: state_controller.h:397