39 #include "examples/learningSpines/tgCPGCableControl.h"
47 #include "examples/learningSpines/tgCPGCableControl.h"
83 lp, hp, kt, kp, kv, def, cl, lf, hf,
84 ffMin, ffMax, afMin, afMax, pfMin, pfMax, tf),
85 feedbackTime(feedTime)
96 std::string resourcePath,
103 m_feedbackControlTime(0.0)
109 m_feedbackControlTime = 0.0;
111 const BaseSpineModelGoal* goalSubject = tgCast::cast<BaseSpineModelLearning, BaseSpineModelGoal>(subject);
113 m_lastGoalDist = getGoalDist(goalSubject);
114 m_controllerStartDist = m_lastGoalDist;
122 m_feedbackControlTime += dt;
123 if (m_updateTime >= m_config.controlTime)
125 if(m_feedbackControlTime > m_config.feedbackTime)
127 const BaseSpineModelGoal* goalSubject = tgCast::cast<BaseSpineModelLearning, BaseSpineModelGoal>(subject);
129 const double dist = getGoalDist(goalSubject);
131 if (dist > m_lastGoalDist)
135 std::vector<double> tempScores;
136 tempScores.push_back(m_controllerStartDist - dist);
137 tempScores.push_back(0.0);
138 goalAdapter.endEpisode(tempScores);
143 m_controllerStartDist = dist;
145 throw std::runtime_error(
"Moved away from goal");
149 m_feedbackControlTime = 0;
150 m_lastGoalDist = dist;
153 const BaseSpineModelGoal* goalSubject = tgCast::cast<BaseSpineModelLearning, BaseSpineModelGoal>(subject);
154 std::vector<double> desComs = getGoalFeedback(goalSubject);
156 std::vector<double> desComs = getFeedback(subject);
161 m_pCPGSys->
update(desComs, m_updateTime);
163 catch (std::runtime_error& e)
170 #ifdef LOGGING // Conditional compile for data logging
171 m_dataObserver.
onStep(subject, m_updateTime);
177 double currentHeight = subject.getSegmentCOM(m_config.segmentNumber)[1];
180 if (currentHeight > 25 || currentHeight < 1.0)
184 throw std::runtime_error(
"Height out of range");
193 const BaseSpineModelGoal* goalSubject = tgCast::cast<BaseSpineModelLearning, BaseSpineModelGoal>(subject);
195 const double distanceMoved = calculateDistanceMoved(goalSubject);
199 scores.push_back(-1.0);
203 scores.push_back(distanceMoved);
208 double totalEnergySpent=0;
210 std::vector<tgSpringCableActuator* > tmpStrings = subject.getAllMuscles();
212 for(
int i=0; i<tmpStrings.size(); i++)
219 const double previousLength = stringHist.
restLengths[j-1];
220 const double currentLength = stringHist.
restLengths[j];
222 double motorSpeed = (currentLength-previousLength);
225 const double workDone = previousTension * motorSpeed;
226 totalEnergySpent += workDone;
230 scores.push_back(totalEnergySpent);
233 nodeAdapter.endEpisode(scores);
234 feedbackAdapter.endEpisode(scores);
236 const double dist = getGoalDist(goalSubject);
237 std::vector<double> tempScores;
238 tempScores.push_back(m_controllerStartDist - dist);
239 tempScores.push_back(0.0);
240 goalAdapter.endEpisode(tempScores);
245 for(
size_t i = 0; i < m_allControllers.size(); i++)
247 delete m_allControllers[i];
249 m_allControllers.clear();
255 std::vector<double> finalConditions = subject->getSegmentCOM(m_config.segmentNumber);
257 const btVector3 goalPos = subject->goalBoxPosition();
259 double x= finalConditions[0] - goalPos.getX();
260 double z= finalConditions[2] - goalPos.getZ();
261 double distanceNew=sqrt(x*x + z*z);
Contains the definition of class ImpedanceControl. $Id$.
void initialize(NeuroEvolution *evo, bool isLearning, configuration config)
Config(int ss, int tm, int om, int param, int segnum=6, double ct=0.1, double la=0, double ha=30, double lp=-1 *M_PI, double hp=M_PI, double kt=0.0, double kp=1000.0, double kv=100.0, bool def=true, double cl=10.0, double lf=0.0, double hf=30.0, double ffMin=0.0, double ffMax=0.0, double afMin=0.0, double afMax=0.0, double pfMin=0.0, double pfMax=0.0, double tf=0.0, double feedTime=1.0)
void update(std::vector< double > &descCom, double dt)
std::deque< double > tensionHistory
A controller for the template class BaseSpineModelLearning.
std::deque< double > restLengths
virtual void onSetup(BaseSpineModelLearning &subject)
virtual void onStep(BaseSpineModelLearning &subject, double dt)
Definition of the tgCPGStringControl observer class.
Implementing the tetrahedral complex spine inspired by Tom Flemons.
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.
AnnealAdapter edgeAdapter
Contains the definition of class AnnealEvolution. Adapting NeuroEvolution to do Simulated Annealing...
Contains the definition of class tgBasicActuator.
virtual void onStep(tgModel &model, double dt)
virtual void onSetup(BaseSpineModelLearning &subject)
virtual void onTeardown(BaseSpineModelLearning &subject)
Definition of class CPGEquationsFB.
Rand seeding simular to the evolution and terrain classes.
SpineOnlineControl(SpineOnlineControl::Config config, std::string args, std::string resourcePath="", std::string ec="edgeConfig.ini", std::string nc="nodeConfig.ini", std::string fc="feedbackConfig.ini", std::string gc="goalConfig.ini")
void notifyStep(double dt)