1 |
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 |
|
|
* Copyright Projet JRL-Japan, 2007 |
3 |
|
|
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 |
|
|
* |
5 |
|
|
* File: StepQueue.cpp |
6 |
|
|
* Project: SOT |
7 |
|
|
* Author: Paul Evrard, Nicolas Mansard |
8 |
|
|
* |
9 |
|
|
* Version control |
10 |
|
|
* =============== |
11 |
|
|
* |
12 |
|
|
* $Id$ |
13 |
|
|
* |
14 |
|
|
* Description |
15 |
|
|
* ============ |
16 |
|
|
* |
17 |
|
|
* StepQueue entity: manages a step queue (a series of future steps, |
18 |
|
|
* plus a series of changes in the future steps). |
19 |
|
|
* |
20 |
|
|
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
21 |
|
|
|
22 |
|
|
#include <dynamic-graph/factory.h> |
23 |
|
|
#include <sot/pattern-generator/step-queue.h> |
24 |
|
|
|
25 |
|
|
#include <sot/core/debug.hh> |
26 |
|
|
|
27 |
|
|
namespace dynamicgraph { |
28 |
|
|
namespace sot { |
29 |
|
|
|
30 |
|
|
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(StepQueue, "StepQueue"); |
31 |
|
|
|
32 |
|
|
FootPrint::FootPrint() : x(0.), y(0.), theta(0.), contact(CONTACT_RIGHT_FOOT) {} |
33 |
|
|
|
34 |
|
|
FootPrint::FootPrint(double nx, double ny, double ntheta, ContactName ncontact) |
35 |
|
|
: x(nx), y(ny), theta(ntheta), contact(ncontact) {} |
36 |
|
|
|
37 |
|
|
const unsigned int StepQueue::QUEUE_SIZE = 4; |
38 |
|
|
const double StepQueue::ZERO_STEP_POSITION = 0.19; |
39 |
|
|
const FootPrint StepQueue::START_FOOT_PRINT(0.0, -ZERO_STEP_POSITION / 2., 0.0, |
40 |
|
|
CONTACT_RIGHT_FOOT); |
41 |
|
|
|
42 |
|
|
StepQueue::StepQueue(const std::string &name) |
43 |
|
|
: Entity(name), footPrintList(), firstStepChanged(false) { |
44 |
|
|
startSequence(); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
void StepQueue::startSequence() { |
48 |
|
|
footPrintList.clear(); |
49 |
|
|
footPrintList.push_back(START_FOOT_PRINT); |
50 |
|
|
footPrintList.push_back( |
51 |
|
|
FootPrint(0., ZERO_STEP_POSITION, 0., CONTACT_LEFT_FOOT)); |
52 |
|
|
footPrintList.push_back( |
53 |
|
|
FootPrint(0., -ZERO_STEP_POSITION, 0., CONTACT_RIGHT_FOOT)); |
54 |
|
|
footPrintList.push_back( |
55 |
|
|
FootPrint(0., ZERO_STEP_POSITION, 0., CONTACT_LEFT_FOOT)); |
56 |
|
|
|
57 |
|
|
firstStepChanged = false; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
void StepQueue::pushStep(double x, double y, double theta) { |
61 |
|
|
FootPrint footprint; |
62 |
|
|
footprint.x = x; |
63 |
|
|
footprint.y = y; |
64 |
|
|
footprint.theta = theta; |
65 |
|
|
|
66 |
|
|
const FootPrint &last = footPrintList.back(); |
67 |
|
|
|
68 |
|
|
if (last.contact == CONTACT_LEFT_FOOT) { |
69 |
|
|
footprint.contact = CONTACT_RIGHT_FOOT; |
70 |
|
|
} else { |
71 |
|
|
footprint.contact = CONTACT_LEFT_FOOT; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
footPrintList.push_back(footprint); |
75 |
|
|
footPrintList.pop_front(); |
76 |
|
|
|
77 |
|
|
firstStepChanged = false; |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
void StepQueue::changeFirstStep(double x, double y, double theta) { |
81 |
|
|
firstStepChange.x = x; |
82 |
|
|
firstStepChange.y = y; |
83 |
|
|
firstStepChange.theta = theta; |
84 |
|
|
|
85 |
|
|
firstStepChanged = true; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
const FootPrint &StepQueue::getFirstStepChange() const { |
89 |
|
|
return firstStepChange; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
const FootPrint &StepQueue::getStep(unsigned int index) const { |
93 |
|
|
return footPrintList[index]; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
const FootPrint &StepQueue::getFirstStep() const { |
97 |
|
|
return footPrintList.front(); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
const FootPrint &StepQueue::getLastStep() const { return footPrintList.back(); } |
101 |
|
|
|
102 |
|
|
bool StepQueue::isFirstStepChanged() const { return firstStepChanged; } |
103 |
|
|
|
104 |
|
|
unsigned int StepQueue::size() const { return QUEUE_SIZE; } |
105 |
|
|
|
106 |
|
|
const FootPrint &StepQueue::getStartFootPrint() const { |
107 |
|
|
return START_FOOT_PRINT; |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
double StepQueue::getZeroStepPosition() const { return ZERO_STEP_POSITION; } |
111 |
|
|
|
112 |
|
|
void StepQueue::display(std::ostream &os) const { |
113 |
|
|
os << "StepQueue <" << getName() << ">:" << std::endl; |
114 |
|
|
|
115 |
|
|
for (size_t i = 0; i < footPrintList.size(); ++i) { |
116 |
|
|
const FootPrint &fp = footPrintList[i]; |
117 |
|
|
os << "step " << i << ": " << fp.contact << ", (" << fp.x << " " << fp.y |
118 |
|
|
<< " " << fp.theta << ")" << std::endl; |
119 |
|
|
} |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
void StepQueue::commandLine(const std::string &cmdLine, |
123 |
|
|
std::istringstream &cmdArgs, std::ostream &os) { |
124 |
|
|
if (cmdLine == "help") { |
125 |
|
|
os << "StepQueue: " << std::endl << std::endl; |
126 |
|
|
} else { |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
} // namespace sot |
131 |
|
|
} // namespace dynamicgraph |