ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

GusBus's profile - activity

2022-11-18 02:56:10 -0500 received badge  Nice Question (source)
2021-11-29 09:23:25 -0500 received badge  Favorite Question (source)
2021-11-29 08:50:44 -0500 received badge  Famous Question (source)
2021-11-29 08:50:44 -0500 received badge  Notable Question (source)
2021-10-25 12:07:33 -0500 received badge  Famous Question (source)
2021-10-15 00:15:07 -0500 received badge  Nice Question (source)
2021-09-27 14:07:07 -0500 received badge  Famous Question (source)
2021-09-03 01:52:14 -0500 received badge  Famous Question (source)
2021-06-28 15:13:02 -0500 received badge  Notable Question (source)
2021-06-27 04:38:29 -0500 received badge  Popular Question (source)
2021-06-27 04:37:33 -0500 received badge  Popular Question (source)
2021-06-17 09:54:28 -0500 received badge  Enthusiast
2021-06-15 23:27:08 -0500 asked a question ROS2 Parameter Change and publishing to /parameter_events

ROS2 Parameter Change and publishing to /parameter_events I have been experimenting with ROS2 Params and have a question

2021-06-15 11:09:12 -0500 asked a question Creating Multiple Plugins from Single Package in ROS2

Creating Multiple Plugins from Single Package in ROS2 I am experimenting with the pluginlib and wondering if it is possi

2021-06-14 23:45:16 -0500 received badge  Notable Question (source)
2021-06-14 18:53:31 -0500 marked best answer Compiling a Simple Plugin in ROS2

