-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged battery roy's branch into revolve battery branched from develo…
…pment.
- Loading branch information
Showing
35 changed files
with
1,622 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Created by Roy Basmacier on 2019-07-09. | ||
// | ||
|
||
#include "Battery.h" | ||
|
||
using namespace revolve::gazebo; | ||
|
||
Battery::Battery(double initial_charge) | ||
: initial_charge(initial_charge), current_charge(initial_charge), time_init(std::to_string(time(0))), robot_name("") | ||
{} | ||
|
||
void Battery::Update(double global_time, double delta_time) | ||
{ | ||
double sum = 0.0; | ||
// std::cout << "battery: " << this->Voltage() << "V" << std::endl; | ||
for (const auto &consumer: this->PowerLoads()) { | ||
// std::cout << "comsumer: " << consumer.first << " -> " << consumer.second << std::endl; | ||
sum += consumer.second; // TODO add constant so its linear | ||
} | ||
this->current_charge += sum * delta_time; // charge is measured in joules | ||
|
||
//TODO properly save battery data somewhere | ||
std::ofstream b_info_file; | ||
b_info_file.open("output/cpg_bo/" + this->robot_name + "/" + this->time_init + "/battery.txt", std::ios_base::app); | ||
if (b_info_file.fail()) | ||
std::cout << "Failed to open: " << b_info_file.fail() << " " << "output/cpg_bo/" + this->robot_name + "/" + this->time_init + "/battery.txt" << std::endl; | ||
b_info_file << global_time << " " << sum << " " << current_charge << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Created by Roy Basmacier on 2019-07-09. | ||
// | ||
|
||
#ifndef REVOLVE_BATTERY_H | ||
#define REVOLVE_BATTERY_H | ||
|
||
|
||
#include <gazebo/gazebo.hh> | ||
#include <gazebo/physics/physics.hh> | ||
#include <gazebo/common/common.hh> | ||
#include <gazebo/msgs/msgs.hh> | ||
|
||
#include <revolve/gazebo/Types.h> | ||
|
||
namespace revolve{ | ||
namespace gazebo{ | ||
|
||
class Battery : public ::gazebo::common::Battery | ||
{ | ||
public: | ||
explicit Battery(double initial_charge); | ||
|
||
void Update(double global_time, double delta_time); | ||
|
||
protected: | ||
/// \brief initial charge of the battery in joules | ||
double initial_charge; // it is set in RobotController.cpp | ||
|
||
/// \brief current charge of the battery in joules | ||
double current_charge; | ||
|
||
/// \brief the time of initiation (for creating data files of battery delete later) | ||
std::string time_init; | ||
|
||
std::string robot_name; | ||
|
||
friend class RobotController; | ||
friend class Evaluator; | ||
friend class DifferentialCPG; | ||
}; | ||
|
||
} | ||
} | ||
|
||
#endif //REVOLVE_BATTERY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.