Robotics StackExchange | Archived questions

Error while compiling Gazebo Ros plugin

Hello, I am using Ubuntu 14.04 and ROS Indigo with Gazebo 2.2.6. I am trying to compile a gazebo ros plugin. Here is the code.

armbot_plugin.hpp:

#ifndef _ARMBOT_PLUGIN_HH_
#define _ARMBOT_PLUGIN_HH_

#include <iostream>
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <gazebo/common/Plugin.hh>

namespace gazebo{

class GAZEBO_VISIBLE RobotDriver : public WorldPlugin
{
private:
  //! The node handle we'll be using
  ros::NodeHandle nh_;
 //! We will be publishing to the "/base_controller/command" topic to issue commands
 ros::Publisher cmd_vel_pub_;

  public:
    //! ROS node initialization
    RobotDriver(ros::NodeHandle &nh) : WorldPlugin()
 {
   nh_ = nh;
   //set up the publisher for the cmd_vel topic
   cmd_vel_pub_ = nh_.advertise<geometry_msgs::Twist>("/base_controller/command", 1);
 }

 //! Loop forever while sending drive commands based on keyboard input
 bool driveKeyboard()
 {
   std::cout << "Type the angle in rads (0,0.5) and press enter  "
     "Press '.' to exit.\n";

   //we will be sending commands of type "twist"
   geometry_msgs::Twist base_cmd;

   int cmd;
   while(nh_.ok()){

     std::cin >> cmd;
     if(cmd>0.5 || cmd<0  && cmd!='.')
     {
       std::cout << "unknown command:" << cmd << "\n";
       continue;
  }

  //base_cmd.linear.x = base_cmd.linear.y = base_cmd.angular.z = 0;
  //turn left (yaw) and drive forward at the same time


  //quit
 else if(cmd=='.'){
    break;
  }
  else {
    base_cmd.angular.y = cmd;
  }

std::cout << "Type the twist in rads (-0.5,0.5) and press enter  "
  "Press '.' to exit.\n";
  cmd=0;
  std::cin >> cmd;
  if(cmd>0.5 || cmd<-0.5  && cmd!='.')
  {
    std::cout << "unknown command:" << cmd << "\n";
    continue;
  }

  //quit
 else if(cmd=='.'){
    break;
  }
else {
    base_cmd.angular.z = cmd;
  }
  //publish the assembled command
  cmd_vel_pub_.publish(base_cmd);
}
return true;
 }
  };
  }
  #endif

armbot_plugin.cpp:

#include <iostream>
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include "armbot_plugin.hpp"

using namespace gazebo;
GZ_REGISTER_WORLD_PLUGIN(RobotDriver)

int main(int argc, char** argv)
{
  //init the ROS node
  ros::init(argc, argv, "robot_driver");
  ros::NodeHandle nh;

  RobotDriver driver(nh);
  driver.driveKeyboard();
  }

and I get the following errors

In file included from /home/sofia/catkin_ws/src/armbot_plugin/src/armbot_plugin.cpp:4:0:
/home/sofia/catkin_ws/src/armbot_plugin/src/armbot_plugin.hpp:13:34: error: expected initializer before ‘:’ token
 class GAZEBO_VISIBLE RobotDriver : public WorldPlugin
                                  ^
/home/sofia/catkin_ws/src/armbot_plugin/src/armbot_plugin.cpp:18:1: error: expected ‘}’ at end of input
 }
 ^
make[2]: *** [armbot_plugin/CMakeFiles/armbot_plugin.dir/src/armbot_plugin.cpp.o] Error 1
make[1]: *** [armbot_plugin/CMakeFiles/armbot_plugin.dir/all] Error 2
make: *** [all] Error 2

If I remove the "GAZEBO_VISIBLE" Macro I get this error:

In file included from /home/sofia/catkinws/src/armbotplugin/src/armbotplugin.hpp:8:0, from /home/sofia/catkinws/src/armbotplugin/src/armbotplugin.cpp:4: /home/sofia/catkinws/src/armbotplugin/src/armbotplugin.cpp: In function ‘gazebo::WorldPlugin* RegisterPlugin()’: /usr/include/gazebo-2.2/gazebo/common/Plugin.hh:408:26: error: cannot allocate an object of abstract type ‘gazebo::RobotDriver’ return new classname();\ ^ /home/sofia/catkinws/src/armbotplugin/src/armbotplugin.cpp:8:1: note: in expansion of macro ‘GZREGISTERWORLDPLUGIN’ GZREGISTERWORLDPLUGIN(RobotDriver) ^ In file included from /home/sofia/catkinws/src/armbotplugin/src/armbotplugin.cpp:4:0: /home/sofia/catkinws/src/armbotplugin/src/armbotplugin.hpp:13:7: note: because the following virtual functions are pure within ‘gazebo::RobotDriver’: class RobotDriver : public WorldPlugin ^ In file included from /home/sofia/catkinws/src/armbotplugin/src/armbotplugin.hpp:8:0, from /home/sofia/catkinws/src/armbotplugin/src/armbotplugin.cpp:4: /usr/include/gazebo-2.2/gazebo/common/Plugin.hh:268:26: note: virtual void gazebo::WorldPlugin::Load(gazebo::physics::WorldPtr, sdf::ElementPtr) public: virtual void Load(physics::WorldPtr world, ^ /home/sofia/catkinws/src/armbotplugin/src/armbotplugin.cpp: In function ‘int main(int, char*)’: /home/sofia/catkinws/src/armbotplugin/src/armbotplugin.cpp:16:15: error: cannot declare variable ‘driver’ to be of abstract type ‘gazebo::RobotDriver’ RobotDriver driver(nh); ^ In file included from /home/sofia/catkinws/src/armbotplugin/src/armbotplugin.cpp:4:0: /home/sofia/catkinws/src/armbotplugin/src/armbot_plugin.hpp:13:7: note: since type ‘gazebo::RobotDriver’ has pure virtual functions class RobotDriver : public WorldPlugin ^ make[2]: ** [armbotplugin/CMakeFiles/armbotplugin.dir/src/armbotplugin.cpp.o] Error 1 make[1]: *** [armbotplugin/CMakeFiles/armbot_plugin.dir/all] Error 2 make: *** [all] Error 2

Asked by sofia.gr on 2017-06-12 04:05:46 UTC

Comments

Answers