PlatoonProtocol
Building
1. Clone the repository.
$ cd ~
$ git clone https://gitlab.informatik.hu-berlin.de/adapt/ws17-HF/Gruppe-A
2. Install the libraries to your computer.
NetworkingLib:
$ cd Gruppe-A/NetworkingLib
$ mkdir build
$ cd build
$ cmake ..
$ sudo make install
PlatoonProtocolLib:
$ cd ~/Gruppe-A/PlatoonProtocol
$ mkdir build
$ cd build
$ cmake ..
$ sudo make install
Important Note:
Before you build the PlatoonProtocolLib you can customize some settings that you find in "PlatoonProtocol/include/Definitions.h". For example: If you want to test or simulate multiple vehicles on a single machine, PLATOON_PROTOCOL_ENABLE_LOCAL_TESTING must be defined. Otherwise the vehicle instances use the same port which is not possible on regular operating systems.
3. Configure your CMakeList.txt file
Just add these lines to your CMakeList.txt file to include the libraries to your project. "MyTarget" is the target which will be using the protocol.
find_package(NetworkingLib REQUIRED)
find_package(PlatoonProtocolLib REQUIRED)
target_link_libraries(MyTarget NetworkingLib PlatoonProtocolLib)
How to use
An example scenario.
Here we suppose to run a platoon as leader:
#include <NetworkingLib/Networking.h>
#include <PlatoonProtocolLib/Protocol.h>
#include <PlatoonProtocolLib/LeaderVehicle.h>
// Create a networking thread.
// All logic is executed asynchronously on this single thread.
// You must ensure that 'net' is kept alive during the lifetime of any protocol object.
networking::Networking net;
// Create a leader.
auto leader = platoonProtocol::LeaderVehicle::create(net, 1); // 1 = vehicleId
// Add endpoints which we may request a platoon to create with.
leader->addVehicleEndpoint(2, "192.168.100.30");
leader->addVehicleEndpoint(3, "192.168.134.5");
// Set the initial platoon configuration.
// This can be set at anytime and will be send to the following vehicles.
leader->setPlatoonConfig(platoonProtocol::PlatoonConfig{10.0f, 20.0f});
// Start the platoon.
leader->createPlatoon();
// Do something different...
// ...
// Decide to leave the platoon.
leader->leavePlatoon();
And on another machine, we're running a follower:
#include <NetworkingLib/Networking.h>
#include <PlatoonProtocolLib/Protocol.h>
#include <PlatoonProtocolLib/FollowerVehicle.h>
// Create a networking thread.
// All logic is executed asynchronously on this single thread.
// You must ensure that 'net' is kept alive during the lifetime of any protocol object.
networking::Networking net;
// Create a leader.
auto follower = platoonProtocol::FollowerVehicle::create(net, 2); // 2 = vehicleId
// Add endpoints which we may request a platoon to create with.
follower->addVehicleEndpoint(1, "192.168.40.27");
follower->addVehicleEndpoint(3, "192.168.134.5");
// Register a callback to receive platoon configuration updates (ps and ipd).
follower->setOnUpdatePlatoonConfigCallback(
[](const platoonProtocol::PlatoonConfig & config){/* Received updated platoonConfig. */});
// Start the platoon.
follower->createPlatoon();
// Do something different...
// ...
// Decide to leave the platoon.
follower->leavePlatoon();