NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
tgCPGInfo.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 
19 #include "tgCPGInfo.h"
20 
22 #include "tgBaseCPGNode.h"
23 
24 #include "tgcreator/tgRigidInfo.h"
25 
26 #include "util/CPGEquations.h"
27 #include "core/ImpedanceControl.h"
28 
29 tgCPGInfo::tgCPGInfo (CPGEquations* CPGSys, array_2D nodeParams)
30 {
31  // Ensure that this hasn't already been assigned
32  assert(m_nodeNum == -1);
33  // Not a null Pointer
34  assert(CPGSys);
35 
36  p_CPGSys = CPGSys;
37 
38  std::vector<double> params (7);
39  params[0] = nodeParams[0][0]; // Frequency Offset
40  params[1] = nodeParams[0][1]; // Frequency Scale
41  params[2] = nodeParams[0][2]; // Radius Offset
42  params[3] = nodeParams[0][3]; // Radius Scale
43  params[4] = 20.0; // rConst (a constant)
44  params[5] = 0.0; // dMin for descending commands
45  params[6] = 5.0; // dMax for descending commands
46 
47  m_nodeNum = p_CPGSys->addNode(params);
48 }
49 
51  std::vector<tgConnectorInfo*> allStrings,
52  array_4D edgeParams)
53 {
54  assert(m_nodeNum >= 0);
55 
56  int muscleSize = edgeParams.shape()[1];
57 
58  tgRigidInfo* fromGroup = thisString->getFromRigidInfo();
59  tgRigidInfo* toGroup = thisString->getToRigidInfo();
60 
61  std::vector<int> connectivityList;
62  std::vector<double> weights;
63  std::vector<double> phases;
64 
69  // Assuming all coupling is two way, there ought to be a way
70  // to search faster than O((2N)^2) since every other
71  // string has to call this. Ideas are welcome
72  for (int i = 0; i < allStrings.size(); i++)
73  {
74  if (thisString != allStrings[i])
75  {
76  tgRigidInfo* theirFromGroup = allStrings[i]->getFromRigidInfo()
78  tgRigidInfo* theirToGroup = allStrings[i]->getToRigidInfo()
80 
81  // "All to all" connectivity for shared rigid bodies
82  if(fromGroup == theirFromGroup ||
83  toGroup == theirToGroup ||
84  fromGroup == theirToGroup ||
85  toGroup == theirFromGroup)
86  {
87  int theirMuscle = allStrings[i]->getNodeNumber();
88  // Integer division: -1 is behind, 0 is same row 1 is ahead
89  int rp = ((m_nodeNum - theirMuscle) / muscleSize) + 1;
90  int j = m_nodeNum % muscleSize;
91  int k = theirMuscle % muscleSize;
92  connectivityList.push_back(theirMuscle);
93  // Upper triangular matrix, lower number always goes first
94  if(j > k){
95  weights.push_back(edgeParams[rp][k][j][0]);
96  phases.push_back(edgeParams[rp][k][j][1]);
97  }
98  else
99  {
100  weights.push_back(edgeParams[rp][j][k][0]);
101  phases.push_back(edgeParams[rp][j][k][1]);
102  }
103  }
104  }
105  }
106 
107  p_CPGSys->defineConnections(m_nodeNum, connectivityList, weights, phases);
108 }
109 
111 {
112  ImpedanceControl* p_ipc = new ImpedanceControl(0.0, // Tension
113  10000.0, // Position
114  5000.0); // Velocity
115 
116  string->setupControl(m_nodeNum, p_CPGSys, p_ipc);
117 
118  // string owns this pointer
119  p_ipc = NULL;
120 }
Definition of abstract class tgRigidInfo.
void addControlInfo(tgBaseCPGNode *string)
Definition: tgCPGInfo.cpp:110
virtual tgRigidInfo * getRigidInfoGroup()
Definition: tgRigidInfo.h:151
void setConnectivity(tgConnectorInfo *thisString, std::vector< tgConnectorInfo * > allStrings, array_4D edgeParams)
Definition: tgCPGInfo.cpp:50
Definition of class tgConnectorInfo.
Contains the definition of class ImpedanceControl. $Id$.
tgCPGInfo(CPGEquations *CPGSys, array_2D nodeParams)
Definition: tgCPGInfo.cpp:29
Definition of class CPGEquations.
Definition of class tgBaseCPGNode.