NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AppOctaCL_CPG.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 
27 // This application
29 // This library
32 #include "core/tgModel.h"
33 #include "core/tgSimView.h"
34 #include "core/tgSimViewGraphics.h"
35 #include "core/tgSimulation.h"
36 #include "core/tgWorld.h"
37 // The C++ Standard Library
38 #include <iostream>
39 
47 int main(int argc, char** argv)
48 {
49  std::cout << "AppNestedStructureTest" << std::endl;
50 
51  // First create the world
52  const tgWorld::Config config(981); // gravity, cm/sec^2
53  tgWorld world(config);
54 
55  // Second create the view
56  const double stepSize = 1.0/1000.0; // Seconds
57  const double renderRate = 1.0/60.0; // Seconds
58  tgSimView view(world, stepSize, renderRate);
59 
60  // Third create the simulation
61  tgSimulation simulation(view);
62 
63  // Fourth create the models with their controllers and add the models to the
64  // simulation
65  const int segments = 3;
67  new FlemonsSpineModelLearningCL(segments);
68 
69  /* Required for setting up learning file input/output. */
70  const std::string suffix((argc > 1) ? argv[1] : "default");
71 
72  const int segmentSpan = 3;
73  const int numMuscles = 4;
74  const int numParams = 2;
75  const int segNumber = 1;
76 
77  const double controlTime = 0.1;
78  const double lowPhase = -1 * M_PI;
79  const double highPhase = M_PI;
80  const double lowAmplitude = 0.0;
81  const double highAmplitude = 30.0;
82 
83  const double tension = 0.0;
84  const double kPosition = 400.0;
85  const double kVelocity = 40.0;
86 
87  SpineFeedbackControl::Config control_config(segmentSpan, numMuscles, numMuscles, numParams, segNumber, controlTime,
88  lowAmplitude, highAmplitude, lowPhase, highPhase,
89  tension, kPosition, kVelocity);
90  SpineFeedbackControl* const myControl =
91  new SpineFeedbackControl(control_config, suffix, "bmirletz/OctaCL_CPG/");
92  myModel->attach(myControl);
93 #if (0)
94  tgCPGLogger* const myLogger =
95  new tgCPGLogger("logs/CPGValues.txt");
96 
97  myControl->attach(myLogger);
98 #endif
99  simulation.addModel(myModel);
100 
101  int i = 0;
102  while (i < 1)
103  {
104  try
105  {
106  simulation.run(60000);
107  simulation.reset();
108  i++;
109  }
110  catch (std::runtime_error e)
111  {
112  simulation.reset();
113  }
114  }
115 
117 
121  #if (0)
122  delete myControl;
123  #endif
124  //Teardown is handled by delete, so that should be automatic
125  return 0;
126 }
int main(int argc, char **argv)
A controller for the template class BaseSpineModelLearning.
Implementing the cross-linked octahedral 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$.
Contains the definition of class tgSimView.
Contains the definition of interface class tgCPGLogger.
void attach(tgObserver< T > *pObserver)
Definition: tgSubject.h:91