29 #include "boost/array.hpp"
30 #include "boost/numeric/odeint.hpp"
32 using namespace boost::numeric::odeint;
34 typedef std::vector<double > cpgVars_type;
36 CPGEquations::CPGEquations() :
39 CPGEquations::CPGEquations(std::vector<CPGNode*> newNodeList) :
40 nodeList(newNodeList),
45 CPGEquations::~CPGEquations()
47 for (std::size_t i = 0; i < nodeList.size(); i++)
56 int CPGEquations::addNode(std::vector<double> newParams)
58 int index = nodeList.size();
60 nodeList.push_back(newNode);
65 void CPGEquations::connectNode(
int nodeIndex,
66 std::vector<CPGEdge*> connectivityList)
68 nodeList[nodeIndex]->addCoupling(connectivityList);
71 void CPGEquations::defineConnections (
int nodeIndex,
72 std::vector<int> connections,
73 std::vector<double> newWeights,
74 std::vector<double> newPhaseOffsets)
76 assert(connections.size() == newWeights.size());
77 assert(connections.size() == newPhaseOffsets.size());
78 assert(nodeList[nodeIndex] != NULL);
80 for(
int i = 0; i != connections.size(); i++){
81 nodeList[nodeIndex]->addCoupling(nodeList[connections[i]], newWeights[i], newPhaseOffsets[i]);
85 std::vector<double> CPGEquations::getXVars() {
86 std::vector<double> newXVars;
88 for (
int i = 0; i != nodeList.size(); i++){
89 newXVars.push_back(nodeList[i]->phiValue);
90 newXVars.push_back(nodeList[i]->rValue);
91 newXVars.push_back(nodeList[i]->rDotValue);
97 std::vector<double> CPGEquations::getDXVars() {
98 std::vector<double> newDXVars;
100 for (
int i = 0; i != nodeList.size(); i++){
101 newDXVars.push_back(nodeList[i]->phiDotValue);
102 newDXVars.push_back(nodeList[i]->rDotValue);
103 newDXVars.push_back(nodeList[i]->rDoubleDotValue);
109 void CPGEquations::updateNodes(std::vector<double> descCom)
111 for(
int i = 0; i != nodeList.size(); i++){
112 nodeList[i]->updateDTs(descCom[i]);
116 void CPGEquations::updateNodeData(std::vector<double> newXVals)
118 assert(newXVals.size()==3*nodeList.size());
120 for(
int i = 0; i!=nodeList.size(); i++){
121 nodeList[i]->updateNodeValues(newXVals[3*i], newXVals[3*i+1], newXVals[3*i+2]);
142 theseCPGs->updateNodeData(x);
143 theseCPGs->updateNodes(descCom);
148 std::vector<double> dXVars = theseCPGs->getDXVars();
153 for(std::size_t i = 0; i != x.size(); i++){
162 std::vector<double> descCom;
182 theseCPGs->updateNodeData(x);
183 #if (0) // Suppress output
184 std::cout << t <<
'\t' << (*theseCPGs)[0] <<
'\t' << (*theseCPGs)[1] <<
'\t' << (*theseCPGs)[2] << std::endl;
204 std::vector<double> xVars = getXVars();
212 std::cout << dt <<
'\t' << nodeList[0]->nodeValue <<
213 '\t' << nodeList[1]->nodeValue <<
214 '\t' << nodeList[2]->nodeValue << std::endl;
219 std::string CPGEquations::toString(
const std::string& prefix)
const
222 std::ostringstream os;
223 os << prefix <<
"CPGEquations(" << std::endl;
225 os << prefix << p <<
"Nodes:" << std::endl;
226 for(
int i = 0; i < nodeList.size(); i++) {
227 os << prefix << p << p << *(nodeList[i]) << std::endl;
230 os << prefix <<
")" << std::endl;
void operator()(const cpgVars_type &x, cpgVars_type &dxdt, double t)
void update(std::vector< double > descCom, double dt)
void operator()(const cpgVars_type &x, const double t)
Definition of class CPGEquations.