NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AppFlemonsSpineLearning.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 #include "examples/learningSpines/KinematicSpineCPGControl.h"
33 // This library
34 #include "core/tgModel.h"
35 #include "core/tgSimView.h"
36 #include "core/tgSimViewGraphics.h"
37 #include "core/tgSimulation.h"
38 #include "core/tgWorld.h"
39 // The C++ Standard Library
40 #include <iostream>
41 
49 int main(int argc, char** argv)
50 {
51  std::cout << "AppNestedStructureTest" << std::endl;
52 
53  // First create the world
54  const tgWorld::Config config(981); // gravity, cm/sec^2
55  tgWorld world(config);
56 
57  // Second create the view
58  const double stepSize = 1.0/1000.0; // Seconds
59  const double renderRate = 1.0/60.0; // Seconds
60  tgSimViewGraphics view(world, stepSize, renderRate);
61 
62  // Third create the simulation
63  tgSimulation simulation(view);
64 
65  // Fourth create the models with their controllers and add the models to the
66  // simulation
67  const int segments = 12;
68  FlemonsSpineModelLearning* myModel =
69  new FlemonsSpineModelLearning(segments);
70 
71  /* Required for setting up learning file input/output. */
72  const std::string suffix((argc > 1) ? argv[1] : "default");
73 
74  const int segmentSpan = 3;
75  const int numMuscles = 8;
76  const int numParams = 2;
77  const int segNumber = 6; // For learning results
78  const double controlTime = .001;
79  const double lowPhase = -1 * M_PI;
80  const double highPhase = M_PI;
81  const double lowAmplitude = -30.0;
82  const double highAmplitude = 30.0;
83  const double kt = 0.0;
84  const double kp = 1000.0;
85  const double kv = 210.0;
86  const bool def = true;
87 
88  // Overridden by def being true
89  const double cl = 10.0;
90  const double lf = -30.0;
91  const double hf = 30.0;
92 
93 
94  BaseSpineCPGControl::Config control_config(segmentSpan,
95  numMuscles,
96  numMuscles,
97  numParams,
98  segNumber,
99  controlTime,
100  lowAmplitude,
101  highAmplitude,
102  lowPhase,
103  highPhase,
104  kt,
105  kp,
106  kv,
107  def,
108  cl,
109  lf,
110  hf
111  );
112  KinematicSpineCPGControl* const myControl =
113  new KinematicSpineCPGControl(control_config, suffix, "learningSpines/TetrahedralComplex/");
114  myModel->attach(myControl);
115 #if (0)
116  tgCPGLogger* const myLogger =
117  new tgCPGLogger("logs/CPGValues.txt");
118 
119  myControl->attach(myLogger);
120 #endif
121  simulation.addModel(myModel);
122 
123  int i = 0;
124  while (i < 1)
125  {
126  simulation.run(30000);
127  #ifdef BT_USE_DOUBLE_PRECISION
128  std::cout << "Double precision" << std::endl;
129  #else
130  std::cout << "Single Precision" << std::endl;
131  #endif
132  simulation.reset();
133  i++;
134  }
135 
137 
141  #if (0)
142  delete myControl;
143  #endif
144  //Teardown is handled by delete, so that should be automatic
145  return 0;
146 }
int main(int argc, char **argv)
Implementing the tetrahedral complex spine inspired by Tom Flemons.
void addModel(tgModel *pModel)
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$.
A controller for the template class BaseSpineModelLearning.
void run() const
Contains the definition of class tgSimView.
Contains the definition of interface class tgCPGLogger.
void attach(tgObserver< T > *pObserver)
Definition: tgSubject.h:91