NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AppEscape_T6.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  */
18 
26 // This application
27 #include "Escape_T6Model.h"
28 #include "Escape_T6Controller.h"
29 
30 // This library
32 #include "Crater.h"
33 #include "CraterDeep.h"
34 #include "core/tgModel.h"
35 #include "core/tgSimViewGraphics.h"
36 #include "core/tgSimulation.h"
37 #include "core/tgWorld.h"
38 
39 // Bullet Physics
40 #include "LinearMath/btVector3.h"
41 
42 // The C++ Standard Library
43 #include <iostream>
44 
45 tgBoxGround *createGround();
46 tgWorld *createWorld();
49 void simulate(tgSimulation *simulation);
50 
59 int main(int argc, char** argv)
60 {
61  std::cout << "AppEscape_T6" << std::endl;
62 
63  // First create the world
64  tgWorld *world = createWorld();
65 
66  // Second create the view
67  //tgSimViewGraphics *view = createGraphicsView(world); // For visual experimenting on one tensegrity
68  tgSimView *view = createView(world); // For running multiple episodes
69 
70  // Third create the simulation
71  tgSimulation *simulation = new tgSimulation(*view);
72 
73  // Fourth create the models with their controllers and add the models to the simulation
74  Escape_T6Model* const model = new Escape_T6Model();
75 
76  // Fifth create controller and attach it to the model
77  double initialLength = 9.0; // decimeters
78  Escape_T6Controller* const controller = new Escape_T6Controller(initialLength);
79  model->attach(controller);
80 
81  //Sixth add model (with controller) to simulation
82  simulation->addModel(model);
83 
84  //Seventh add crater to simulation
85  btVector3 originCrater = btVector3(0,0,0);
86  //Crater* crater = new Crater(originCrater);
87  CraterDeep* crater = new CraterDeep(originCrater);
88  simulation->addModel(crater);
89 
90  simulate(simulation);
91 
92  delete controller;
93  //Teardown is handled by delete, so that should be automatic
94  return 0;
95 }
96 
97 tgBoxGround *createGround() {
98  // Determine the angle of the ground in radians. All 0 is flat
99  const double yaw = 0.0;
100  const double pitch = 0.0;
101  const double roll = 0.0;
102  const btVector3 eulerAngles = btVector3(yaw, pitch, roll); // Default: (0.0, 0.0, 0.0)
103  const double friction = 0.5; // Default: 0.5
104  const double restitution = 0.0; // Default: 0.0
105  const btVector3 size = btVector3(10000.0, 2, 10000.0); // Default: (500.0, 1.5, 500.0)
106  const btVector3 origin = btVector3(0.0, 0.0, 0.0); // Default: (0.0, 0.0, 0.0)
107  const tgBoxGround::Config groundConfig(eulerAngles, friction, restitution,
108  size, origin);
109  // the world will delete this
110  return new tgBoxGround(groundConfig);
111 }
112 
113 tgWorld *createWorld() {
114  const tgWorld::Config config(98.1); // gravity, cm/sec^2 Use this to adjust length scale of world.
115  // NB: by changing the setting below from 981 to 98.1, we've
116  // scaled the world length scale to decimeters not cm.
117 
118  tgBoxGround* ground = createGround();
119  return new tgWorld(config, ground);
120 }
121 
124  const double timestep_physics = 1.0 / 60.0 / 10.0; // Seconds
125  const double timestep_graphics = 1.f /60.f; // Seconds, AKA render rate. Leave at 1/60 for real-time viewing
126  return new tgSimViewGraphics(*world, timestep_physics, timestep_graphics);
127 }
128 
131  const double timestep_physics = 1.0 / 60.0 / 10.0; // Seconds
132  const double timestep_graphics = 1.f /60.f; // Seconds, AKA render rate. Leave at 1/60 for real-time viewing
133  return new tgSimView(*world, timestep_physics, timestep_graphics);
134 }
135 
137 void simulate(tgSimulation *simulation) {
138  int nEpisodes = 1; // Number of episodes ("trial runs")
139  int nSteps = 60000; // Number of steps in each episode, 60k is 100 seconds (timestep_physics*nSteps)
140  for (int i=0; i<nEpisodes; i++) {
141  simulation->run(nSteps);
142  simulation->reset();
143  }
144 }
145 
int main(int argc, char **argv)
Contains the definition of class Escape_T6Model. $Id$.
tgSimViewGraphics * createGraphicsView(tgWorld *world)
void addModel(tgModel *pModel)
tgSimView * createView(tgWorld *world)
Contains the definition of class tgSimulation.
Contains the definition of class tgModel.
Contains the definition of class tgSimViewGraphics.
Contains the definition of class Crater. Specifically, a crater is defined as a series of boxes which...
Contains the definition of class tgWorld $Id$.
void simulate(tgSimulation *simulation)
void run() const
Contains the definition of class tgBoxGround.
void attach(tgObserver< T > *pObserver)
Definition: tgSubject.h:91
Contains the definition of class CraterDeep. Specifically, this crater is defined as a series of boxe...