NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AppSpineKinematicsTest.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 
27 // This application
28 #include "yamlbuilder/TensegrityModel.h"
30 // This library
32 #include "core/tgModel.h"
33 #include "core/tgSimulation.h"
34 #include "core/tgSimViewGraphics.h"
35 #include "core/tgWorld.h"
36 #include "sensors/tgDataLogger2.h"
40 // Bullet Physics
41 #include "LinearMath/btVector3.h"
42 // The C++ Standard Library
43 #include <iostream>
44 #include <string>
45 #include <vector>
46 
54 int main(int argc, char** argv)
55 {
56  // For this YAML parser app, need to check that an argument path was
57  // passed in.
58  if (argv[1] == NULL)
59  {
60  throw std::invalid_argument("No arguments passed in to the application. You need to specify which YAML file you wouldd like to build.");
61  }
62 
63  // create the ground and world. Specify ground rotation in radians
64  const double yaw = 0.0;
65  const double pitch = 0.0;
66  const double roll = 0.0;
67  const tgBoxGround::Config groundConfig(btVector3(yaw, pitch, roll));
68  // the world will delete this
69  tgBoxGround* ground = new tgBoxGround(groundConfig);
70 
71  // For this kinematics test, no gravity. We want a purely kinematic movement,
72  // as if the spine was floating in space.
73  const tgWorld::Config config(0.0); // gravity, dm/sec^2
74  tgWorld world(config, ground);
75 
76  // create the view
77  const double timestep_physics = 0.0001; // seconds
78  //const double timestep_physics = 0.001;
79  const double timestep_graphics = 1.f/60.f; // seconds
80  tgSimViewGraphics view(world, timestep_physics, timestep_graphics);
81 
82  // create the simulation
83  tgSimulation simulation(view);
84 
85  // create the models with their controllers and add the models to the simulation
86  // This constructor for TensegrityModel takes the 'debugging' flag as the
87  // second argument.
88  TensegrityModel* const myModel = new TensegrityModel(argv[1],false);
89 
90  // Attach a controller to the model, if desired.
91  // This is a controller that interacts with a generic TensegrityModel as
92  // built by the TensegrityModel file, BUT it only actually works
93  // with the specific HorizontalSpine YAML file.
94  // @TODO: should this throw an error when attached to a model that
95  // wasn't built with the HorizontalSpine YAML file?
96 
97  // Parameters for the Horizontal Spine Controller are specified in that .h file,
98  // repeated here:
99  double startTime = 3.0;
100  double minLength = 0.8;
101  double rate = 0.25;
102  std::vector<std::string> tagsToControl;
103  // HF is the right horizontal set
104  // HL is the bottom horizontal set maybe?
105  // HB is the left horizontal set
106  // HR is the top horizontal set.
107  // BUT, something is wrong here. Probably Bullet's numerical problems.
108  tagsToControl.push_back("HR");
109  tagsToControl.push_back("HF");
110  //tagsToControl.push_back("HB");
111  // Call the constructor for the controller
112  SpineKinematicsTestController* const controller =
113  new SpineKinematicsTestController(startTime, minLength, rate, tagsToControl);
114  // Attach the controller to the model. Must happen before running the
115  // simulation.
116  myModel->attach(controller);
117 
118  // Add the model to the world
119  simulation.addModel(myModel);
120 
121  // Add sensors using the new sensing framework
122  // A string prefix for the filename
123  std::string log_filename = "~/NTRTsim_logs/AppSpineKinematicsTest";
124  // The time interval between sensor readings:
125  double timeInterval = 0.2;
126  // First, create the data manager
127  tgDataLogger2* myDataLogger = new tgDataLogger2(log_filename, timeInterval);
128  //std::cout << myDataLogger->toString() << std::endl;
129  // Then, add the model to the data logger
130  myDataLogger->addSenseable(myModel);
131  // Create sensor infos for all the types of sensors that the data logger
132  // will create.
133  //tgRodSensorInfo* myRodSensorInfo = new tgRodSensorInfo();
134  tgSpringCableActuatorSensorInfo* mySCASensorInfo =
137  // Attach the sensor infos to the data logger
138  //myDataLogger->addSensorInfo(myRodSensorInfo);
139  myDataLogger->addSensorInfo(mySCASensorInfo);
140  myDataLogger->addSensorInfo(myCRSensorInfo);
141  // Next, attach it to the simulation
142  simulation.addDataManager(myDataLogger);
143 
144  simulation.run();
145 
146  // teardown is handled by delete
147  return 0;
148 }
void addDataManager(tgDataManager *pDataManager)
virtual void addSenseable(tgSenseable *pSenseable)
int main(int argc, char **argv)
Contains the definition of class tgDataLogger2.
void addModel(tgModel *pModel)
Contains the definition of class SpineKinematicsTestController.
Contains the definition of class tgSimulation.
Contains the definition of class tgModel.
Contains the definition of class tgSimViewGraphics.
Definition of concrete class tgCompoundRigidSensorInfo.
virtual void addSensorInfo(tgSensorInfo *pSensorInfo)
Definition of concrete class tgRodSensorInfo.
Definition of concrete class tgSpringCableActuatorSensorInfo.
Contains the definition of class tgWorld $Id$.
void run() const
Contains the definition of class tgBoxGround.
void attach(tgObserver< T > *pObserver)
Definition: tgSubject.h:91