step_plan_utest.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 
3 #include <math.h>
4 
5 #include <gtest/gtest.h>
6 
9 
10 
11 
12 using namespace vigir_footstep_planning;
13 
14 msgs::StepPlan genStepPlan(geometry_msgs::Pose start, unsigned int steps, unsigned int foot_index = msgs::Foot::LEFT, unsigned int start_step_index = 0, bool closing_step = true)
15 {
16  msgs::StepPlan step_plan;
17 
18  double yaw = tf::getYaw(start.orientation);
19 
20  // generate initial step
21  msgs::Step step;
22  step.foot.foot_index = foot_index;
23  step.foot.pose = start;
24  step.step_index = start_step_index;
25  step.valid = true;
26 
27  step_plan.steps.push_back(step);
28 
29  // add extra step when closing step is set
30  if (closing_step)
31  steps++;
32 
33  for (unsigned int i = 0; i < steps; i++)
34  {
35  // alternate left and right foot pose
36  if (step.foot.foot_index == msgs::Foot::RIGHT)
37  {
38  step.foot.foot_index = msgs::Foot::LEFT;
39  step.foot.pose.position.x += 0.2 * -sin(yaw);
40  step.foot.pose.position.y += 0.2 * cos(yaw);
41  }
42  else
43  {
44  step.foot.foot_index = msgs::Foot::RIGHT;
45  step.foot.pose.position.x += -0.2 * -sin(yaw);
46  step.foot.pose.position.y += -0.2 * cos(yaw);
47  }
48 
49  // forward movement
50  // closing step handling
51  if (!closing_step || i < steps-1)
52  {
53  step.foot.pose.position.x += 0.25 * cos(yaw);
54  step.foot.pose.position.y += 0.25 * sin(yaw);
55  }
56 
57  step.step_index++;
58 
59  step_plan.steps.push_back(step);
60  }
61  return step_plan;
62 }
63 
64 // Test for checking if appendStepPlan generates correct results
65 TEST(StepPlan, appendStepPlan)
66 {
67  geometry_msgs::Pose start;
68  start.position.x = 1.0;
69  start.position.z = 1.0;
70  start.orientation = tf::createQuaternionMsgFromYaw(0.0);
71 
72  // generate plan 1: 4 steps, no closing step
73  msgs::StepPlan step_plan_1 = genStepPlan(start, 4, msgs::Foot::LEFT, 0, false);
74 
75  // generate plan 2: 6 steps, starting from last step of step_plan_1
76  msgs::StepPlan step_plan_2 = genStepPlan(step_plan_1.steps.back().foot.pose, 6, msgs::Foot::LEFT);
77  step_plan_2.steps.erase(step_plan_2.steps.begin());
78 
79  // append plan 1 and 2
80  StepPlan step_plan_result(step_plan_1);
81  step_plan_result.appendStepPlan(step_plan_2);
82  ASSERT_EQ(12, step_plan_result.size());
83 
84  // generate expected step plan
85  StepPlan step_plan_exp(genStepPlan(start, 10));
86  ASSERT_EQ(12, step_plan_exp.size());
87 
88  // compare
89  isEqualTest(step_plan_exp, step_plan_result);
90 }
91 
92 // Test for checking if updateStepPlan generates correct results
93 TEST(StepPlan, updateStepPlan)
94 {
95  geometry_msgs::Pose start;
96  start.position.x = 1.0;
97  start.position.z = 1.0;
98  start.orientation = tf::createQuaternionMsgFromYaw(0.0);
99 
100  // generate plan 1: 6 steps
101  msgs::StepPlan step_plan_1 = genStepPlan(start, 6, msgs::Foot::LEFT);
102 
103  // generate plan 2: 8 steps, starting from step #3 of step_plan_1
104  msgs::StepPlan step_plan_2 = genStepPlan(step_plan_1.steps[3].foot.pose, 8, msgs::Foot::RIGHT, 3);
105 
106  // update plan 1 with 2
107  StepPlan step_plan_result(step_plan_1);
108  step_plan_result.updateStepPlan(step_plan_2);
109  ASSERT_EQ(13, step_plan_result.size());
110 
111  // generate expected step plan
112  StepPlan step_plan_exp(genStepPlan(start, 11));
113  ASSERT_EQ(13, step_plan_exp.size());
114 
115  for (size_t i = 3; i < 8; i++)
116  {
117  msgs::Step step;
118  EXPECT_TRUE(step_plan_exp.getStep(step, i));
119  step_plan_exp.updateStep(step);
120  }
121 
122  // compare
123  isEqualTest(step_plan_exp, step_plan_result);
124 }
125 
126 // Test for checking if stitchStepPlan generates correct results
127 TEST(StepPlan, stitchStepPlan)
128 {
129  geometry_msgs::Pose start_1;
130  start_1.position.x = 1.0;
131  start_1.position.y = 1.1;
132  start_1.position.z = 1.0;
133  start_1.orientation = tf::createQuaternionMsgFromYaw(M_PI_4);
134 
135  // generate plan 1: 6 steps
136  msgs::StepPlan step_plan_1 = genStepPlan(start_1, 6);
137 
138  geometry_msgs::Pose start_2;
139  start_2.position.x = 2.1;
140  start_2.position.y = 1.0;
141  start_2.position.z = 1.0;
142  start_2.orientation = tf::createQuaternionMsgFromYaw(1.0);
143 
144  // generate plan 2: 6 steps
145  msgs::StepPlan step_plan_2 = genStepPlan(start_2, 6, msgs::Foot::RIGHT, 3);
146 
147  // stitch plan 1 with 2
148  StepPlan step_plan_result(step_plan_1);
149  step_plan_result.stitchStepPlan(step_plan_2, 3);
150  ASSERT_EQ(11, step_plan_result.size());
151 
152  // generate expected step plan
153  StepPlan step_plan_exp(genStepPlan(start_1, 9));
154  ASSERT_EQ(11, step_plan_exp.size());
155 
156  for (size_t i = 3; i < 8; i++)
157  {
158  msgs::Step step;
159  EXPECT_TRUE(step_plan_exp.getStep(step, i));
160  step_plan_exp.updateStep(step);
161  }
162 
163  // compare
164  isEqualTest(step_plan_exp, step_plan_result);
165 }
static double getYaw(const Quaternion &bt_q)
TEST(StepPlan, appendStepPlan)
msgs::ErrorStatus appendStepPlan(const msgs::StepPlan &step_plan)
Appends a step plan to current step plan. No transformation will be done!
Definition: step_plan.cpp:188
msgs::StepPlan genStepPlan(geometry_msgs::Pose start, unsigned int steps, unsigned int foot_index=msgs::Foot::LEFT, unsigned int start_step_index=0, bool closing_step=true)
void isEqualTest(const std_msgs::String &exp, const std_msgs::String &res)
unsigned int step
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
msgs::ErrorStatus updateStepPlan(const msgs::StepPlan &step_plan)
Merges the given step plan to current step plan. Already exisiting steps will be tagged as modified...
Definition: step_plan.cpp:210
msgs::ErrorStatus stitchStepPlan(const msgs::StepPlan &step_plan, int step_index=0)
Stitches the given step plan into the current step plan starting at step_index. Hereby the all in ran...
Definition: step_plan.cpp:230


vigir_footstep_planning_msgs
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:45:25