step_queue.cpp
Go to the documentation of this file.
2 
3 
4 
5 namespace vigir_step_control
6 {
8 {
9 }
10 
12 {
13 }
14 
16 {
18  step_plan_.clear();
19  is_dirty_ = true;
20 }
21 
22 bool StepQueue::empty() const
23 {
25  return step_plan_.empty();
26 }
27 
28 size_t StepQueue::size() const
29 {
31  return step_plan_.size();
32 }
33 
34 bool StepQueue::isDirty() const
35 {
37  return is_dirty_;
38 }
39 
41 {
43  is_dirty_ = false;
44 }
45 
46 bool StepQueue::updateStepPlan(const msgs::StepPlan& step_plan, int min_step_index)
47 {
48  if (step_plan.steps.empty())
49  return true;
50 
52  msgs::ErrorStatus status = isConsistent(step_plan);
53  if (!isOk(status))
54  {
55  ROS_ERROR("[StepQueue] updateStepPlan: Consistency check failed!");
56  ROS_ERROR("%s", toString(status).c_str());
57  return false;
58  }
59 
60  unsigned int step_plan_start_index = std::max(min_step_index, step_plan.steps.front().step_index);
61 
63 
64  // step index has to start at 0, when step queue is empty
65  if (this->step_plan_.empty())
66  {
67  if (step_plan_start_index != 0)
68  {
69  ROS_ERROR("[StepQueue] updateStepPlan: Current step queue is empty. Expected step plan starting with index 0!");
70  return false;
71  }
72  }
73  else
74  {
75  msgs::Step old_step;
76  msgs::Step new_step;
77 
78  // check if queue and given step plan has overlapping steps
79  if (!this->step_plan_.getStep(old_step, step_plan_start_index))
80  {
81  ROS_ERROR("[StepQueue] updateStepPlan: Can't merge plan due to non-overlapping step indices of current step plan (max queued index: %i, needed index: %u)!", this->step_plan_.getLastStepIndex(), step_plan_start_index);
82  return false;
83  }
84  // check if input step plan has needed overlapping steps
85  else if (!StepPlan::getStep(new_step, step_plan, step_plan_start_index))
86  {
87  ROS_ERROR("[StepQueue] updateStepPlan: Can't merge plan due to non-overlapping step indices of new step plan (max index: %u, needed index: %u)!", step_plan.steps.back().step_index, step_plan_start_index);
88  return false;
89  }
90  // check if overlapping indeces have the same foot index
91  else if (old_step.foot.foot_index != new_step.foot.foot_index)
92  {
93  ROS_ERROR("[StepQueue] updateStepPlan: Step %u has wrong foot index!", step_plan_start_index);
94  return false;
95  }
96  // check if start foot position is equal
97  else
98  {
99  geometry_msgs::Pose p_old = old_step.foot.pose;
100  geometry_msgs::Pose p_new = new_step.foot.pose;
101  if (p_old.position.x != p_new.position.x || p_old.position.y != p_new.position.y || p_old.position.z != p_new.position.z)
102  {
103  ROS_WARN("[StepQueue] updateStepPlan: Overlapping step differs in position! Delta: %f/%f/%f", p_new.position.x-p_old.position.x, p_new.position.y-p_old.position.y, p_new.position.z-p_old.position.z);
104  }
105  if (p_old.orientation.x != p_new.orientation.x || p_old.orientation.y != p_new.orientation.y || p_old.orientation.z != p_new.orientation.z || p_old.orientation.w != p_new.orientation.w)
106  {
107  ROS_WARN("[StepQueue] updateStepPlan: Overlapping step differs in orientation! Delta: %f/%f/%f/%f", p_new.orientation.x-p_old.orientation.x, p_new.orientation.y-p_old.orientation.y, p_new.orientation.z-p_old.orientation.z, p_new.orientation.w-p_old.orientation.w);
108  }
109  }
110  }
111 
113  status += this->step_plan_.stitchStepPlan(step_plan, step_plan_start_index);
114  this->step_plan_.removeSteps(step_plan.steps.rbegin()->step_index+1);
115 
116  is_dirty_ = true;
117 
118  return isOk(status);
119 }
120 
121 bool StepQueue::getStep(msgs::Step& step, unsigned int step_index)
122 {
123  SharedLock lock(queue_mutex_);
124  return step_plan_.getStep(step, step_index);
125 }
126 
127 bool StepQueue::getStepAt(msgs::Step& step, unsigned int position)
128 {
129  SharedLock lock(queue_mutex_);
130  return step_plan_.getStepAt(step, position);
131 }
132 
133 std::vector<msgs::Step> StepQueue::getSteps(unsigned int start_index, unsigned int end_index) const
134 {
135  SharedLock lock(queue_mutex_);
136 
137  std::vector<msgs::Step> steps;
138 
139  for (unsigned int i = start_index; i <= end_index; i++)
140  {
141  msgs::Step step;
142  if (step_plan_.getStep(step, i))
143  steps.push_back(step);
144  }
145 
146  return steps;
147 }
148 
149 void StepQueue::removeStep(unsigned int step_index)
150 {
151  UniqueLock lock(queue_mutex_);
152  step_plan_.removeStep(step_index);
153  is_dirty_ = true;
154 }
155 
156 void StepQueue::removeSteps(unsigned int from_step_index, int to_step_index)
157 {
158  UniqueLock lock(queue_mutex_);
159  step_plan_.removeSteps(from_step_index, to_step_index);
160  is_dirty_ = true;
161 }
162 
163 bool StepQueue::popStep(msgs::Step& step)
164 {
165  UniqueLock lock(queue_mutex_);
166  is_dirty_ = true;
167  return step_plan_.popStep(step);
168 }
169 
171 {
172  msgs::Step step;
173  is_dirty_ = true;
174  return popStep(step);
175 }
176 
178 {
179  SharedLock lock(queue_mutex_);
180 
181  msgs::Step step;
182  if (step_plan_.getfirstStep(step))
183  return step.step_index;
184  else
185  return -1;
186 }
187 
189 {
190  SharedLock lock(queue_mutex_);
191 
192  msgs::Step step;
193  if (step_plan_.getLastStep(step))
194  return step.step_index;
195  else
196  return -1;
197 }
198 } // namespace
void removeStep(unsigned int step_index)
Remove steps with specific index from queue.
Definition: step_queue.cpp:149
int lastStepIndex() const
Returns last step index enqueued for execution.
Definition: step_queue.cpp:188
std::string toString(const StepControllerState &state)
bool getStepAt(msgs::Step &step, unsigned int position=0u)
Retrieves step of execution queue.
Definition: step_queue.cpp:127
bool empty() const
Checks if there are steps in queue.
Definition: step_queue.cpp:22
void removeSteps(unsigned int from_step_index, int to_step_index=-1)
Remove steps in the given range [from_step_index, to_step_index].
Definition: step_queue.cpp:156
#define ROS_WARN(...)
bool isDirty() const
Returns if step queue has been changed.
Definition: step_queue.cpp:34
int firstStepIndex() const
Returns next step index enqueued for execution.
Definition: step_queue.cpp:177
boost::unique_lock< Mutex > UniqueLock
Definition: step_queue.h:45
void clearDirtyFlag()
Resets dirty flag.
Definition: step_queue.cpp:40
bool updateStepPlan(const msgs::StepPlan &step_plan, int min_step_index=0)
Merges given step plan to the current execution queue of steps. Hereby, two cases have to considered:...
Definition: step_queue.cpp:46
std::vector< msgs::Step > getSteps(unsigned int start_index, unsigned int end_index) const
getSteps Retrieves all steps with index in range of [start_index; end_index]
Definition: step_queue.cpp:133
boost::shared_lock< Mutex > SharedLock
Definition: step_queue.h:44
#define ROS_ERROR(...)
size_t size() const
Returns size of step queue.
Definition: step_queue.cpp:28
bool getStep(msgs::Step &step, unsigned int step_index=0u)
Retrieves step of execution queue.
Definition: step_queue.cpp:121


vigir_step_control
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:44:47