Skip to content

Console Plugin System

multiagent-mapping-sheep edited this page Nov 27, 2017 · 2 revisions

Installation

To get maplab into a state with all core plugins (VIMap file system integration, BA, LC, etc.), run

catkin build maplab

The package maplab is a metapackage containing the maplab console and all non-experimental plugins to ease the installation of a functioning console. You can type help in the console to get a list of all installed plugins.

If a plugin doesn't show up in a console, you may need to recompile it with rerunning cmake (as this will create the entry in the plugin file list):

catkin build --no-deps --force-cmake <missing_plugin_name>

How it works

Each plugin adds an entry with the path to the library *.so to $CATKIN_WS/devel/share/console-plugins.txt ("plugin list") during compilation. This list is then opened by the maplab console application. The application tries to dynamically load the library referred in the console-plugins.txt file.

Uninstalling a plugin

Delete the library .so: Delete the file under $CATKIN_WS/devel/lib/lib<PACKAGE_NAME>.so. Maplab will still try to load the library, but detect that the file is missing and delete the entry from the list.

Note: to readd the plugin to the console, it's not sufficient to only recompile the package. You also need to make sure that cmake is rerun by running catkin with the --force-cmake argument.

Adding a new plugin

  • Derive your plugin class from common::ConsolePluginBaseWithPlotter or common::ConsolePluginBase. bar-plugin.h:

    #ifndef FOO_BAR_PLUGIN_H_
    #define FOO_BAR_PLUGIN_H_
    
    #include <string>
    
    #include <console-common/console-plugin-base-with-plotter.h>
    #include <console-common/console.h>
    
    namespace foo {
    
    class BarPlugin : public common::ConsolePluginBaseWithPlotter {
     public:
      BarPlugin(common::Console* console,
                visualization::ViwlsGraphRvizPlotter* plotter);
    
      virtual std::string getPluginId() const override {
        return "foo_bar_plugin";
      }
    };
    
    }  // namespace foo
    
    #endif  // FOO_BAR_PLUGIN_H_
  • Implement your own console commands. bar-plugin.cc:

    #include "foo/bar-plugin.h"
    
    #include <console-common/console.h>
    #include <gflags/gflags.h>
    #include <map-manager/map-manager.h>
    #include <vi-map/vi-map.h>
    #include <visualization/viwls-graph-plotter.h>
    
    namespace foo {
    
    BarPlugin::BarPlugin(common::Console* console, visualization::ViwlsGraphRvizPlotter* plotter)
        : common::ConsolePluginBaseWithPlotter(console, plotter) {
      addCommand(
       {"foo_bar"},
       [this]() -> int {
         // Get write access to map.
         vi_map::VIMapManager map_manager;
         vi_map::VIMapManager::MapWriteAccess vi_map =
             map_manager.getMapWriteAccess(selected_map_key);
    
         // Run awesome algorithm.
         run_algorithm(vi_map.get())
    
         return common::kSuccess;
         // or   return common::kStupidUserError (soft fail - won't kill the console)
         // or   return common::kUnknownError    (hard fail - will kill the console)
       },
       "This command will run an awesome algorithm.",
       common::Processing::Sync);
    }
    
    }  // namespace foo
    
    MAPLAB_CREATE_CONSOLE_PLUGIN_WITH_PLOTTER(foo::BarPlugin);
  • Add the following macro to your CMakeLists.txt

    cmake_minimum_required(VERSION 2.8.3)
    project(foo_bar_plugin)
    
    find_package(catkin_simple REQUIRED)
    
    catkin_simple(ALL_DEPS_REQUIRED)
    
    add_definitions(-fPIC -shared)
    
    #############
    # LIBRARIES #
    #############
    cs_add_library(${PROJECT_NAME} src/bar-plugin.cc)
    create_console_plugin(${PROJECT_NAME})
    
    ##########
    # EXPORT #
    ##########
    cs_install()
    cs_export()
Clone this wiki locally