Error Compiling Gazebo Plugin
I have been trying to move a model car in Gazebo using a plugin. I first followed the ROS plugin tutorial and everything was working accordingly. I then used the code from this answer but I got bombarded by so many errors. I tried compiling the skeleton with the header files and it worked fine. However, whenever I add the code (even the constructor code alone) I get some errors. So I'm assuming its not a problem with the environment, but rather with my lack of knowledge of OOP in cpp/gazebo ? I am using ROS melodic and Gazebo 9. I would really appreciate if someone can have a look and tell me where I can start from, since I've been reaching dead ends for days because of this.
Here is my whole code:
#include <gazebo/common/Plugin.hh>
#include <ros/ros.h>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
namespace gazebo
{
class WorldPluginTutorial : public WorldPlugin
{
public:
WorldPluginTutorial() : WorldPlugin()
{
printf("Hello World!\n");
gazebo::physics::ModelPtr this->model ;
}
void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
{
// Make sure the ROS node for Gazebo has already been initialized
if (!ros::isInitialized())
{
ROS_FATAL_STREAM("A ROS node for Gazebo has not been initialized, unable to load plugin. "
<< "Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
return;
}
ROS_INFO("Hello World!");
this->model = _world->GetModel("my_robot");
}
public : void OnUpdate(const common::UpdateInfo & /*_info*/)
{
// Apply a small linear velocity to the model.
//this->model->SetLinearVel(math::Vector3(0, 0, 0)); // just in case needed
// pose of the footprint
gazebo::math::Pose mapose(this->vect3_pose_model, this->rot_pose_model);
this->model->SetLinkWorldPose(mapose,"WheelFR_link");
//pose of every joint
this.vecteur_str = ["head","base","joint3","whatever"];
for (int i = 0 ; i < this->vecteur_str.size(); i++)
{
//what I used to control the joints
//this->model->GetJoint(vecteur_str[i])->SetAngle(0, vecteur_effort[i]);
// This is what you want
this->model->GetJoint(vecteur_str[i])->SetForce(unsigned int _index, double _effort)
}
}
};
GZ_REGISTER_WORLD_PLUGIN(WorldPluginTutorial)
}
And these are the errors I'm getting:
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp: In constructor ‘gazebo::WorldPluginTutorial::WorldPluginTutorial()’:
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:14:33: error: expected unqualified-id before ‘this’
gazebo::physics::ModelPtr this->model ;
^~~~
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp: In member function ‘virtual void gazebo::WorldPluginTutorial::Load(gazebo::physics::WorldPtr, sdf::ElementPtr)’:
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:30:11: error: ‘class gazebo::WorldPluginTutorial’ has no member named ‘model’
this->model = _world->GetModel("my_robot");
^~~~~
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:30:27: error: ‘class gazebo::physics::World’ has no member named ‘GetModel’; did you mean ‘Models’?
this->model = _world->GetModel("my_robot");
^~~~~~~~
Models
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp: In member function ‘void gazebo::WorldPluginTutorial::OnUpdate(const gazebo::common::UpdateInfo&)’:
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:41:15: error: ‘gazebo::math’ has not been declared
gazebo::math::Pose mapose(this->vect3_pose_model, this->rot_pose_model);
^~~~
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:42:13: error: ‘class gazebo::WorldPluginTutorial’ has no member named ‘model’
this->model->SetLinkWorldPose(mapose,"WheelFR_link");
^~~~~
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:42:37: error ...