Skip to content

Commit

Permalink
Merge pull request #192 from diegoferigo/refactor/rename_logger
Browse files Browse the repository at this point in the history
Rename log macros
  • Loading branch information
diegoferigo authored Apr 30, 2020
2 parents 3eb5893 + 6bc2496 commit 909d21e
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 319 deletions.
27 changes: 18 additions & 9 deletions cpp/gympp/base/Space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ bool Box::contains(const Space::Sample& data) const

// Check the type
if (!bufferPtr) {
gymppError << "Failed to get the buffer or the supported type from the sample" << std::endl;
gymppError
<< "Failed to get the buffer or the supported type from the sample"
<< std::endl;
return false;
}

Expand All @@ -94,14 +96,17 @@ bool Box::contains(const Space::Sample& data) const

if (bufferPtr->size() != pImpl->shape[0]) {
gymppError << "The size of the buffer (" << bufferPtr->size()
<< ") does not match with the shape of the space (" << pImpl->shape[0] << ")"
<< std::endl;
<< ") does not match with the shape of the space ("
<< pImpl->shape[0] << ")" << std::endl;
return false;
}

for (unsigned i = 0; i < bufferPtr->size(); ++i) {
if (((*bufferPtr)[i] > pImpl->high[i]) || ((*bufferPtr)[i] < pImpl->low[i])) {
gymppError << "The sample does not comply to the limits set for its space" << std::endl;
if (((*bufferPtr)[i] > pImpl->high[i])
|| ((*bufferPtr)[i] < pImpl->low[i])) {
gymppError
<< "The sample does not comply to the limits set for its space"
<< std::endl;
return false;
}
}
Expand Down Expand Up @@ -165,21 +170,25 @@ bool Discrete::contains(const Space::Sample& data) const

// Check the type
if (!bufferPtr) {
gymppError << "Failed to get the buffer or the supported type from the sample" << std::endl;
gymppError
<< "Failed to get the buffer or the supported type from the sample"
<< std::endl;
return false;
}

// TODO: only 1D
assert(pImpl->shape.size() == 1);
if (bufferPtr->size() != pImpl->shape.size()) {
gymppError << "The size of the buffer (" << bufferPtr->size()
<< ") does not match with the shape of the space (" << pImpl->shape.size() << ")"
<< std::endl;
<< ") does not match with the shape of the space ("
<< pImpl->shape.size() << ")" << std::endl;
return false;
}

if ((*bufferPtr)[0] < 0 || (*bufferPtr)[0] >= pImpl->n) {
gymppError << "The sample does not comply to the limits set for its space" << std::endl;
gymppError
<< "The sample does not comply to the limits set for its space"
<< std::endl;
return false;
}

Expand Down
11 changes: 8 additions & 3 deletions cpp/gympp/base/include/gympp/base/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace gympp {
using BufferLong = BufferContainer<size_t>::type;
using BufferFloat = BufferContainer<float>::type;
using BufferDouble = BufferContainer<double>::type;
using GenericBuffer = std::variant<BufferInt, BufferLong, BufferFloat, BufferDouble>;
using GenericBuffer =
std::variant<BufferInt, BufferLong, BufferFloat, BufferDouble>;

namespace data {
using Shape = std::vector<size_t>;
Expand Down Expand Up @@ -63,7 +64,8 @@ struct gympp::base::data::Sample
template <typename T>
std::optional<T> get(const size_t i) const
{
auto bufferPtr = std::get_if<typename BufferContainer<T>::type>(&buffer);
auto bufferPtr =
std::get_if<typename BufferContainer<T>::type>(&buffer);

if (!bufferPtr) {
return {};
Expand Down Expand Up @@ -100,7 +102,10 @@ struct gympp::base::Range
DataSupport min = 0;
DataSupport max = 0;

bool contains(double value) { return (value <= max && value >= min) ? true : false; }
bool contains(double value)
{
return (value <= max && value >= min) ? true : false;
}
};

#endif // GYMPP_BASE_COMMON
3 changes: 0 additions & 3 deletions cpp/gympp/base/include/gympp/base/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ struct gympp::base::State
gympp::base::Observation observation;
};

// TODO: https://hub.packtpub.com/openai-gym-environments-wrappers-and-monitors-tutorial/
// These C++ and their mapping to python / julia should allow using the Wrapper method

// From https://github.com/openai/gym/blob/master/gym/core.py
class gympp::base::Environment
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/gympp/base/include/gympp/base/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace gympp {
namespace base {
class Task;
} // namespace gazebo
} // namespace base
} // namespace gympp

class gympp::base::Task
Expand Down
30 changes: 15 additions & 15 deletions cpp/scenario/controllers/src/ComputedTorqueFixedBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,29 @@ ComputedTorqueFixedBase::~ComputedTorqueFixedBase() {}

bool ComputedTorqueFixedBase::initialize()
{
gymppDebug << "Initializing ComputedTorqueFixedBaseCpp" << std::endl;
sDebug << "Initializing ComputedTorqueFixedBaseCpp" << std::endl;

if (pImpl->kinDyn) {
gymppWarning
sWarning
<< "The KinDynComputations object has been already initialized"
<< std::endl;
return true;
}

if (!(m_model && m_model->valid())) {
gymppError << "Couldn't initialize controller. Model not valid."
sError << "Couldn't initialize controller. Model not valid."
<< std::endl;
return false;
}

if (m_controlledJoints.size() != m_model->dofs()
|| m_controlledJoints.empty()) {
gymppError << "The list of controlled joints is not valid" << std::endl;
sError << "The list of controlled joints is not valid" << std::endl;
return false;
}

if (m_controlledJoints.empty()) {
gymppDebug << "No list of controlled joints. Controlling all the "
sDebug << "No list of controlled joints. Controlling all the "
"robots joints."
<< std::endl;

Expand All @@ -170,7 +170,7 @@ bool ComputedTorqueFixedBase::initialize()

for (auto& joint : m_model->joints(m_controlledJoints)) {
if (joint->dofs() != 1) {
gymppError << "Joint '" << joint->name()
sError << "Joint '" << joint->name()
<< "' does not have 1 DoF and is not supported"
<< std::endl;
return false;
Expand All @@ -179,7 +179,7 @@ bool ComputedTorqueFixedBase::initialize()

iDynTree::ModelLoader loader;
if (!loader.loadReducedModelFromFile(pImpl->urdfFile, m_controlledJoints)) {
gymppError << "Failed to load reduced model from the urdf file"
sError << "Failed to load reduced model from the urdf file"
<< std::endl;
return false;
}
Expand All @@ -189,7 +189,7 @@ bool ComputedTorqueFixedBase::initialize()
iDynTree::MIXED_REPRESENTATION);

if (!pImpl->kinDyn->loadRobotModel(loader.model())) {
gymppError << "Failed to insert model in the KinDynComputations object"
sError << "Failed to insert model in the KinDynComputations object"
<< std::endl;
return false;
}
Expand All @@ -199,14 +199,14 @@ bool ComputedTorqueFixedBase::initialize()
pImpl->initialValues.controlMode[joint->name()] = joint->controlMode();

if (!joint->setControlMode(base::JointControlMode::Force)) {
gymppError << "Failed to control joint '" << joint->name()
sError << "Failed to control joint '" << joint->name()
<< "' in Force" << std::endl;
return false;
}
}

// Initialize buffers
gymppDebug << "Controlling " << m_controlledJoints.size() << " DoFs"
sDebug << "Controlling " << m_controlledJoints.size() << " DoFs"
<< std::endl;
pImpl->buffers = std::make_unique<Impl::Buffers>(m_controlledJoints.size());

Expand Down Expand Up @@ -283,7 +283,7 @@ bool ComputedTorqueFixedBase::step(const Controller::StepSize& /*dt*/)

if (!m_model->setJointGeneralizedForceTargets(pImpl->buffers->torquesVector,
m_controlledJoints)) {
gymppError << "Failed to set joint forces" << std::endl;
sError << "Failed to set joint forces" << std::endl;
return false;
}

Expand All @@ -300,7 +300,7 @@ bool ComputedTorqueFixedBase::terminate()
auto joint = m_model->getJoint(jointName);

if (!joint->setControlMode(controlMode)) {
gymppError << "Failed to restore original control mode of joint '"
sError << "Failed to restore original control mode of joint '"
<< jointName << "'" << std::endl;
ok = ok && false;
}
Expand Down Expand Up @@ -332,17 +332,17 @@ bool ComputedTorqueFixedBase::updateStateFromModel()
if (!pImpl->kinDyn->setRobotState(pImpl->buffers->jointPositions,
pImpl->buffers->jointVelocities,
pImpl->buffers->gravity)) {
gymppError << "Failed to set the robot state" << std::endl;
sError << "Failed to set the robot state" << std::endl;
return false;
}

if (!pImpl->kinDyn->getFreeFloatingMassMatrix(pImpl->buffers->massMatrix)) {
gymppError << "Failed to get the mass matrix" << std::endl;
sError << "Failed to get the mass matrix" << std::endl;
return false;
}

if (!pImpl->kinDyn->generalizedBiasForces(pImpl->buffers->biasForces)) {
gymppError << "Failed to get the bias forces " << std::endl;
sError << "Failed to get the bias forces " << std::endl;
return false;
}

Expand Down
7 changes: 3 additions & 4 deletions cpp/scenario/gazebo/include/scenario/gazebo/Joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,9 @@ struct scenario::base::JointLimit
: JointLimit(std::min(_min.size(), _max.size()))
{
if (_min.size() != _max.size()) {
gymppWarning
<< "The max and min limits have different size. "
<< "Ignoring the limits and using the smaller dimension."
<< std::endl;
sWarning << "The max and min limits have different size. "
<< "Ignoring the limits and using the smaller dimension."
<< std::endl;
return;
}

Expand Down
8 changes: 4 additions & 4 deletions cpp/scenario/gazebo/include/scenario/gazebo/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#define SCENARIO_GAZEBO_LOG

#include <ignition/common/Console.hh>
#define gymppError ::ignition::common::Console::err(__FILE__, __LINE__)
#define gymppWarning ::ignition::common::Console::warn(__FILE__, __LINE__)
#define gymppMessage ::ignition::common::Console::msg(__FILE__, __LINE__)
#define gymppDebug ::ignition::common::Console::dbg(__FILE__, __LINE__)
#define sError ::ignition::common::Console::err(__FILE__, __LINE__)
#define sWarning ::ignition::common::Console::warn(__FILE__, __LINE__)
#define sMessage ::ignition::common::Console::msg(__FILE__, __LINE__)
#define sDebug ::ignition::common::Console::dbg(__FILE__, __LINE__)
#define gymppLog ::ignition::common::Console::log(__FILE__, __LINE__)

#endif // SCENARIO_GAZEBO_LOG
Loading

0 comments on commit 909d21e

Please sign in to comment.