43 tgCPGActuatorControl::tgCPGActuatorControl(
const double controlStep) :
46 m_controlStep(controlStep),
47 m_commandedTension(0.0),
51 if (m_controlStep < 0.0)
53 throw std::invalid_argument(
"Negative control step");
57 tgCPGActuatorControl::~tgCPGActuatorControl()
69 std::vector<const tgBulletSpringCableAnchor*> anchors =
72 std::size_t n = anchors.size();
75 m_pFromBody = anchors[0]->attachedBody;
76 m_pToBody = anchors[n - 1]->attachedBody;
87 tgBasicActuator& m_sca = *(tgCast::cast<tgSpringCableActuator, tgBasicActuator>(subject));
92 m_commandedTension = motorControl().
control(m_sca,
m_controlTime, controlLength(), getCPGValue());
105 assert(m_nodeNumber == -1);
107 m_pCPGSystem = &CPGSys;
109 std::vector<double> params (7);
110 params[0] = nodeParams[0][0];
111 params[1] = nodeParams[0][0];
112 params[2] = nodeParams[0][1];
113 params[3] = nodeParams[0][1];
118 m_nodeNumber = m_pCPGSystem->addNode(params);
125 assert(m_nodeNumber >= 0);
127 int muscleSize = edgeParams.shape()[1];
129 std::vector<int> connectivityList;
130 std::vector<double> weights;
131 std::vector<double> phases;
136 for (
int i = 0; i < allStrings.size(); i++)
138 if (
this != allStrings[i])
141 assert(m_pCPGSystem == allStrings[i]->
getCPGSys());
143 const btRigidBody* theirFromGroup = allStrings[i]->getFromBody();
144 const btRigidBody* theirToGroup = allStrings[i]->getToBody();
147 if(m_pFromBody == theirFromGroup ||
148 m_pToBody == theirToGroup ||
149 m_pFromBody == theirToGroup ||
150 m_pToBody == theirFromGroup)
152 int theirMuscle = allStrings[i]->getNodeNumber();
154 int rp = ((m_nodeNumber - theirMuscle) / muscleSize) + 1;
155 int j = m_nodeNumber % muscleSize;
156 int k = theirMuscle % muscleSize;
157 connectivityList.push_back(theirMuscle);
160 weights.push_back(edgeParams[rp][k][j][0]);
161 phases.push_back(edgeParams[rp][k][j][1]);
165 weights.push_back(edgeParams[rp][j][k][0]);
166 phases.push_back(edgeParams[rp][j][k][1]);
172 m_pCPGSystem->defineConnections(m_nodeNumber, connectivityList, weights, phases);
177 tgBaseCPGNode::setupControl(ipc);
181 double controlLength)
183 if (controlLength < 0.0)
185 throw std::invalid_argument(
"Negative control length");
188 m_controlLength = controlLength;
189 tgBaseCPGNode::setupControl(ipc);
Contains the definition of class ImpedanceControl. $Id$.
Definitions of class tgSpringCable.
virtual void moveMotors(double dt)
virtual void onStep(tgSpringCableActuator &subject, double dt)
virtual const double getStartLength() const
void setConnectivity(const std::vector< tgCPGActuatorControl * > &allStrings, array_4D edgeParams)
Utility class for class casting and filtering collections by type.
const CPGEquations * getCPGSys() const
virtual void onAttach(tgSpringCableActuator &subject)
Definition of the tgCPGStringControl observer class.
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
Contains the definition of class tgBasicActuator.
const double m_controlStep
virtual const std::vector< const tgSpringCableAnchor * > getAnchors() const =0
Definitions of class tgBulletSpringCableAnchor, formerly muscleAnchor.
Definition of class CPGEquations.
void assignNodeNumber(CPGEquations &CPGSys, array_2D nodeParams)
Definitions of class tgSpringCableAnchor.
double control(tgBasicController &mLocalController, double deltaTimeSeconds, double newPosition, double offsetVel=0)
Control Functions.
const tgSpringCable * getSpringCable() const