gzerr couldn't be resolved (mobile_base plugin)
Hey guys,
I just wanted to control my mobile platform by adapting the code from the [http://gazebosim.org/wiki/Tutorials/1...robot/mobilebase] tutorial. I am using the newest gazebo version.
I compiled the plugin using the CMakeLists.txt and after that imported the project in Eclipse.
When I wanted to rebuild the project, Eclipse threw some error messages regarding the gzerr
macro saying the function Instance
and the method ColorErr
could not be resolved. I also tried to call the function directly with the same results. The only thing I changed is the class name.
Here is the plugin code so far:
#include <boost/bind.hpp>
#include <gazebo.hh>
#include <physics/physics.hh>
#include <common/common.hh>
#include <stdio.h>
#include <string>
namespace gazebo
{
class PlattformControlPlugin : public ModelPlugin
{
public: void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
{
// Store the pointer to the model
this->model = _parent;
// Load parameters for this plugin
if (this->LoadParams(_sdf))
{
// Listen to the update event. This event is broadcast every
// simulation iteration.
this->updateConnection = event::Events::ConnectWorldUpdateStart(
boost::bind(&PlattformControlPlugin::OnUpdate, this));
}
}
public: bool LoadParams(sdf::ElementPtr _sdf)
{
if (this->FindJointByParam(_sdf, this->left_wheel_joint_,
"left_wheel_hinge") &&
this->FindJointByParam(_sdf, this->right_wheel_joint_,
"right_wheel_hinge"))
return true;
else
return false;
}
public: bool FindJointByParam(sdf::ElementPtr _sdf,
physics::JointPtr &_joint,
std::string _param)
{
if (!_sdf->HasElement(_param))
{
// original plugin code
gzerr << "param [" << _param << "] not found\n";
// My call without using the macro
//common::Console::Instance()->ColorErr("Error", __FILE__, __LINE__, 31)
// << "param [" << _param << "] not found\n";
return false;
}
else
{
_joint = this->model->GetJoint(
_sdf->GetElement(_param)->GetValueString());
if (!_joint)
{
gzerr << "joint by name ["
<< _sdf->GetElement(_param)->GetValueString()
<< "] not found in model\n";
return false;
}
}
return true;
}
// Called by the world update start event
public: void OnUpdate()
{
this->left_wheel_joint_->SetForce(0, 0.2);
this->right_wheel_joint_->SetForce(0, -0.2);
}
// Pointer to the model
private: physics::ModelPtr model;
// Pointer to the update event connection
private: event::ConnectionPtr updateConnection;
private: physics::JointPtr left_wheel_joint_;
private: physics::JointPtr right_wheel_joint_;
};
// Register this plugin with the simulator
GZ_REGISTER_MODEL_PLUGIN(PlattformControlPlugin)
}
I tested the plugin using std::cerr for the moment. And I didn't get my platform moving, because the plugin couldn't find my joints. I tried using the names with and without the namespace of my sdf-file. And in Gazebo I can see those names.
The plugin doesn't get further than to this point:
if (!_sdf->HasElement(_param))
{
// original plugin code
gzerr << "param [" << _param << "] not found\n";
// My call without using the macro
//common::Console::Instance()->ColorErr("Error", __FILE__, __LINE__, 31)
// << "param [" << _param << "] not found\n";
return false;
}
Tia, Christoph