NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AppTgBoxAnchorDebugDemo.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 
28 // This application
29 #include "tgBoxAnchorDebugModel.h"
30 // This library
32 #include "core/tgModel.h"
33 #include "core/tgSimViewGraphics.h"
34 #include "core/tgSimulation.h"
35 #include "core/tgWorld.h"
36 #include "sensors/tgDataLogger2.h"
39 // Bullet Physics
40 #include "LinearMath/btVector3.h"
41 // The C++ Standard Library
42 #include <iostream>
43 
50 int main(int argc, char** argv)
51 {
52  std::cout << "AppTgBoxAnchorDebugDemo" << std::endl;
53 
54  // First create the ground and world
55 
56  // Determine the angle of the ground in radians. All 0 is flat
57  const double yaw = 0.0;
58  //const double pitch = M_PI/15.0;
59  const double pitch = 0.0;
60  const double roll = 0.0;
61  const tgBoxGround::Config groundConfig(btVector3(yaw, pitch, roll));
62  // the world will delete this
63  tgBoxGround* ground = new tgBoxGround(groundConfig);
64 
65  const tgWorld::Config config(98.1); // gravity, cm/sec^2 Use this to adjust length scale of world.
66  // Note, by changing the setting below from 981 to 98.1, we've
67  // scaled the world length scale to decimeters not cm.
68 
69  tgWorld world(config, ground);
70 
71  // Second create the view
72  const double timestep_physics = 0.001; // Seconds
73  const double timestep_graphics = 1.f/60.f; // Seconds
74  tgSimViewGraphics view(world, timestep_physics, timestep_graphics);
75 
76  // Third create the simulation
77  tgSimulation simulation(view);
78 
79  // Fourth create the models with their controllers and add the models to the
80  // simulation
81  tgModel* const myModel = new tgBoxAnchorDebugModel();
82 
83  // Finally, add out model to the simulation
84  simulation.addModel(myModel);
85 
86  // For the sensors:
87  // A string prefix for the filename
88  std::string log_filename = "~/NTRTsim_logs/AppTgBoxAnchorDebugDemo";
89  // First, create the data manager
90  tgDataLogger2* myDataLogger = new tgDataLogger2(log_filename);
91  //std::cout << myDataLogger->toString() << std::endl;
92  // Then, add the model to the data logger
93  myDataLogger->addSenseable(myModel);
94  // Create sensor infos for all the types of sensors that the data logger
95  // will create.
96  tgRodSensorInfo* myRodSensorInfo = new tgRodSensorInfo();
97  tgSpringCableActuatorSensorInfo* mySCASensorInfo =
99  // Attach the sensor infos to the data logger
100  myDataLogger->addSensorInfo(myRodSensorInfo);
101  myDataLogger->addSensorInfo(mySCASensorInfo);
102  // Next, attach it to the simulation
103  simulation.addDataManager(myDataLogger);
104  // and everything else should happen automatically.
105 
106  // Run until the user stops
107  simulation.run();
108 
109  //Teardown is handled by delete, so that should be automatic
110  return 0;
111 }
void addDataManager(tgDataManager *pDataManager)
int main(int argc, char **argv)
virtual void addSenseable(tgSenseable *pSenseable)
Contains the definition of class tgDataLogger2.
void addModel(tgModel *pModel)
Contains the definition of class tgSimulation.
Contains the definition of class tgModel.
Contains the definition of class tgSimViewGraphics.
virtual void addSensorInfo(tgSensorInfo *pSensorInfo)
Definition of concrete class tgRodSensorInfo.
Definition of concrete class tgSpringCableActuatorSensorInfo.
Contains the definition of class tgWorld $Id$.
Contains the definition of class tgBoxAnchorDebugModel. $Id$.
void run() const
Contains the definition of class tgBoxGround.