NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
CPGNode.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 "CPGNode.h"
28 #include "CPGEdge.h"
29 
30 CPGNode::CPGNode(int nodeNum, const std::vector<double> & params):
31 nodeValue(0),
32 phiValue(0),
33 phiDotValue(0),
34 rValue(0),
35 rDotValue(0),
36 m_nodeNumber(nodeNum),
37 rDoubleDotValue(0),
38 rConst(params[4]),
39 frequencyOffset(params[0]),
40 frequencyScale(params[1]),
41 radiusOffset(params[2]),
42 radiusScale(params[3]),
43 dMin(params[5]),
44 dMax(params[6])
45 {
46  //Precondition
47  assert(params.size() == 7);
48 }
49 
50 CPGNode::~CPGNode()
51 {
52  for (std::size_t i = 0; i < couplingList.size(); i++)
53  {
54  delete couplingList[i];
55  }
56  couplingList.clear();
57 }
58 
59 void CPGNode::addCoupling(CPGEdge* newEdge)
60 {
61  couplingList.push_back(newEdge);
62 }
63 
64 void CPGNode::addCoupling(std::vector<CPGEdge*> edgeList){
65  couplingList.insert(couplingList.end(), edgeList.begin(), edgeList.end());
66 }
67 
68 void CPGNode::addCoupling( CPGNode* cNode,
69  const double cWeight,
70  const double cPhase)
71 {
72  CPGEdge* newEdge = new CPGEdge(cNode, cWeight, cPhase);
73  CPGNode::addCoupling(newEdge);
74 }
75 
76 void CPGNode::updateDTs(double descCom)
77 {
78  phiDotValue = 2 * M_PI * nodeEquation(descCom, frequencyOffset, frequencyScale);
79 
85  for (int i = 0; i != couplingList.size(); i++){
86  couplingList[i]->couple(*this);
87  }
88 
89  rDoubleDotValue = rConst * (rConst / 4 * (nodeEquation(descCom, radiusOffset, radiusScale)
90  - rValue) - rDotValue);
91 }
92 
93 double CPGNode::nodeEquation( double d,
94  double c0,
95  double c1)
96 {
97  //@todo: Make parameters dMax, dMin
98  if(d >= dMin && d <= dMax){
99  return c1 * d + c0;
100  }
101  else{
102  return 0;
103  }
104 }
105 
106 void CPGNode::updateNodeValues (double newPhi,
107  double newR,
108  double newRD)
109 
110 {
111  rValue = newR;
112  rDotValue = newRD;
113  phiValue = newPhi;
114  nodeValue = rValue*cos(phiValue);
115 }
116 
117 std::string CPGNode::toString(const std::string& prefix) const
118 {
119  std::string p = " ";
120  std::ostringstream os;
121  os << prefix << "CPGNode(" << p << m_nodeNumber << std::endl;
122 
123  // TODO: add something about parameters of this node?
124 
125  os << prefix << p << "Connectivity:" << std::endl;
126  for(int i = 0; i < couplingList.size(); i++) {
127  os << prefix << p << p << *(couplingList[i]);
128  }
129 
130  os << prefix << ")";
131  return os.str();
132 }
double nodeEquation(double d, double c0, double c1)
Definition: CPGNode.cpp:93
const int m_nodeNumber
Definition: CPGNode.h:109
const double rConst
Definition: CPGNode.h:114
Definition of class CPGEdge.
Definition of class CPGNode.
CPGNode(int nodeNum, const std::vector< double > &params)
Definition: CPGNode.cpp:30
double nodeValue
Definition: CPGNode.h:95
void updateDTs(double descCom)
Definition: CPGNode.cpp:76