NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AppObstacleTest.cpp
Go to the documentation of this file.
1 /*
2 * Copyright © 2012, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
4 * All rights reserved.
5 *
6 * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7 * under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15 * either express or implied. See the License for the specific language
16 * governing permissions and limitations under the License.
17 */
24 // This application
25 #include "tgBlockField.h"
26 #include "tgStairs.h"
27 // This library
31 #include "core/tgModel.h"
32 #include "core/tgSimViewGraphics.h"
33 #include "core/tgSimulation.h"
34 #include "core/tgWorld.h"
35 #include "tgcreator/tgUtil.h"
36 
37 // The Bullet Physics Library
38 #include "LinearMath/btVector3.h"
39 #include "LinearMath/btQuaternion.h"
40 // The C++ Standard Library
41 #include <iostream>
48 int main(int argc, char** argv)
49 {
50 
51  std::cout << "AppObstacleTest" << std::endl;
52 
53  // First create the ground and world. Specify ground rotation in radians
54  const double yaw = 0.0;
55  const double pitch = 0.0;
56  const double roll = 0.0;
57  const tgBoxGround::Config groundConfig(btVector3(yaw, pitch, roll));
58 
59  // the world will delete this
60  tgBoxGround* ground = new tgBoxGround(groundConfig);
61 
62  btVector3 eulerAngles = btVector3(0.0, 0.0, 0.0);
63  btScalar friction = 0.5;
64  btScalar restitution = 0.0;
65  // Size doesn't affect hilly terrain
66  btVector3 size = btVector3(0.0, 0.1, 0.0);
67  btVector3 origin = btVector3(0.0, 0.0, 0.0);
68  size_t nx = 100;
69  size_t ny = 100;
70  double margin = 0.5;
71  double triangleSize = 5.0;
72  double waveHeight = 3.0;
73  double offset = 0.0;
74  tgHillyGround::Config hillGroundConfig(eulerAngles, friction, restitution,
75  size, origin, nx, ny, margin, triangleSize,
76  waveHeight, offset);
77 
78 
79  const tgWorld::Config config(98.1); // gravity, cm/sec^2
80  tgWorld world(config, ground);
81 
82  // Second create the view
83  const double timestep_physics = 1.0/1000.0; // seconds
84  const double timestep_graphics = 1.f/60.f; // seconds
85  tgSimView view(world, timestep_physics, timestep_graphics);
86 
87  // Third create the simulation
88  tgSimulation simulation(view);
89 
90  btVector3 position(0.0, 0.0, 0.0);
91 
92  // Fourth create the models with their controllers and add the models to the
93  // simulation
94  tgBlockField* myObstacle = new tgBlockField();
95  // Add the model to the world
96  simulation.addModel(myObstacle);
97 
98  tgStairs* bigStairs = new tgStairs();
99  // Add the stairs to the world
100  simulation.addObstacle(bigStairs);
101 
102  for (int i = 0; i < 3; i++)
103  {
104 
105  simulation.run(10);
106 
107  if (i %2 == 0)
108  {
109  // World will delete prior pointer, so make a new one each time
110  tgHillyGround* hillGround = new tgHillyGround(hillGroundConfig);
111  simulation.reset(hillGround);
112  }
113  else
114  {
115  ground = new tgBoxGround(groundConfig);
116  simulation.reset(ground);
117  }
118  }
119  return 0;
120 }
void addObstacle(tgModel *pObstacle)
Contains the definition of class tgHillyGround.
Contains the definition of class tgStairs. A random field of blocks used to test tensegrities.
void addModel(tgModel *pModel)
Contains the definition of class tgSimulation.
Contains the definition of class tgModel.
Contains the definition of class tgSimViewGraphics.
Contains the definition of class tgBlockField. A random field of blocks used to test tensegrities...
Contains the definition of class tgWorld $Id$.
void run() const
Contains the definition of class tgBoxGround.
int main(int argc, char **argv)
Rand seeding simular to the evolution and terrain classes.
Contains the definition of class tgEmptyGround.