NTRT Simulator  Version: Master
 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  #if(1)
68  tgSimViewGraphics *view = createGraphicsView(world); // For visual experimenting on one tensegrity
69  #else
70  tgSimView *view = createView(world); // For running multiple episodes
71  #endif
72 
73  // Third create the simulation
74  tgSimulation *simulation = new tgSimulation(*view);
75 
76  // Fourth create the models with their controllers and add the models to the simulation
77  Escape_T6Model* const model = new Escape_T6Model();
78 
79  /* Required for setting up learning file input/output. */
80  const std::string suffix((argc > 1) ? argv[1] : "default");
81 
82  // Fifth create controller and attach it to the model
83  double initialLength = 9.0; // decimeters
84  Escape_T6Controller* const controller = new Escape_T6Controller(initialLength,
85  suffix,
86  "craterEscape/",
87  "Config.ini");
88  model->attach(controller);
89 
90  //Sixth add model (with controller) to simulation
91  simulation->addModel(model);
92 
93  //Seventh add crater to simulation
94  btVector3 originCrater = btVector3(0,0,0);
95  //Crater* crater = new Crater(originCrater);
96  CraterDeep* crater = new CraterDeep(originCrater);
97  simulation->addModel(crater);
98 
99  simulate(simulation);
100 
101  delete controller;
102  //Teardown is handled by delete, so that should be automatic
103  return 0;
104 }
105 
106 tgBoxGround *createGround() {
107  // Determine the angle of the ground in radians. All 0 is flat
108  const double yaw = 0.0;
109  const double pitch = 0.0;
110  const double roll = 0.0;
111  const btVector3 eulerAngles = btVector3(yaw, pitch, roll); // Default: (0.0, 0.0, 0.0)
112  const double friction = 0.5; // Default: 0.5
113  const double restitution = 0.0; // Default: 0.0
114  const btVector3 size = btVector3(10000.0, 2, 10000.0); // Default: (500.0, 1.5, 500.0)
115  const btVector3 origin = btVector3(0.0, 0.0, 0.0); // Default: (0.0, 0.0, 0.0)
116  const tgBoxGround::Config groundConfig(eulerAngles, friction, restitution,
117  size, origin);
118  // the world will delete this
119  return new tgBoxGround(groundConfig);
120 }
121 
122 tgWorld *createWorld() {
123  const tgWorld::Config config(98.1); // gravity, cm/sec^2 Use this to adjust length scale of world.
124  // NB: by changing the setting below from 981 to 98.1, we've
125  // scaled the world length scale to decimeters not cm.
126 
127  tgBoxGround* ground = createGround();
128  return new tgWorld(config, ground);
129 }
130 
133  const double timestep_physics = 1.0 / 60.0 / 10.0; // Seconds
134  const double timestep_graphics = 1.f /60.f; // Seconds, AKA render rate. Leave at 1/60 for real-time viewing
135  return new tgSimViewGraphics(*world, timestep_physics, timestep_graphics);
136 }
137 
140  const double timestep_physics = 1.0 / 60.0 / 10.0; // Seconds
141  const double timestep_graphics = 1.f /60.f; // Seconds, AKA render rate. Leave at 1/60 for real-time viewing
142  return new tgSimView(*world, timestep_physics, timestep_graphics);
143 }
144 
146 void simulate(tgSimulation *simulation) {
147  int nEpisodes = 1; // Number of episodes ("trial runs")
148  int nSteps = 60000; // Number of steps in each episode, 60k is 100 seconds (timestep_physics*nSteps)
149  for (int i=0; i<nEpisodes; i++) {
150  simulation->run(nSteps);
151  simulation->reset();
152  }
153 }
154 
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...