0
$\begingroup$

Rosanswers logo

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: ‘mapose’ was not declared in this scope
       this->model->SetLinkWorldPose(mapose,"WheelFR_link");
                                     ^~~~~~
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:42:37: note: suggested alternative: ‘raise’
       this->model->SetLinkWorldPose(mapose,"WheelFR_link");
                                     ^~~~~~
                                     raise
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:44:11: error: request for member ‘vecteur_str’ in ‘(gazebo::WorldPluginTutorial*)this’, which is of pointer type ‘gazebo::WorldPluginTutorial*’ (maybe you meant to use ‘->’ ?)
      this.vecteur_str = ["head","base","joint3","whatever"];
           ^~~~~~~~~~~
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:44:26: error: expected identifier before string constant
      this.vecteur_str = ["head","base","joint3","whatever"];
                          ^~~~~~
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:44:32: error: expected ‘]’ before ‘,’ token
      this.vecteur_str = ["head","base","joint3","whatever"];
                                ^
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp: In lambda function:
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:44:32: error: expected ‘{’ before ‘,’ token
/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:45:34: error: ‘class gazebo::WorldPluginTutorial’ has no member named ‘vecteur_str’
       for (int i = 0 ; i < this->vecteur_str.size(); i++)
                                  ^~~~~~~~~~~
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:50:15: error: ‘class gazebo::WorldPluginTutorial’ has no member named ‘model’
         this->model->GetJoint(vecteur_str[i])->SetForce(unsigned int _index, double _effort)
               ^~~~~
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:50:31: error: ‘vecteur_str’ was not declared in this scope
         this->model->GetJoint(vecteur_str[i])->SetForce(unsigned int _index, double _effort)
                               ^~~~~~~~~~~
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:50:31: note: suggested alternative: ‘avio_put_str’
         this->model->GetJoint(vecteur_str[i])->SetForce(unsigned int _index, double _effort)
                               ^~~~~~~~~~~
                               avio_put_str
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:50:57: error: expected primary-expression before ‘unsigned’
         this->model->GetJoint(vecteur_str[i])->SetForce(unsigned int _index, double _effort)
                                                         ^~~~~~~~
/home/admin/catkin_ws8/src/gazebo_tutorials/src/simple_world_plugin.cpp:50:78: error: expected primary-expression before ‘double’
         this->model->GetJoint(vecteur_str[i])->SetForce(unsigned int _index, double _effort)
                                                                              ^~~~~~
gazebo_tutorials/CMakeFiles/gazebo_tutorials.dir/build.make:62: recipe for target 'gazebo_tutorials/CMakeFiles/gazebo_tutorials.dir/src/simple_world_plugin.cpp.o' failed
make[2]: *** [gazebo_tutorials/CMakeFiles/gazebo_tutorials.dir/src/simple_world_plugin.cpp.o] Error 1
CMakeFiles/Makefile2:1233: recipe for target 'gazebo_tutorials/CMakeFiles/gazebo_tutorials.dir/all' failed
make[1]: *** [gazebo_tutorials/CMakeFiles/gazebo_tutorials.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j12 -l12" failed

Originally posted by pip on ROS Answers with karma: 16 on 2020-04-20

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I am not sure what was the required environmental setup, but following this tutorial and manipulating the variables/model was a good work around for me.


Originally posted by pip with karma: 16 on 2020-04-25

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.