wiki:PacpusTutorialsNewComponent

Version 1 (modified by DHERBOMEZ Gérald, 8 years ago) ( diff )

--

Introduction

In this tutorial we will learn how to add a new component to an existing PACPUS project. Before starting, please make sure that your installation of PACPUS framework works fine, follow the guide here: GettingStarted

Goal

So we will add a component to the pacpussensors project that will generate a string and send it to an ouput.

Explanations

step 1: getting the source code of the project and compile it

Go to your development folder, typically it may ~/dev/pacpus and get the source code of the SVN repository and compile the project:

svn co https://devel.hds.utc.fr/svn/pacpussensors/trunk pacpussensors

We will keep only the PacpusSocket plugin for this example. Edit the CMakeLists.txt in the pacpussensors directory and comment all add_subdirectory(...) commands except of add_subdirectory(PacpusSocket). You will get something like this:

# ========================================
# Build the PacpusSensors' modules
# ========================================
#
# In the following list add the plugin you want to build. 
# Paths are relative to the root of the project. 
#

#add_subdirectory(Alasca)
#add_subdirectory(CanGateway)       #require kvaser libcan
#add_subdirectory(PtGreyCameras)
#add_subdirectory(Dualshock)
#add_subdirectory(NMEA0183)
#add_subdirectory(Gps)              #require NMEA0183
#add_subdirectory(SpanCPTComponent) #require NMEA0183
#add_subdirectory(Sick)
add_subdirectory(PacpusSocket)
#add_subdirectory(OpencvVideo)
#add_subdirectory(Wifibot)         #depends on PacpusSocket, change PacpusSocket to PacpusUdpSocket 
#add_subdirectory(Ladybug)         #require Ladybug spherical camera's driver, not compiled yet
#add_subdirectory(StdDbtPlayerComponents) 
#add_subdirectory(TelnetClient)
#add_subdirectory(VelodyneComponent)

To compile the project we will do it with QtCreator (please read the page to knwow how to configure correctly the project regarding pacpus needs). Open the software, then select the menu File->Open File or Project and choose the root CMakeLists.txt (in ~/dev/pacpus/pacpussensors/ if you have followed the guidelines).

In the Build menu, launch the building process, the results of a correct compilation is:

[100%] Built target PacpusSocket
Install the project...
-- Install configuration: ""
-- Installing: /opt/pacpus/0.2.3/bin/libPacpusSocket.so
-- Removed runtime path from "/opt/pacpus/0.2.3/bin/libPacpusSocket.so"
-- Installing: /opt/pacpus/0.2.3/include/PacpusSocket
-- Up-to-date: /opt/pacpus/0.2.3/include/PacpusSocket/PacpusUDPSocket.h
-- Installing: /opt/pacpus/0.2.3/include/PacpusSocket/PacpusSocketConfig.h
-- Installing: /opt/pacpus/0.2.3/include/PacpusSocket/PacpusSocketPlugin.h
-- Up-to-date: /opt/pacpus/0.2.3/include/PacpusSocket/PacpusSocketAirplug.h

The PacpusSocket.so plugin and headers files should be installed in your PACPUS_ROOT folder.

Step 2: writing the StringGenerator component

We will add the StringGenerator component to the pacpussensors project. Instead of adding a new plugin, we will include this component to the PacpusSocket plugin.

So go to the PacpusSocket folder and create 2 new files:

  • StringGenerator.h: the declaration of the component, the class may inherit from QObject (needed for the input/output mechanism) and ComponentBase (mandatory to be a pacpus component)
  • StringGenerator.cpp: the implementation of the component that must follow the component interface, ie:
    • a declaration of a ComponentFactory: static ComponentFactory <MyClassComponent> sFactory("MyComponentTypeForTheXml");
    • a specific constructor with a QString parameter: MyClassComponent::MyClassComponent(QString name) : ComponentBase(name)
    • the 5 pacpus methods:
      • void MyClassComponent::startActivity()
      • void MyClassComponent::stopActivity()
      • ComponentBase::COMPONENT_CONFIGURATION MyClassComponent::configureComponent(XmlComponentConfig config)
      • void MyClassComponent::addInputs()
      • void MyClassComponent::addOutputs()

Attachments (1)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.