Skip to content

Commit

Permalink
Transfer commit at v1.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Pilch committed Mar 31, 2021
0 parents commit 1ec3d56
Show file tree
Hide file tree
Showing 33 changed files with 4,646 additions and 0 deletions.
45 changes: 45 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.10.2)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(PACKAGE_VERSION 1.5.5)
project(positioning_systems_api VERSION ${PACKAGE_VERSION})

if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -O0 -g3 -pthread -fPIC")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -O2 -g0 -pthread -fPIC")
endif()

option(BUILD_TESTS "Builds tests" ON)
option(BUILD_EXAMPLES "Build short example binaries" ON)

include(GNUInstallDirs)
set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/cmake/positioning_systems_apiConfig.cmake.in")
set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/positioning_systems_apiConfig.cmake")
set(config_targets_file_serial_communication "serial_communication.cmake")
set(config_targets_file_follow_me_driver "follow_me_driver.cmake")
set(config_targets_file_rtls_driver "rtls_driver.cmake")
set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/positioning_systems_apiConfigVersion.cmake")
set(export_dest_dir "lib/cmake/positioning_systems_api")

add_subdirectory(serial_communication)
add_subdirectory(follow_me_driver)
add_subdirectory(rtls_driver)
add_subdirectory(logger)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

include(CMakePackageConfigHelpers)
configure_file("${project_config_in}" "${project_config_out}" @ONLY)
write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)

install(FILES
"${project_config_out}"
"${version_config_file}" DESTINATION "${export_dest_dir}"
)
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Terabee

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
139 changes: 139 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# positioning_systems_api

This package comprises following modules described below: **serial_communication**, **follow_me_driver**, **rtls_driver**, **logger**.

## serial_communication

General purpose serial communication

### Features

- support for different baudrate, parity, bytesize (5, 6, 7, or 8 bits), stopbits and flow control
- implementation for Linux and Windows

### Usage

In order to use serial_communication in your code, include the interface header and appropriate implementation header, e.g.

```
#include "serial_communication/iserial.hpp"
#include "serial_communication/serial.hpp"
```

Add `positioning_systems_api` to `find_package` of your `CMakeLists.txt` and link the target against `serial_communication`:

```
target_link_libraries(target_name
positioning_systems_api::serial_communication
)
```

See subdirectory `examples` for a C++ source file presenting usage of `serial_communication`.

## follow_me_driver

Driver dedicated for communication with Terabee Follow-Me system

### Features

- set configuration parameters: span manual setting and auto-calibration, output mode (text/binary), swap beacons, Exponential Moving Average filter window size,
- configuration of RS485 connection parameters (slave address, baud rate, parity)
- set configuration parameters of the remote control: enable/disable buzzer, change button mode (toggle/hold)
- data reception (distance and heading)

### Usage

Include the following header:
```
#include "follow_me_driver/follow_me_driver.hpp"
```

and header with appropriate implementation of serial port, e.g.
```
#include "serial_communication/serial.hpp"
```

Add `positioning_systems_api` to `find_package` of your `CMakeLists.txt` and link the target against `follow_me_driver`:

```
target_link_libraries(target_name
positioning_systems_api::follow_me_driver
)
```

See subdirectory `examples` for a C++ source file presenting usage of `follow_me_driver`.

## rtls_driver

Driver dedicated for communication with Terabee Robot Positioning System

### Features

- setting all configuration parameters
- reading the whole configuration of device
- reading position output of the tracker

### Usage

Include the following header:
```
#include "rtls_driver/rtls_driver.hpp"
```

and header with appropriate implementation of serial port, e.g.
```
#include "serial_communication/serial.hpp"
```

Add `positioning_systems_api` to `find_package` of your `CMakeLists.txt` and link the target against `rtls_driver`:

```
target_link_libraries(target_name
positioning_systems_api::rtls_driver
)
```

See subdirectory `examples` for a C++ source file presenting usage of `rtls_driver`.

## Compilation

```
mkdir build
cd build
cmake ../
make
```

**Note:**

If using MinGW in Windows, type

`cmake .. -G "MinGW Makefiles"` instead of `cmake ../`

to prevent configuring for MSVC.

Use `cmake.exe --build . --target all -- -j` to build.

## Installation in the system
```
sudo make install
```

## Run tests

```
cd build
make test
```
For tests to pass, linux null modem emulator is required https://github.com/freemed/tty0tty

## Logging
To use the logger, set the following environment variables:
```
export LOGGER_ENABLE_LOGGING=1
export LOGGER_PRINT_STDOUT=1
```

Set `export LOGGER_ENABLE_DEBUG=1` to enable debug logs.

Set `export LOGGER_FILENAME=rtls_output.log` to change the default log file name.
4 changes: 4 additions & 0 deletions cmake/positioning_systems_apiConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(config_targets_file_serial_communication @config_targets_file_serial_communication@)
include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file_serial_communication}")
set(config_targets_file_follow_me_driver @config_targets_file_follow_me_driver@)
include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file_follow_me_driver}")
45 changes: 45 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
project(positioning_systems_api_examples)

