Skip to content

Commit 87ed2f0

Browse files
authored
Merge pull request #4 from Terabee/feature/evo_15m_40m
Added Evo 15m and 40m
2 parents 9dddf8e + 26897ad commit 87ed2f0

16 files changed

+504
-6
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ add_library(${LIB_NAME}
3131
src/teraranger/TerarangerBasicCommon.cpp
3232
src/teraranger/TerarangerEvo3m.cpp
3333
src/teraranger/TerarangerEvo600Hz.cpp
34+
src/teraranger/TerarangerEvo15m.cpp
35+
src/teraranger/TerarangerEvo40m.cpp
3436
src/teraranger/TerarangerEvo60m.cpp
3537
src/teraranger/TerarangerEvo64px.cpp
3638
src/teraranger/TerarangerEvoMini.cpp

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Terabee
3+
Copyright (c) 2021 Terabee
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

examples/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ target_link_libraries(ExampleReadEvo3m ${LIB_NAME})
1010
add_executable(ExampleReadEvo600Hz ExampleReadEvo600Hz.cpp)
1111
target_link_libraries(ExampleReadEvo600Hz ${LIB_NAME})
1212

13+
add_executable(ExampleReadEvo15m ExampleReadEvo15m.cpp)
14+
target_link_libraries(ExampleReadEvo15m ${LIB_NAME})
15+
16+
add_executable(ExampleReadEvo40m ExampleReadEvo40m.cpp)
17+
target_link_libraries(ExampleReadEvo40m ${LIB_NAME})
18+
1319
add_executable(ExampleReadEvo60m ExampleReadEvo60m.cpp)
1420
target_link_libraries(ExampleReadEvo60m ${LIB_NAME})
1521

examples/ExampleReadEvo15m.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @Author Marcin Pilch
3+
*
4+
* @Copyright Terabee 2021
5+
*
6+
*/
7+
8+
#include <chrono>
9+
#include <csignal>
10+
#include <iostream>
11+
#include <thread>
12+
13+
#include <terabee/ITerarangerFactory.hpp>
14+
#include <terabee/ITerarangerEvo15m.hpp>
15+
16+
volatile std::sig_atomic_t g_signal_status;
17+
void signal_handler(int signal) {
18+
g_signal_status = signal;
19+
}
20+
21+
int main(int argc, char** argv)
22+
{
23+
if (argc != 2)
24+
{
25+
std::cout << "usage: ./ExampleReadEvo15 DEVICE_NAME" << std::endl;
26+
return -1;
27+
}
28+
std::signal(SIGTSTP, signal_handler);
29+
auto factory = terabee::ITerarangerFactory::getFactory();
30+
auto evo15 = factory->createTerarangerEvo15m(argv[1]);
31+
if (!evo15)
32+
{
33+
std::cout << "Failed to create device" << std::endl;
34+
}
35+
if (!evo15->initialize())
36+
{
37+
std::cout << "Failed to initialize device" << std::endl;
38+
return -1;
39+
}
40+
std::cout << "Press C-z to quit" << std::endl;
41+
while (g_signal_status != SIGTSTP)
42+
{
43+
std::cout << "Distance = " << evo15->getDistance().distance.front() << std::endl;
44+
std::this_thread::sleep_for(std::chrono::seconds(1));
45+
}
46+
return evo15->shutDown() ? 0 : -1;
47+
}

examples/ExampleReadEvo40m.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @Author Marcin Pilch
3+
*
4+
* @Copyright Terabee 2021
5+
*
6+
*/
7+
8+
#include <chrono>
9+
#include <csignal>
10+
#include <iostream>
11+
#include <thread>
12+
13+
#include <terabee/ITerarangerFactory.hpp>
14+
#include <terabee/ITerarangerEvo40m.hpp>
15+
16+
volatile std::sig_atomic_t g_signal_status;
17+
void signal_handler(int signal) {
18+
g_signal_status = signal;
19+
}
20+
21+
int main(int argc, char** argv)
22+
{
23+
if (argc != 2)
24+
{
25+
std::cout << "usage: ./ExampleReadEvo40 DEVICE_NAME" << std::endl;
26+
return -1;
27+
}
28+
std::signal(SIGTSTP, signal_handler);
29+
auto factory = terabee::ITerarangerFactory::getFactory();
30+
auto evo40 = factory->createTerarangerEvo40m(argv[1]);
31+
if (!evo40)
32+
{
33+
std::cout << "Failed to create device" << std::endl;
34+
}
35+
if (!evo40->initialize())
36+
{
37+
std::cout << "Failed to initialize device" << std::endl;
38+
return -1;
39+
}
40+
std::cout << "Press C-z to quit" << std::endl;
41+
while (g_signal_status != SIGTSTP)
42+
{
43+
std::cout << "Distance = " << evo40->getDistance().distance.front() << std::endl;
44+
std::this_thread::sleep_for(std::chrono::seconds(1));
45+
}
46+
return evo40->shutDown() ? 0 : -1;
47+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef I_TERARANGER_EVO_15M_HPP
2+
#define I_TERARANGER_EVO_15M_HPP
3+
4+
/**
5+
* @Author Marcin Pilch
6+
*
7+
* @Copyright Terabee 2021
8+
*
9+
*/
10+
11+
/**
12+
* \example ExampleReadEvo15m.cpp
13+
*/
14+
15+
#include "terabee/DistanceData.hpp"
16+
17+
namespace terabee
18+
{
19+
20+
/**
21+
* Interface to <a href="https://www.terabee.com/shop/lidar-tof-range-finders/teraranger-evo-15m/">TeraRanger Evo 15m</a> sensor.
22+
* \see
23+
* - \ref ITerarangerFactory::createTerarangerEvo15m
24+
* - \ref ExampleReadEvo15m.cpp
25+
*/
26+
class ITerarangerEvo15m
27+
{
28+
public:
29+
virtual ~ITerarangerEvo15m() = default;
30+
/**
31+
* Performs initialization of the device.
32+
* \return
33+
* - true on success
34+
* - false on failure, e.g. device disconnected, communication failure,
35+
* device already initialized
36+
*/
37+
virtual bool initialize() = 0;
38+
/**
39+
* Disconnects the device
40+
* \return
41+
* - true on success
42+
* - false on failure, e.g. device busy
43+
*/
44+
virtual bool shutDown() = 0;
45+
/**
46+
* Method for obtaining sensor measurement in a synchronous way.
47+
* \return
48+
* - returns measured distance in [m]
49+
* - If fails to communicate with sensor (e.g. device not initialized) returns `std::nan("")`
50+
* - If measurement cannot be done (e.g. sensor malfunction) returns -1
51+
* - If object is too close returns `-std::numeric_limits<float>::infinity()`
52+
* - If measured value is out of range returns `std::numeric_limits<float>::infinity()`
53+
*/
54+
virtual DistanceData getDistance() = 0;
55+
/**
56+
* Method for obtaining sensor measurement in an asynchronous way.
57+
* Registers a callback to be invoked every time new data from the sensor is received;
58+
* \param cb
59+
* - The callback function must return `void` and accept one argument: const reference to DistanceData
60+
* - Callback registration must be done before sensor initialization
61+
* - Callbacks are invoked after sensor initialization when new data is constantly received
62+
* - Callback can be set to `nullptr`; In this case no callback will be invoked when new data is received
63+
* - Callback function should be short, heavy computations should be avoided, because it blocks asynchronous data capture routine;
64+
*
65+
* \return
66+
* - true on success
67+
* - false on failure (e.g. sensor already initialized)
68+
*/
69+
virtual bool registerOnDistanceDataCaptureCallback(OnDistanceDataCaptureCallback cb) = 0;
70+
};
71+
72+
} // namespace terabee
73+
74+
#endif // I_TERARANGER_EVO_15M_HPP
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef I_TERARANGER_EVO_40M_HPP
2+
#define I_TERARANGER_EVO_40M_HPP
3+
4+
/**
5+
* @Author Marcin Pilch
6+
*
7+
* @Copyright Terabee 2021
8+
*
9+
*/
10+
11+
/**
12+
* \example ExampleReadEvo40m.cpp
13+
*/
14+
15+
#include "terabee/DistanceData.hpp"
16+
17+
namespace terabee
18+
{
19+
20+
/**
21+
* Interface to <a href="https://www.terabee.com/shop/lidar-tof-range-finders/teraranger-evo-40m/">TeraRanger Evo 40m</a> sensor.
22+
* \see
23+
* - \ref ITerarangerFactory::createTerarangerEvo40m
24+
* - \ref ExampleReadEvo40m.cpp
25+
*/
26+
class ITerarangerEvo40m
27+
{
28+
public:
29+
virtual ~ITerarangerEvo40m() = default;
30+
/**
31+
* Performs initialization of the device.
32+
* \return
33+
* - true on success
34+
* - false on failure, e.g. device disconnected, communication failure,
35+
* device already initialized
36+
*/
37+
virtual bool initialize() = 0;
38+
/**
39+
* Disconnects the device
40+
* \return
41+
* - true on success
42+
* - false on failure, e.g. device busy
43+
*/
44+
virtual bool shutDown() = 0;
45+
/**
46+
* Method for obtaining sensor measurement in a synchronous way.
47+
* \return
48+
* - returns measured distance in [m]
49+
* - If fails to communicate with sensor (e.g. device not initialized) returns `std::nan("")`
50+
* - If measurement cannot be done (e.g. sensor malfunction) returns -1
51+
* - If object is too close returns `-std::numeric_limits<float>::infinity()`
52+
* - If measured value is out of range returns `std::numeric_limits<float>::infinity()`
53+
*/
54+
virtual DistanceData getDistance() = 0;
55+
/**
56+
* Method for obtaining sensor measurement in an asynchronous way.
57+
* Registers a callback to be invoked every time new data from the sensor is received;
58+
* \param cb
59+
* - The callback function must return `void` and accept one argument: const reference to DistanceData
60+
* - Callback registration must be done before sensor initialization
61+
* - Callbacks are invoked after sensor initialization when new data is constantly received
62+
* - Callback can be set to `nullptr`; In this case no callback will be invoked when new data is received
63+
* - Callback function should be short, heavy computations should be avoided, because it blocks asynchronous data capture routine;
64+
*
65+
* \return
66+
* - true on success
67+
* - false on failure (e.g. sensor already initialized)
68+
*/
69+
virtual bool registerOnDistanceDataCaptureCallback(OnDistanceDataCaptureCallback cb) = 0;
70+
};
71+
72+
} // namespace terabee
73+
74+
#endif // I_TERARANGER_EVO_40M_HPP

include/terabee/ITerarangerFactory.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* - One of the interfaces documentation to learn how to use a particular sensor:
1616
* - terabee::ITerarangerEvo3m
1717
* - terabee::ITerarangerEvo600Hz
18+
* - terabee::ITerarangerEvo15m
19+
* - terabee::ITerarangerEvo40m
1820
* - terabee::ITerarangerEvo60m
1921
* - terabee::ITerarangerEvo64px
2022
* - terabee::ITerarangerEvoMini
@@ -36,6 +38,8 @@
3638

3739
#include "terabee/ITerarangerEvo3m.hpp"
3840
#include "terabee/ITerarangerEvo600Hz.hpp"
41+
#include "terabee/ITerarangerEvo15m.hpp"
42+
#include "terabee/ITerarangerEvo40m.hpp"
3943
#include "terabee/ITerarangerEvo60m.hpp"
4044
#include "terabee/ITerarangerEvo64px.hpp"
4145
#include "terabee/ITerarangerEvoMini.hpp"
@@ -71,6 +75,22 @@ class ITerarangerFactory
7175
*/
7276
virtual std::unique_ptr<ITerarangerEvo600Hz> createTerarangerEvo600Hz(
7377
const std::string& serial_port) = 0;
78+
/**
79+
* \param serial_port name of the serial port device, e.g. `/dev/ttyACM0`
80+
* \return pointer to Evo15m device connected to the host USB;
81+
* If serial port cannot be opened, or if it is impossible to communicate
82+
* with device, returns nullptr.
83+
*/
84+
virtual std::unique_ptr<ITerarangerEvo15m> createTerarangerEvo15m(
85+
const std::string& serial_port) = 0;
86+
/**
87+
* \param serial_port name of the serial port device, e.g. `/dev/ttyACM0`
88+
* \return pointer to Evo40m device connected to the host USB;
89+
* If serial port cannot be opened, or if it is impossible to communicate
90+
* with device, returns nullptr.
91+
*/
92+
virtual std::unique_ptr<ITerarangerEvo40m> createTerarangerEvo40m(
93+
const std::string& serial_port) = 0;
7494
/**
7595
* \param serial_port name of the serial port device, e.g. `/dev/ttyACM0`
7696
* \return pointer to Evo60m device connected to the host USB;

include/terabee/internal/factories/TerarangerFactory.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/**
55
* @Author Pawel Ptasznik
66
*
7-
* @Copyright Terabee 2020
7+
* @Copyright Terabee 2021
88
*
99
*/
1010

@@ -13,6 +13,8 @@
1313

1414
#include "terabee/ITerarangerEvo3m.hpp"
1515
#include "terabee/ITerarangerEvo600Hz.hpp"
16+
#include "terabee/ITerarangerEvo15m.hpp"
17+
#include "terabee/ITerarangerEvo40m.hpp"
1618
#include "terabee/ITerarangerEvo60m.hpp"
1719
#include "terabee/ITerarangerEvo64px.hpp"
1820
#include "terabee/ITerarangerEvoMini.hpp"
@@ -36,6 +38,10 @@ class TerarangerFactory: public ITerarangerFactory
3638
const std::string& serial_port) override;
3739
std::unique_ptr<ITerarangerEvo600Hz> createTerarangerEvo600Hz(
3840
const std::string& serial_port) override;
41+
std::unique_ptr<ITerarangerEvo15m> createTerarangerEvo15m(
42+
const std::string& serial_port) override;
43+
std::unique_ptr<ITerarangerEvo40m> createTerarangerEvo40m(
44+
const std::string& serial_port) override;
3945
std::unique_ptr<ITerarangerEvo60m> createTerarangerEvo60m(
4046
const std::string& serial_port) override;
4147
std::unique_ptr<ITerarangerEvo64px> createTerarangerEvo64px(

include/terabee/internal/teraranger/TerarangerBasicCommon.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
/**
55
* @Author Pawel Ptasznik
66
*
7-
* @Copyright Terabee 2020
7+
* @Copyright Terabee 2021
88
*
9-
* Common implementaion for TerarangerEvo3m and TerarangerEvo60m
10-
* (and maybe some more in the future)
9+
* Common implementaion for
10+
* - TerarangerEvo3m
11+
* - TerarangerEvo15m
12+
* - TerarangerEvo40m
13+
* - TerarangerEvo60m
14+
* - TerarangerEvo600Hz
1115
*/
1216

1317
#include <array>

0 commit comments

Comments
 (0)