NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AppFlemonsSpineContact.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
31 
32 // This library
33 #include "core/tgModel.h"
34 #include "core/tgSimView.h"
35 #include "core/tgSimViewGraphics.h"
36 #include "core/tgSimulation.h"
37 #include "core/tgWorld.h"
39 // The C++ Standard Library
40 #include <iostream>
41 #include <exception>
42 
50 int main(int argc, char** argv)
51 {
52  std::cout << "AppFlemonsSpineContact" << std::endl;
53 
54  // First create the world
55  const tgWorld::Config config(981); // gravity, cm/sec^2
56 #if (1)
57  btVector3 eulerAngles = btVector3(0.0, 0.0, 0.0);
58  btScalar friction = 0.5;
59  btScalar restitution = 0.0;
60  btVector3 size = btVector3(500.0, 0.5, 500.0);
61  btVector3 origin = btVector3(0.0, 0.0, 0.0);
62  size_t nx = 100;
63  size_t ny = 100;
64  double margin = 0.5;
65  double triangleSize = 5.0;
66  double waveHeight = 3.0;
67  double offset = 0.0;
68  tgHillyGround::Config groundConfig(eulerAngles, friction, restitution,
69  size, origin, nx, ny, margin, triangleSize,
70  waveHeight, offset);
71 
72  tgHillyGround* ground = new tgHillyGround(groundConfig);
73 
74  tgWorld world(config, ground);
75 #else
76  tgWorld world(config);
77 #endif
78 
79  // Second create the view
80  const double stepSize = 1.0/1000.0; // Seconds
81  const double renderRate = 1.0/60.0; // Seconds
82  tgSimView view(world, stepSize, renderRate);
83 
84  // Third create the simulation
85  tgSimulation simulation(view);
86 
87  // Fourth create the models with their controllers and add the models to the
88  // simulation
89  const int segments = 6;
90  FlemonsSpineModelContact* myModel =
91  new FlemonsSpineModelContact(segments);
92 
93  /* Required for setting up learning file input/output. */
94  const std::string suffix((argc > 1) ? argv[1] : "default");
95 
96  const int segmentSpan = 3;
97  const int numMuscles = 8;
98  const int numParams = 2;
99  const int segNumber = 0; // For learning results
100  const double controlTime = .01;
101  const double lowPhase = -1 * M_PI;
102  const double highPhase = M_PI;
103  const double lowAmplitude = 0.0;
104  const double highAmplitude = 300.0;
105  const double kt = 0.0;
106  const double kp = 1000.0;
107  const double kv = 200.0;
108  const bool def = true;
109 
110  // Overridden by def being true
111  const double cl = 10.0;
112  const double lf = 0.0;
113  const double hf = 30.0;
114 
115  // Feedback parameters
116  const double ffMin = -0.5;
117  const double ffMax = 10.0;
118  const double afMin = 0.0;
119  const double afMax = 200.0;
120  const double pfMin = -0.5;
121  const double pfMax = 6.28;
122 
123  SpineFeedbackControl::Config control_config(segmentSpan,
124  numMuscles,
125  numMuscles,
126  numParams,
127  segNumber,
128  controlTime,
129  lowAmplitude,
130  highAmplitude,
131  lowPhase,
132  highPhase,
133  kt,
134  kp,
135  kv,
136  def,
137  cl,
138  lf,
139  hf,
140  ffMin,
141  ffMax,
142  afMin,
143  afMax,
144  pfMin,
145  pfMax
146  );
147  SpineFeedbackControl* const myControl =
148  new SpineFeedbackControl(control_config, suffix, "bmirletz/TetrahedralComplex_Contact/");
149  myModel->attach(myControl);
150 
151  simulation.addModel(myModel);
152 
153  int i = 0;
154  while (i < 30000)
155  {
156  try
157  {
158  simulation.run(30000);
159  simulation.reset();
160  i++;
161  }
162  catch (std::runtime_error e)
163  {
164  simulation.reset();
165  }
166  }
167 
169 
173  #if (0)
174  delete myControl;
175  #endif
176  //Teardown is handled by delete, so that should be automatic
177  return 0;
178 }
A controller for the template class BaseSpineModelLearning.
Contains the definition of class tgHillyGround.
int main(int argc, char **argv)
void addModel(tgModel *pModel)
Implementing the tetrahedral complex spine inspired by Tom Flemons.
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 run() const
Contains the definition of class tgSimView.
void attach(tgObserver< T > *pObserver)
Definition: tgSubject.h:91