NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
TetraSpineCPGControl.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 #include "TetraSpineCPGControl.h"
29 
30 #include <string>
31 
32 
33 // Should include tgString, but compiler complains since its been
34 // included from TetraSpineLearningModel. Perhaps we should move things
35 // to a cpp over there
36 #include "core/tgLinearString.h"
37 #include "core/ImpedanceControl.h"
38 
41 
42 #include "examples/learningSpines/tgCPGStringControl.h"
43 
50  std::string args,
51  std::string ec,
52  std::string nc) :
53 BaseSpineCPGControl(config, args, ec, nc)
54 {
55 }
56 
57 void TetraSpineCPGControl::setupCPGs(BaseSpineModelLearning& subject, array_2D nodeActions, array_4D edgeActions)
58 {
59  std::vector <tgLinearString*> allMuscles = subject.getAllMuscles();
60 
61  for (std::size_t i = 0; i < allMuscles.size(); i++)
62  {
63  tgCPGStringControl* pStringControl = new tgCPGStringControl();
64  allMuscles[i]->attach(pStringControl);
65  m_allControllers.push_back(pStringControl);
66  }
67 
69  // First assign node numbers to the info Classes
70  for (std::size_t i = 0; i < m_allControllers.size(); i++)
71  {
72  m_allControllers[i]->assignNodeNumber(*m_pCPGSys, nodeActions);
73  }
74 
75  double tension;
76  double kPosition;
77  double kVelocity;
78  double controlLength;
79  // Then determine connectivity and setup string
80  for (std::size_t i = 0; i < m_allControllers.size(); i++)
81  {
82  tgCPGStringControl * const pStringInfo = m_allControllers[i];
83  assert(pStringInfo != NULL);
84  pStringInfo->setConnectivity(m_allControllers, edgeActions);
85 
86  //String will own this pointer
87 #if (1) // origninal params
88  if (allMuscles[i]->hasTag("outer"))
89  {
90  tension = 0.0;
91  kPosition = 1000.0;
92  kVelocity = 100.0;
93  controlLength = 17.0;
94  }
95  else
96  {
97  tension = 0.0;
98  kPosition = 1000.0;
99  kVelocity = 100.0;
100  controlLength = 15.0 ;
101  }
102 #else // Params for In Won
103  if (allMuscles[i]->hasTag("outer"))
104  {
105  tension = 0.0;
106  kPosition = 2000.0;
107  kVelocity = 300.0;
108  controlLength = 17.5;
109  }
110  else
111  {
112  tension = 0.0;
113  kPosition = 2000.0;
114  kVelocity = 300.0;
115  controlLength = 15.0 ;
116  }
117 #endif
118  ImpedanceControl* p_ipc = new ImpedanceControl( tension,
119  kPosition,
120  kVelocity);
121  pStringInfo->setupControl(*p_ipc, controlLength);
122  }
123 
124 }
Controller for TetraSpineLearningModel.
virtual void setupCPGs(BaseSpineModelLearning &subject, array_2D nodeActions, array_4D edgeActions)
A class to read a learning configuration from a .ini file.
Contains the definition of class AnnealEvolution. Adapting NeuroEvolution to do Simulated Annealing...
void setConnectivity(const std::vector< tgCPGStringControl * > &allStrings, array_4D edgeParams)
Contains the definition of class ImpedanceControl. $Id$.
Contains the definition of class tgLinearString.
TetraSpineCPGControl(BaseSpineCPGControl::Config config, std::string args, std::string ec="edgeConfig.ini", std::string nc="nodeConfig.ini")