I am trying to work through the simple plugin example (http://wiki.ros.org/pluginlib/Tutoria...) but cannot get it to build for ROS2.

Trying to use https://docs.ros.org/en/foxy/Guides/A... and the details in the tutorial, but I have limited CMake experience and cannot get it to build. Are there available examples that use ROS2?

Any help would be greatly appreciated.

EDIT

Been trying to piece together a few different resources and have got things to build, but now the library can't be found so I must be doing something wrong.

The plugin failed to load for some reason. Error: %sCould not find library corresponding to plugin

I've set up two packages, once containing the base class and one containing the plugins

Folder structure

src
-controller
 -include
  -Controller.h
 -src
  -ControlFramework.cpp
 CMakeLists.txt
 package.xml
-linear_controller
 -include
  -LinearController1.h
  -LinearController2.h
 -src
  -LinearController1.cpp
  -LinearController2.cpp
 CMakeLists.txt
 linear_controller_plugins.xml
 package.xml

Base Class

Controller.h

#pragma once

namespace control_base
{
    class Controller
    {
    public:
        Controller() {};
        virtual ~Controller() {};

        virtual bool initialize(double p, double i, double d) = 0;
        virtual double computeFeedback(double error) = 0;
    };
}

ControlFramework.cpp

#include <iostream>
#include <pluginlib/class_loader.hpp>
#include <controller/Controller.h>


using namespace std;

int main(int argc, char** argv)
{
  pluginlib::ClassLoader<control_base::Controller> poly_loader("linear_controller", "control_base::Controller");

  try
  {
    std::shared_ptr<control_base::Controller> triangle = poly_loader.createSharedInstance("control_plugins::LinearController1");
    triangle->initialize(10.0, 0.0, 0.0);

    std::shared_ptr<control_base::Controller> square = poly_loader.createSharedInstance("control_plugins::LinearController2");
    square->initialize(5.0, 0.0, 0.0);

    cout << "Triangle area: %.2f" << triangle->computeFeedback(2.0);
    cout << "Square area: %.2f" << square->computeFeedback(2.0);
  }
  catch(pluginlib::PluginlibException& ex)
  {
    cout << "The plugin failed to load for some reason. Error: %s" << ex.what();
  }

  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)
project(controller)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(pluginlib REQUIRED)

#Include directories
include_directories(
  include
)

set(plugins_dependencies
  pluginlib
)

add_executable(${PROJECT_NAME} 
  src/ControlFramework.cpp
)
ament_target_dependencies(${PROJECT_NAME} ${plugins_dependencies})


install(TARGETS ${PROJECT_NAME}
  DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY include/
  DESTINATION include/
)

ament_package()

package.xml

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>controller</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="angus@todo.todo">angus</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>pluginlib</depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

Plugin Package

LinearController1.h

#pragma once

#include <pluginlib/class_list_macros.hpp>
#include <controller/Controller.h>                      // Inheriting the base class

namespace control_plugins
{
  class LinearController1 : public control_base::Controller {
  public:
    LinearController1() {};                               // Constructor
                                                          // No destructor!
    bool initialize(double p, double i, double d);         
    double computeFeedback(double error);

  private:
    double _p_gain{0};
    double _i_gain{0};
    double _d_gain{0};
  };
}

LinearController1.cpp

#include <linear_controller/LinearController1.h>

namespace control_plugins 
{
  bool LinearController1::initialize(double p, double i, double d)
  {
    _p_gain = p;
    _i_gain = i;
    _d_gain = d;

    return true;
  }

  double LinearController1::computeFeedback(double ...
(more)
2021-06-14 18:51:49 -0500 answered a question Compiling a Simple Plugin in ROS2

So Using the diff_drive_controller I made quite a few changes to get things working: Created Separate packages for plug

2021-06-14 17:11:02 -0500 commented answer Compiling a Simple Plugin in ROS2

Thanks very much for the info and direction. I think your fixes were definitely necessary but still getting the same err

2021-06-14 10:08:20 -0500 received badge  Favorite Question (source)
2021-06-14 08:34:33 -0500 received badge  Popular Question (source)
2021-06-11 20:07:34 -0500 received badge  Editor (source)
2021-06-11 20:07:34 -0500 edited question Compiling a Simple Plugin in ROS2

Compiling a Simple Plugin in ROS2 I am trying to work through the simple plugin example (http://wiki.ros.org/pluginlib/T

2021-06-11 18:53:51 -0500 marked best answer Moveit2 Tutorial - Move Group C++ Interface. Not Avoiding the Placed Box

The tutorial runs flawlessly with no errors or failures, however when the box is placed in the world. The robot does not seem to care that it is there and rams right into it.

Tutorial Link: http://moveit2_tutorials.picknik.ai/d...

Has anyone else had this happen or seen this and have a solution?

2021-06-11 18:53:51 -0500 received badge  Scholar (source)
2021-06-11 18:53:38 -0500 received badge  Notable Question (source)
2021-06-11 18:50:33 -0500 asked a question Compiling a Simple Plugin in ROS2

Compiling a Simple Plugin in ROS2 I am trying to work through the simple plugin example (http://wiki.ros.org/pluginlib/T

2021-05-20 15:28:52 -0500 edited question Moveit2 Tutorial - Move Group C++ Interface. Not Avoiding the Placed Box

Moveit2 Tutorial - Move Group C++ Interface. Not Avoiding the Placed Box The tutorial runs flawlessly with no errors or

2021-05-20 15:28:06 -0500 commented answer Moveit2 Tutorial - Move Group C++ Interface. Not Avoiding the Placed Box

Brilliant thanks for the update. That has fixed the problem.

2021-05-20 15:27:45 -0500 received badge  Supporter (source)
2021-05-20 15:12:29 -0500 received badge  Student (source)
2021-05-20 15:10:57 -0500 received badge  Popular Question (source)
2021-05-19 23:46:34 -0500 asked a question Moveit2 Tutorial - Move Group C++ Interface. Not Avoiding the Placed Box

Moveit2 Tutorial - Move Group C++ Interface. Not Avoiding the Placed Box The tutorial runs flawlessly with no errors or

2021-05-11 17:32:23 -0500 commented question Publishing unbound array in ROS2 topic

Can you please post your CMakeLists.txt and package.xml as well