O --- O
libPEDSIM Documentation
[HOME] [EXAMPLES] [ECOSYSTEM] [DOCUMENTATION] [DOWNLOAD]
O --- O
test_dynamics.cpp
1 #include "gtest/gtest.h"
2 
3 #include "ped_agent.h"
4 #include "ped_obstacle.h"
5 #include "ped_waypoint.h"
6 #include "ped_scene.h"
7 #include "ped_outputwriter.h"
8 
9 
36 
37 
73 
82 
104 
105 class DynamicsTest : public testing::Test {
106 public:
107  Ped::Tscene *pedscene;
108  Ped::Twaypoint *w1;
109  Ped::Twaypoint *w2;
110 
111  virtual void SetUp() {
112  const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info();
113  // printf("We are in test %s of test case %s.\n", test_info->name(), test_info->test_case_name());
114 
115  pedscene = new Ped::Tscene(-200, -200, 400, 400);
116  w1 = new Ped::Twaypoint(0, 0, 1);
117  w2 = new Ped::Twaypoint(50, 0, 10);
118 
119  // Ped::OutputWriter *ow = new Ped::FileOutputWriter(test_info->name());
121  pedscene->setOutputWriter(ow);
122  }
123 
124  virtual void TearDown() {
125  delete w1;
126  delete w2;
127  delete pedscene;
128  }
129 };
130 
131 
132 
141 TEST_F(DynamicsTest, moveNotIfNotAffected) {
142  Ped::Tagent *a = new Ped::Tagent();
143  a->setPosition(50, 20, 0);
144  pedscene->addAgent(a);
145 
146  for (int i=0; i<10; ++i) {
147  pedscene->moveAgents(0.2);
148  }
149 
150  vector<Ped::Tagent*> all = pedscene->getAllAgents();
151 
152  ASSERT_EQ(50, all[0]->getPosition().x);
153  ASSERT_EQ(20, all[0]->getPosition().y);
154  ASSERT_EQ( 0, all[0]->getPosition().z);
155 
156  // Cleanup
157  for (Ped::Tagent* agent : pedscene->getAllAgents()) delete agent;
158 }
160 
161 
168 TEST_F(DynamicsTest, moveTowardsWaypoint) {
169  Ped::Tagent *a = new Ped::Tagent();
170  a->setPosition(50, 0, 0);
171  a->addWaypoint(w1);
172  pedscene->addAgent(a);
173 
174  for (int i=0; i<10; ++i) {
175  pedscene->moveAgents(0.2);
176  }
177 
178  vector<Ped::Tagent*> all = pedscene->getAllAgents();
179 
180  ASSERT_GT(50, all.front()->getPosition().x);
181 
182  // Cleanup
183  for (Ped::Tagent* agent : pedscene->getAllAgents()) delete agent;
184 }
186 
187 
198 TEST_F(DynamicsTest, moveStopsAtLastWaypoint) {
199  Ped::Tagent *a = new Ped::Tagent();
200  a->setPosition(-50, 0, 0);
201  a->addWaypoint(w1);
202  a->setWaypointBehavior(Ped::Tagent::WaypointBehavior::BEHAVIOR_ONCE);
203  pedscene->addAgent(a);
204 
205  // Move all agents for some time steps
206  for (int i=0; i<200; ++i) { // It takes about 100 steps to reach the waypoint
207  pedscene->moveAgents(0.5); // Only low precision required for this
208  }
209 
210  vector<Ped::Tagent*> all = pedscene->getAllAgents();
211 
212  // The agent should be near the inner corner of the waypoint's
213  // radius. w1 is from -1 to +1 (radius 2)
214  EXPECT_NEAR(0.0, all.front()->getPosition().x, 2.0);
215  EXPECT_NEAR(0.0, all.front()->getPosition().y, 2.0);
216 
217  // Cleanup
218  for (Ped::Tagent* agent : pedscene->getAllAgents()) delete agent;
219 }
221 
222 
232 TEST_F(DynamicsTest, moveAxisStability) {
233  for (int i = 0; i<10; i++) {
234  Ped::Tagent *a = new Ped::Tagent();
235  a->setfactorlookaheadforce(0.0); // disable that
236  a->setPosition(0.1 * i, 1.0, 0.0);
237  pedscene->addAgent(a);
238  }
239 
240  // Move all agents for some steps, with very high precision (0.03).
241  for (int i=0; i<1000; ++i) {
242  pedscene->moveAgents(0.03);
243  }
244 
245  vector<Ped::Tagent*> all = pedscene->getAllAgents();
246 
247  // All agents should stay on y = 1.0 and move only horizontally on the x-axis.
248  for (Ped::Tagent* agent : pedscene->getAllAgents()) {
249  EXPECT_NEAR(1.0, agent->getPosition().y, 0.1);
250  }
251 
252  // Cleanup
253  for (Ped::Tagent* agent : pedscene->getAllAgents()) delete agent;
254 }
void addWaypoint(Twaypoint *wp)
Definition: ped_agent.cpp:94
void setPosition(double px, double py, double pz)
Definition: ped_agent.cpp:186
void setfactorlookaheadforce(double f)
Definition: ped_agent.cpp:224
O --- O

⁠(c) Christian Gloor [ c|h|g|l|o|o|r|@|s|i|l|m|a|r|i|l|.|o|r|g| ]