Plug-in structure

From Rsewiki
Revision as of 12:01, 25 April 2010 by Jca (Talk | contribs)

Jump to: navigation, search

Contents

Introduction

A plug-in is a library module that be loaded by an AURS server and extend the functionality of the server. The plug-in can use the services provided by the server core.

The services provided by the server includes:

  • Service to direct commands from a client to the plugin (XML-formatted)
  • API to decode XML commands
  • Access to specific data sources - e.g. odometry pose, laser scans or camera images.
  • API for global variable creation and access - for parameter configuration and module status.
  • Access to data from other plug-ins
  • API to call functions in other plug-ins
  • API to allow other plug-ins to call this plug-in

Minimum plugin

A minimum plug-in can reply to a command and show a bit of online help.

Two codefiles and a Makefile is needed (see the minimum directory in the code)

Makefile
ufuncminimum.h
ufuncminimum.cpp

Class definition

The ufuncminimum.h defines the UFuncMinimum plug-in class as

class UFuncMinimum : public UFuncPlugBase
{
  public:
  UFuncMinimum()
  { // command list and version text
    setCommand("minimum", "minimum plugin example");
  }
  virtual bool handleCommand(UServerInMsg * msg, void * extra);
};

The class enherits all the needed core functionality from UFuncPlugBase. The plugin has a key-name called minimum as defined in the class constructor.

When the server gets a command with the keyword minimum it callse the function

bool handleCommand(UServerInMsg * msg, void * extra);

This function has two parameters, the command message itself in msg and an extra parameter used in some event-related commands, and may point to the data structure related to the event (push commands).

Method implementation

The ufuncminimum.cpp file defines the handleCommand(...) method. In this case it looks like this:

1  #include "ufuncminimum.h"
2  #ifdef LIBRARY_OPEN_NEEDED
3  UFunctionBase * createFunc()
4  { // create an object of this type
5    return new UFuncMinimum();
6  }
7  #endif
8
9  bool UFuncMinimum::handleCommand(UServerInMsg * msg, void * extra)
10 {
11  const int MRL = 500;
12  char reply[MRL];
13  bool ask4help;
14  double a = 100.0, b = 100.0;
15  //
16  ask4help = msg->tag.getAttValue("help", NULL, 0);
17  msg->tag.getAttDouble("a", &a, a);
18  msg->tag.getAttDouble("b", &b, b);
19  //
20  if (ask4help)
21  { // create the reply in XML-like (html - like) format
22    sendHelpStart("MINIMUM");
23    sendText("--- MINIMUM is a demonstration plugin that calculates the minimum of two numbers\n");
24    sendText("a=A        Value of A (default is 100)\n");
25    sendText("a=B        Value of B (default is 100)\n");
26    sendText("help       This message\n");
27    sendHelpDone();
28  }
29  else
30  { // calculate minimum value
31    snprintf(reply, MRL, "minimum(a=%g, b=%g) is %g", a, b, fmin(a,b));
32    sendInfo(reply);
33  }
34  return true;
35 }


Makefile

The Makefile gives the name of the plug-in and must know which files to compile.

@todo which lines

Global variables and inter-plug-in calls

See also Variables

Laser scanner access

@todo

Camera image access

@todo

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox