1 |
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 |
|
|
* Copyright Projet JRL-Japan, 2007 |
3 |
|
|
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 |
|
|
* |
5 |
|
|
* File: StepTimeLine.h |
6 |
|
|
* Project: SOT |
7 |
|
|
* Author: Nicolas Mansard, Olivier Stasse, Paul Evrard |
8 |
|
|
* |
9 |
|
|
* Version control |
10 |
|
|
* =============== |
11 |
|
|
* |
12 |
|
|
* $Id$ |
13 |
|
|
* |
14 |
|
|
* Description |
15 |
|
|
* ============ |
16 |
|
|
* |
17 |
|
|
* StepTimeLine entity: synchronizes a StepQueue, a StepComputer and a |
18 |
|
|
* PGManager to compute steps to send to the PG. Uses a StepChecker |
19 |
|
|
* to clip the steps. |
20 |
|
|
* Highest-level class for automatic step generation. |
21 |
|
|
* |
22 |
|
|
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
23 |
|
|
|
24 |
|
|
#ifndef __SOT_STEP_TIME_LINE_H__ |
25 |
|
|
#define __SOT_STEP_TIME_LINE_H__ |
26 |
|
|
|
27 |
|
|
/* --------------------------------------------------------------------- */ |
28 |
|
|
/* --- INCLUDE --------------------------------------------------------- */ |
29 |
|
|
/* --------------------------------------------------------------------- */ |
30 |
|
|
|
31 |
|
|
#include <pinocchio/fwd.hpp> |
32 |
|
|
|
33 |
|
|
/* SOT */ |
34 |
|
|
#include <dynamic-graph/entity.h> |
35 |
|
|
#include <dynamic-graph/signal-ptr.h> |
36 |
|
|
#include <dynamic-graph/signal-time-dependent.h> |
37 |
|
|
#include <sot/pattern-generator/pg-manager.h> |
38 |
|
|
#include <sot/pattern-generator/step-computer.h> |
39 |
|
|
#include <sot/pattern-generator/step-queue.h> |
40 |
|
|
|
41 |
|
|
/* --------------------------------------------------------------------- */ |
42 |
|
|
/* --- API ------------------------------------------------------------- */ |
43 |
|
|
/* --------------------------------------------------------------------- */ |
44 |
|
|
|
45 |
|
|
#if defined(WIN32) |
46 |
|
|
#if defined(step_time_line_EXPORTS) |
47 |
|
|
#define StepTimeLine_EXPORT __declspec(dllexport) |
48 |
|
|
#else |
49 |
|
|
#define StepTimeLine_EXPORT __declspec(dllimport) |
50 |
|
|
#endif |
51 |
|
|
#else |
52 |
|
|
#define StepTimeLine_EXPORT |
53 |
|
|
#endif |
54 |
|
|
|
55 |
|
|
namespace dynamicgraph { |
56 |
|
|
namespace sot { |
57 |
|
|
|
58 |
|
|
/* --------------------------------------------------------------------- */ |
59 |
|
|
/* --- CLASS ----------------------------------------------------------- */ |
60 |
|
|
/* --------------------------------------------------------------------- */ |
61 |
|
|
|
62 |
|
|
/// Synchronizes the components for the automatic step generation. |
63 |
|
|
/// |
64 |
|
|
/// This entity automatically generates steps to send to a PatternGenerator |
65 |
|
|
/// entity. The responsibility of this entity is to synchronize all the |
66 |
|
|
/// components that are used to generate and send the steps, by triggering |
67 |
|
|
/// them at the appropriate time. |
68 |
|
|
/// |
69 |
|
|
/// This entity accepts the following shell commands: |
70 |
|
|
/// - state: stepper.state will print the current state of the timeline, |
71 |
|
|
/// stepper.state start will start the stepping, |
72 |
|
|
/// stepper.state stop will stop the stepping. |
73 |
|
|
/// |
74 |
|
|
/// The possible states of the timeline are the following: |
75 |
|
|
/// - starting: playing an initial step sequence (warmup), |
76 |
|
|
/// - started: generating steps using the StepComputer, |
77 |
|
|
/// - stopping: playing a final step sequence (cleanup), |
78 |
|
|
/// - stopped: doing nothing (not sending steps). |
79 |
|
|
/// |
80 |
|
|
/// \note{This entity class can not be instantiated in a shell since it does |
81 |
|
|
/// not register any factory. This behavior is intended.} |
82 |
|
|
class StepTimeLine_EXPORT StepTimeLine : public Entity { |
83 |
|
|
public: // Entity name |
84 |
|
|
static const std::string CLASS_NAME; |
85 |
|
|
virtual const std::string &getClassName(void) const { return CLASS_NAME; } |
86 |
|
|
|
87 |
|
|
private: |
88 |
|
|
static const unsigned int PERIOD_DEFAULT; |
89 |
|
|
|
90 |
|
|
/// Zero-based index of the first step to modify. The 0-th step |
91 |
|
|
/// is the very first step sent at the STARTING state. |
92 |
|
|
static const unsigned int FIRST_STEP_TO_MODIFY; |
93 |
|
|
|
94 |
|
|
public: // Construction |
95 |
|
|
StepTimeLine(const std::string &name); |
96 |
|
|
|
97 |
|
|
public: // Trigger |
98 |
|
|
/// Trigger signal, to be updated periodically to trigger a |
99 |
|
|
/// call to the synchronization method. Typically, this signal |
100 |
|
|
/// is added to the periodic calls of OpenHRP. |
101 |
|
|
Signal<int, int> triggerSOUT; |
102 |
|
|
|
103 |
|
|
/// The trigger callback function, which implements the synchronization |
104 |
|
|
/// of all the sub-components used to generate and send the steps. |
105 |
|
|
int &triggerCall(int &dummy, int timeCurr); |
106 |
|
|
|
107 |
|
|
private: // State |
108 |
|
|
enum SteppingState { |
109 |
|
|
STATE_STARTING, ///< Introducing 4 steps then switches to STATE_STARTED. |
110 |
|
|
STATE_STOPPING, ///< Running but stop requested: introduce a last step |
111 |
|
|
/// and stop. |
112 |
|
|
STATE_STARTED, ///< Running, simply introduce steps. |
113 |
|
|
STATE_STOPPED ///< Nothing to do, cannot introduce steps in the FIFO |
114 |
|
|
}; |
115 |
|
|
|
116 |
|
|
public: // Entity |
117 |
|
|
virtual void display(std::ostream &os) const; |
118 |
|
|
virtual void commandLine(const std::string &cmdLine, |
119 |
|
|
std::istringstream &cmdArgs, std::ostream &os); |
120 |
|
|
|
121 |
|
|
private: |
122 |
|
|
StepQueue *stepQueue; |
123 |
|
|
StepComputer *stepComputer; |
124 |
|
|
PGManager *pgManager; |
125 |
|
|
|
126 |
|
|
SteppingState state; |
127 |
|
|
int timeLastIntroduction; |
128 |
|
|
int period; |
129 |
|
|
unsigned int nStartingSteps; |
130 |
|
|
}; |
131 |
|
|
|
132 |
|
|
} // namespace sot |
133 |
|
|
} // namespace dynamicgraph |
134 |
|
|
|
135 |
|
|
#endif |