@@ -64,6 +64,9 @@ using Init_t = limbo::init::LHS<DifferentialCPG::Params>;
6464using Kernel_t = limbo::kernel::MaternFiveHalves<DifferentialCPG::Params>;
6565using GP_t = limbo::model::GP<DifferentialCPG::Params, Kernel_t, Mean_t>;
6666
67+
68+
69+
6770/* *
6871 * Constructor for DifferentialCPG class.
6972 *
@@ -74,10 +77,13 @@ DifferentialCPG::DifferentialCPG(
7477 const ::gazebo::physics::ModelPtr &_model,
7578 const sdf::ElementPtr robot_config,
7679 const std::vector< revolve::gazebo::MotorPtr > &_motors,
77- const std::vector< revolve::gazebo::SensorPtr > &_sensors)
80+ const std::vector< revolve::gazebo::SensorPtr > &_sensors,
81+ std::shared_ptr<::revolve::gazebo::Battery> battery
82+ )
7883 : next_state(nullptr )
7984 , input(new double [_sensors.size()])
8085 , output(new double [_motors.size()])
86+ , battery_(battery)
8187{
8288
8389 this ->learner = robot_config->GetElement (" rv:brain" )->GetElement (" rv:learner" );
@@ -279,17 +285,24 @@ DifferentialCPG::DifferentialCPG(
279285 }
280286 }
281287
288+
289+
282290 // Create directory for output.
283- this ->directory_name = controller->GetAttribute (" output_directory" )->GetAsString ();
291+ // this->directory_name = controller->GetAttribute("output_directory")->GetAsString();
284292 if (this ->directory_name .empty ())
285293 {
286- this ->directory_name = " output/cpg_bo/" ;
287- this ->directory_name += std::to_string (time (0 )) + " /" ;
294+ std::cout << " §yes§" ;
295+ this ->directory_name = " output/cpg_bo/" + this ->robot ->GetName () + " /" ; // CHANGETHIS
296+ this ->directory_name += this ->battery_ ->time_init + " /" ;
288297 }
298+ else
299+ std::cout << " §no§\n " ;
300+
301+
289302
290- std::system ((" mkdir -p " + this ->directory_name ).c_str ());
303+ std::system ((" mkdir -p " + this ->directory_name ).c_str ());
291304
292- // Initialise array of neuron states for Update() method
305+ // Initialise array of neuron states for Update() methodc
293306 this ->next_state = new double [this ->neurons .size ()];
294307 this ->n_weights = (int )(this ->connections .size ()/2 ) + this ->n_motors ;
295308
@@ -353,7 +366,7 @@ DifferentialCPG::DifferentialCPG(
353366 }
354367
355368 // Initiate the cpp Evaluator
356- this ->evaluator .reset (new Evaluator (this ->evaluation_rate ));
369+ this ->evaluator .reset (new Evaluator (battery, this ->evaluation_rate ));
357370 this ->evaluator ->directory_name = this ->directory_name ;
358371}
359372
@@ -370,9 +383,21 @@ DifferentialCPG::~DifferentialCPG()
370383/* *
371384 * Dummy function for limbo
372385 */
386+
387+
373388struct DifferentialCPG ::evaluation_function{
374389 // Number of input dimension (samples.size())
375- BO_PARAM (size_t , dim_in, 18 );
390+ // spider9:18,
391+ // spider13:26,
392+ // spider17:34,
393+ // gecko7:13,
394+ // gecko12:23,
395+ // gecko17:33,
396+ // babyA:16,
397+ // babyB:22,
398+ // babyC:32,
399+ // one+:12
400+ BO_PARAM (size_t , dim_in, 13 ); // CHANGETHIS
376401
377402 // number of dimensions of the fitness
378403 BO_PARAM (size_t , dim_out, 1 );
@@ -409,6 +434,9 @@ void DifferentialCPG::bo_init_sampling(){
409434 Eigen::VectorXd init_sample (this ->n_weights );
410435
411436 // For all weights
437+ srand ((unsigned )time (NULL ));
438+ // trash first one, because it could be the same and I do not know why
439+ auto trash_first = rand ();
412440 for (size_t j = 0 ; j < this ->n_weights ; j++)
413441 {
414442 // Generate a random number in [0, 1]. Transform later
@@ -456,6 +484,9 @@ void DifferentialCPG::bo_init_sampling(){
456484 Eigen::VectorXd init_sample (this ->n_weights );
457485
458486 // For all dimensions
487+ srand ((unsigned )time (NULL ));
488+ // trash first one, because it could be the same and I do not know why
489+ auto trash_first = rand ();
459490 for (size_t j = 0 ; j < this ->n_weights ; j++)
460491 {
461492 // Take a LHS
@@ -637,6 +668,7 @@ void DifferentialCPG::bo_step(){
637668 limbo::acquifun<limbo::acqui::UCB<DifferentialCPG::Params, GP_t>>> boptimizer;
638669
639670 // Optimize. Pass dummy evaluation function and observations .
671+
640672 boptimizer.optimize (DifferentialCPG::evaluation_function (),
641673 this ->samples ,
642674 this ->observations );
@@ -814,7 +846,7 @@ void DifferentialCPG::Update(
814846 {
815847 std::cout << std::endl << " I am finished " << std::endl;
816848 }
817- std::exit (0 );
849+ // std::exit(0);
818850 }
819851
820852 // Evaluation policy here
0 commit comments