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
We make the assumption that we works in a Linux environment.
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 fromQObject
(needed for the input/output mechanism) andComponentBase
(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()
- a declaration of a
Add these 2 files to the CMakeLists.txt
of the PacpusSocket
plugin:
- put the cpp file to
PROJECT_SRCS
variable - put the header file to
PROJECT_HDRS
andFILES_TO_MOC
variables
Then compile the project again in QtCreator, you may get the same PacpusSocket.so
plugin but at the difference it contains a new component.
You can find the template files for this component in this archive: raw-attachment:StringGeneratorTemplate.tar.gz
Step 3: coding the string generation algorithm
To generate the string at a fixed rate we will use a QTimer
object.
Step 4: testing
Attachments (1)
-
StringGeneratorTemplate.tar.gz
(1.1 KB
) - added by 8 years ago.
Template for the string generator tuto component
Download all attachments as: .zip