NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AppSUPERball.cpp
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 "T6Model.h"
28 // This library
30 #include "core/tgModel.h"
31 #include "core/tgSimViewGraphics.h"
32 #include "core/tgSimulation.h"
33 #include "core/tgWorld.h"
34 // Bullet Physics
35 #include "LinearMath/btVector3.h"
36 // The C++ Standard Library
37 #include <iostream>
38 
39 tgBoxGround *createGround();
40 tgWorld *createWorld();
43 void simulate(tgSimulation *simulation);
44 
51 int main(int argc, char** argv)
52 {
53  std::cout << "AppSUPERball_InternalFriction" << std::endl;
54 
55  // First create the ground and world
56  tgWorld *world = createWorld();
57 
58  // Second create the view
59  tgSimViewGraphics *view = createGraphicsView(world); // For visual experimenting on one tensegrity
60 // tgSimView *view = createView(world); // For running multiple episodes
61 
62  // Third create the simulation
63  tgSimulation *simulation = new tgSimulation(*view);
64 
65  // Fourth create the models with their controllers and add the models to the
66  // simulation
67  T6Model* const myModel = new T6Model();
68 
69  // Fifth, select the controller to use. Uncomment desired controller.
70 
71  // For the T6RestLengthController, pass in the amount of cable to contract
72  // in. This is the "rest length difference": the static offset of cable
73  // length between geometric length in equilibrium and the actual rest length
74  // of an individual cable.
75  // Note for the above scale of gravity, this is in decimeters.
76  //T6RestLengthController* const pTC = new T6RestLengthController(myModel, 4);
77 
78  //myModel->attach(pTC);
79  simulation->addModel(myModel);
80 
81  // Run specified times within function call
82  simulate(simulation);
83 
84  // Run until the user stops
85 // simulation->run();
86 
87  //Teardown is handled by delete, so that should be automatic
88  return 0;
89 }
90 
91 tgBoxGround *createGround() {
92  // Determine the angle of the ground in radians. All 0 is flat
93  const double yaw = 0.0;
94  const double pitch = 0.0;
95  const double roll = 0.0;
96  const btVector3 eulerAngles = btVector3(yaw, pitch, roll); // Default: (0.0, 0.0, 0.0)
97  const double friction = 0.5; // Default: 0.5
98  const double restitution = 0.0; // Default: 0.0
99  const btVector3 size = btVector3(10000.0, 2, 10000.0); // Default: (500.0, 1.5, 500.0)
100  const btVector3 origin = btVector3(0.0, 0.0, 0.0); // Default: (0.0, 0.0, 0.0)
101  const tgBoxGround::Config groundConfig(eulerAngles, friction, restitution,
102  size, origin);
103  // the world will delete this
104  return new tgBoxGround(groundConfig);
105 }
106 
107 tgWorld *createWorld() {
108  const tgWorld::Config config(98.1); // gravity, cm/sec^2 Use this to adjust length scale of world.
109  // NB: by changing the setting below from 981 to 98.1, we've
110  // scaled the world length scale to decimeters not cm.
111 
112  tgBoxGround* ground = createGround();
113  return new tgWorld(config, ground);
114 }
115 
118  const double timestep_physics = 1.0 / 60.0 / 10.0; // Seconds
119  const double timestep_graphics = 1.f /60.f; // Seconds, AKA render rate. Leave at 1/60 for real-time viewing
120  return new tgSimViewGraphics(*world, timestep_physics, timestep_graphics);
121 }
122 
124 tgSimView *createView(tgWorld *world) {
125  const double timestep_physics = 1.0 / 60.0 / 10.0; // Seconds
126  const double timestep_graphics = 1.f /60.f; // Seconds, AKA render rate. Leave at 1/60 for real-time viewing
127  return new tgSimView(*world, timestep_physics, timestep_graphics);
128 }
129 
131 void simulate(tgSimulation *simulation) {
132  int nEpisodes = 1; // Number of episodes ("trial runs")
133  int nSteps = 60000; // Number of steps in each episode, 60k is 100 seconds (timestep_physics*nSteps)
134  for (int i=0; i<nEpisodes; i++) {
135  simulation->run(nSteps);
136  simulation->reset();
137  }
138 }
int main(int argc, char **argv)
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 tgWorld $Id$.
void simulate(tgSimulation *simulation)
void run() const
Contains the definition of class tgBoxGround.