NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
KinematicSpineCPGControl.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 
27 #include "KinematicSpineCPGControl.h"
28 
29 #include <string>
30 
31 
32 // Should include tgString, but compiler complains since its been
33 // included from BaseSpineModelLearning. Perhaps we should move things
34 // to a cpp over there
36 #include "core/tgBasicActuator.h"
39 #include "dev/CPG_feedback/tgCPGCableControl.h"
40 
41 #include "helpers/FileHelpers.h"
42 
45 
46 #include "util/CPGEquations.h"
47 #include "util/CPGNode.h"
48 
49 //#define LOGGING
50 #define USE_KINEMATIC
51 
58  std::string args,
59  std::string resourcePath,
60  std::string ec,
61  std::string nc) :
62 BaseSpineCPGControl(config, args, resourcePath, ec, nc)
63 {
64 
65 
66 }
67 
68 void KinematicSpineCPGControl::setupCPGs(BaseSpineModelLearning& subject, array_2D nodeActions, array_4D edgeActions)
69 {
70 
71  std::vector <tgSpringCableActuator*> allMuscles = subject.getAllMuscles();
72 
73  for (std::size_t i = 0; i < allMuscles.size(); i++)
74  {
75  #ifdef USE_KINEMATIC
76  tgPIDController::Config config(5000.0, 0.0, 10.0, true); // Non backdrivable
77  tgCPGCableControl* pStringControl = new tgCPGCableControl(config, m_config.controlTime);
78  #else
79  tgCPGStringControl* pStringControl = new tgCPGStringControl();
80  #endif
81  allMuscles[i]->attach(pStringControl);
82 
83  m_allControllers.push_back(pStringControl);
84  }
85 
87  // First assign node numbers to the info Classes
88  for (std::size_t i = 0; i < m_allControllers.size(); i++)
89  {
90  m_allControllers[i]->assignNodeNumber(*m_pCPGSys, nodeActions);
91  }
92 
93  // Then determine connectivity and setup string
94  for (std::size_t i = 0; i < m_allControllers.size(); i++)
95  {
96  tgCPGActuatorControl * const pStringInfo = m_allControllers[i];
97  assert(pStringInfo != NULL);
98  pStringInfo->setConnectivity(m_allControllers, edgeActions);
99 
100  //String will own this pointer
101  tgImpedanceController* p_ipc = new tgImpedanceController( m_config.tension,
102  m_config.kPosition,
103  m_config.kVelocity);
104  if (m_config.useDefault)
105  {
106  pStringInfo->setupControl(*p_ipc);
107  }
108  else
109  {
110  pStringInfo->setupControl(*p_ipc, m_config.controlLength);
111  }
112  }
113 
114 }
Contains the definition of class ImpedanceControl. $Id$.
void setConnectivity(const std::vector< tgCPGActuatorControl * > &allStrings, array_4D edgeParams)
Definition of the tgCPGStringControl observer class.
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...
A series of functions to assist with file input/output.
KinematicSpineCPGControl(BaseSpineCPGControl::Config config, std::string args, std::string resourcePath="", std::string ec="edgeConfig.ini", std::string nc="nodeConfig.ini")
Contains the definition of class AnnealEvolution. Adapting NeuroEvolution to do Simulated Annealing...
Contains the definition of class tgBasicActuator.
Definition of class CPGEquations.
Definition of class CPGNode.
virtual void setupCPGs(BaseSpineModelLearning &subject, array_2D nodeActions, array_4D edgeActions)