PolySync is a middlware component that abstracts the interface between your sensor hardware and the work that you want to do to transmit information around the vehicle. In this tutorial we will demonstrate the basics of connecting to the PolySync bus to allow you to read and write information.
What you will need
- The example source code.
- A computer capable of running PolySync (see the PolySync Installation Guide)
- The system should be compliant with the System Requirements
- It should be running Ubuntu Linux version 14.04.3
- It should have compliant hardware with at least 4GB of ram
- It should have all of the run-time dependencies available; these are included in the installation process
- The system should have PolySync installed
- The system should have a license
- Development tools capable of compiling the tutorial (e.g. sudo apt-get install build-essential)
Compiling the Source Code
The default installation directory for PolySync is /usr/local/polysync. For purposes of this tutorial, the default directory will be used as a reference. Relative paths will be used and should be considered to originate from the default directory.
The tutorial source code is located in the examples/cpp/ directory and also on the public GitHub.
Use the following command sequence to compile the code:
$ git clone https://github.com/PolySync/PolySync-CPP-Examples
$ cd CPP-Examples/HelloWorld $ mkdir build $ cd build $ cmake .. $ make
What is Happening in this code
This simple example contains one node that establishes the system resources that it requires and creates a virtual “bus.” This bus allows the node to both listen for and send messages. As we add nodes, this bus serves as the medium where all of the nodes communicate. Since there is only a single node (no other nodes to communicate with), this node uses a node-level system event to indicate a change in the state of the node.
PolySync Node <-- InitState Event
This example code demonstrates the use of the Node class which defines the interface for how to interact with the overall PolySync system. The Node base class defines the mechanism via virtual functions in the base class. The work required by the developer is to overload those functions, but only the ones that they require.
The functions that can be overloaded are:
- void messageEvent(std::shared_ptr< Message > )
- void okStateEvent()
- void fatalStateEvent()
- void errorStateEvent()
- void warnStateEvent()
- void releaseStateEvent()
- void initStateEvent()
- void setConfigurationEvent( int argc, char ** argv )
In this instance we are specifically only overloading the initStateEvent function to indicate that the Node has initialized correctly. The other functions will be detailed in further tutorials.
When you execute the code, the connectToPolySync function does not return but you should see a “Hello world!” print statement when the node initializes.
To end the program, perform a Ctrl-C.