add_executable(serial_example
serial_example.cpp
)

target_link_libraries(serial_example
serial_communication
)

add_executable(follow_me_master_example
follow_me_master_example.cpp
)

target_link_libraries(follow_me_master_example
follow_me_driver
serial_communication
)

add_executable(follow_me_remote_example
follow_me_remote_example.cpp
)

target_link_libraries(follow_me_remote_example
follow_me_driver
serial_communication
)

add_executable(rtls_anchor_example
rtls_anchor_example.cpp
)

target_link_libraries(rtls_anchor_example
rtls_driver
serial_communication
)

add_executable(rtls_tracker_example
rtls_tracker_example.cpp
)

target_link_libraries(rtls_tracker_example
rtls_driver
serial_communication
)
64 changes: 64 additions & 0 deletions examples/follow_me_master_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <memory>
#include <iostream>
#include <csignal>
#include <thread>
#include "follow_me_driver/follow_me_driver.hpp"

#ifdef __linux__
#define STOP_SIGNAL SIGTSTP
#include "serial_communication/serial.hpp"
using SerialInterface = terabee::serial_communication::Serial;
#elif defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
#define STOP_SIGNAL SIGTERM
#include "serial_communication/serial_windows.hpp"
using SerialInterface = terabee::serial_communication::SerialWindows;
#endif

static volatile std::sig_atomic_t g_signal_status;
void signal_handler(int signal) {
g_signal_status = signal;
}

int main(int argc, char **argv)
{
terabee::utility::logger::Logger logger("FollowMeMasterExample");
if (argc != 2)
{
logger->info("usage: ./follow_me_master_example PORT_NAME");
return -1;
}
std::signal(STOP_SIGNAL, signal_handler);

std::string portname = argv[1];
std::shared_ptr<terabee::serial_communication::ISerial> serial_port =
std::make_shared<SerialInterface>(portname);

serial_port->setBaudrate(115200);
serial_port->setTimeout(std::chrono::milliseconds(200));

serial_port->open();

if (!serial_port->isOpen())
{
logger->error("Failed to open serial port!");
return 0;
}

terabee::FollowMeMasterBeacon master_beacon(serial_port);
terabee::PolarPoint2D point = { 0.0, 0.0 };

master_beacon.swapBeacons(false);
master_beacon.setEMAWindow(10);
master_beacon.setBeaconsSpan(1000);
logger->info(master_beacon.retrieveDeviceData());

master_beacon.printoutModeBin();
logger->info("Press Ctrl + Z to quit");
while (g_signal_status != STOP_SIGNAL)
{
master_beacon.process(point);
logger->info("Distance: {}\tHeading: {}", point.distance, point.heading);
}

return serial_port->close() ? 0 : -1;
}
59 changes: 59 additions & 0 deletions examples/follow_me_remote_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <memory>
#include <iostream>
#include <csignal>
#include <thread>
#include "follow_me_driver/follow_me_driver.hpp"

#ifdef __linux__
#define STOP_SIGNAL SIGTSTP
#include "serial_communication/serial.hpp"
using SerialInterface = terabee::serial_communication::Serial;
#elif defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
#define STOP_SIGNAL SIGTERM
#include "serial_communication/serial_windows.hpp"
using SerialInterface = terabee::serial_communication::SerialWindows;
#endif

static volatile std::sig_atomic_t g_signal_status;
void signal_handler(int signal) {
g_signal_status = signal;
}

int main(int argc, char **argv)
{
terabee::utility::logger::Logger logger("FollowMeRemoteExample");
if (argc != 2)
{
logger->info("usage: ./follow_me_remote_example PORT_NAME");
return -1;
}
std::signal(STOP_SIGNAL, signal_handler);

std::string portname = argv[1];
std::shared_ptr<terabee::serial_communication::ISerial> serial_port =
std::make_shared<SerialInterface>(portname);

serial_port->setBaudrate(115200);
serial_port->setTimeout(std::chrono::milliseconds(700));

serial_port->open();

if (!serial_port->isOpen())
{
logger->error("Failed to open serial port!");
return 0;
}

terabee::FollowMeRemoteControl remote_control(serial_port);

remote_control.setBuzzer(false);
remote_control.setButtonMode(terabee::FollowMeRemoteControl::button_mode::hold);

terabee::FollowMeRemoteControl::button_mode button_mode;
bool buzzer;
remote_control.retrieveRemoteParameters(button_mode, buzzer);
logger->info("Button mode: {}", static_cast<int>(button_mode));
logger->info("Buzzer: {}", buzzer);

return serial_port->close() ? 0 : -1;
}
Loading

0 comments on commit 1ec3d56

Please sign in to comment.