NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
LearningSpineJSON.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 "LearningSpineJSON.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
38 
41 
42 #include "tgCPGStringControl_mod.h"
43 
50  std::string args,
51  std::string ec,
52  std::string nc) :
53 BaseSpineCPGControl(config, args)
54 
55 {
56 }
57 
58 void LearningSpineJSON::setupCPGs(BaseSpineModelLearning& subject, array_2D nodeActions, array_4D edgeActions)
59 {
60  std::vector <tgSpringCableActuator*> allMuscles = subject.getAllMuscles();
61 
62  for (std::size_t i = 0; i < allMuscles.size(); i++)
63  {
64  tgCPGStringControl_mod* pStringControl = new tgCPGStringControl_mod();
65  allMuscles[i]->attach(pStringControl);
66  std::cout << allMuscles[i]->getTags() << std::endl;
67  m_allControllers.push_back(pStringControl);
68  }
69 
70  assert(m_allControllers.size() == allMuscles.size());
71 
73  // First assign node numbers to the info Classes
74  for (std::size_t i = 0; i < m_allControllers.size(); i++)
75  {
76  m_allControllers[i]->assignNodeNumber(*m_pCPGSys, nodeActions);
77  }
78 
79  double tension;
80  double kPosition;
81  double kVelocity;
82  double controlLength;
83  // Then determine connectivity and setup string
84  for (std::size_t i = 0; i < m_allControllers.size(); i++)
85  {
86  tgCPGActuatorControl * const pStringInfo = m_allControllers[i];
87  assert(pStringInfo != NULL);
88  pStringInfo->setConnectivity(m_allControllers, edgeActions);
89 
90  if (allMuscles[i]->hasTag("inner top"))
91  {
92  tension = 2000.0;
93  kPosition = 500.0;
94  kVelocity = 100.0;
95  controlLength = allMuscles[i]->getStartLength();
96  controlLength = 19.0;
97  }
98  else if (allMuscles[i]->hasTag("outer top"))
99  {
100  tension = 1000.0;
101  kPosition = 500.0;
102  kVelocity = 100.0;
103  controlLength = 18.5;
104  }
105  else if (allMuscles[i]->hasTag("inner"))
106  {
107  tension = 1500.0;
108  kPosition = 300.0;
109  kVelocity = 100.0;
110  controlLength = allMuscles[i]->getStartLength();
111  controlLength = 21.5;
112  }
113  else if (allMuscles[i]->hasTag("outer"))
114  {
115  tension = 800.0;
116  kPosition = 300.0;
117  kVelocity = 100.0;
118  controlLength = 19.2 ;
119  }
120  else
121  {
122  throw std::runtime_error("Missing tags!");
123  }
124 
125  tgImpedanceController* p_ipc = new tgImpedanceController( tension,
126  kPosition,
127  kVelocity);
128  pStringInfo->setupControl(*p_ipc, controlLength);
129 
130  }
131 
132 }
Contains the definition of class ImpedanceControl. $Id$.
LearningSpineJSON(BaseSpineCPGControl::Config config, std::string args, std::string ec="edgeConfig.ini", std::string nc="nodeConfig.ini")
void setConnectivity(const std::vector< tgCPGActuatorControl * > &allStrings, array_4D edgeParams)
A class to read a learning configuration from a .ini file.
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
Controller for TetraSpineLearningModel.
Contains the definition of class AnnealEvolution. Adapting NeuroEvolution to do Simulated Annealing...
virtual void setupCPGs(BaseSpineModelLearning &subject, array_2D nodeActions, array_4D edgeActions)