scanner_v2.h
Go to the documentation of this file.
1 // Copyright (c) 2020-2021 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 #ifndef PSEN_SCAN_V2_STANDALONE_SCANNER_V2_H
16 #define PSEN_SCAN_V2_STANDALONE_SCANNER_V2_H
17 
18 #include <memory>
19 #include <mutex>
20 #include <future>
21 #include <functional>
22 
23 #include <boost/optional.hpp>
24 
28 
30 
36 {
37 class ScannerConfiguration;
39 using std::placeholders::_1;
40 using std::placeholders::_2;
41 
60 class ScannerV2 : public IScanner
61 {
62 public:
63  ScannerV2(const ScannerConfiguration& scanner_config, const LaserScanCallback& laser_scan_callback);
64  ~ScannerV2() override;
65 
66 public:
68  std::future<void> start() override;
69 
71  std::future<void> stop() override;
72 
73 private:
74  template <class T>
75  void triggerEventWithParam(const T& event);
76 
77  template <class T>
78  void triggerEvent();
79 
80  void scannerStartedCallback();
81  void scannerStoppedCallback();
82  void scannerStartErrorCallback(const std::string& error_msg);
83  void scannerStopErrorCallback(const std::string& error_msg);
84 
85 private:
86  using OptionalPromise = boost::optional<std::promise<void>>;
87 
88 private:
89  OptionalPromise scanner_has_started_{ boost::none };
90  OptionalPromise scanner_has_stopped_{ boost::none };
91 
97  std::mutex member_mutex_;
98 
99  std::unique_ptr<ScannerStateMachine> sm_;
100 };
101 
102 template <class T>
104 {
105  const std::lock_guard<std::mutex> lock(member_mutex_);
106  sm_->process_event(event);
107 }
108 
109 template <class T>
111 {
112  triggerEventWithParam<T>(T());
113 }
114 
115 } // namespace psen_scan_v2_standalone
116 
117 #endif // PSEN_SCAN_V2_STANDALONE_SCANNER_V2_H
psen_scan_v2_standalone::ScannerV2::OptionalPromise
boost::optional< std::promise< void > > OptionalPromise
Definition: scanner_v2.h:86
psen_scan_v2_standalone::protocol_layer
Namespace for the implementation of the scanner protocol state machine.
Definition: function_pointers.h:26
watchdog.h
psen_scan_v2_standalone::ScannerV2::triggerEventWithParam
void triggerEventWithParam(const T &event)
Definition: scanner_v2.h:103
scanner_events.h
scanner_interface.h
psen_scan_v2_standalone::ScannerV2::sm_
std::unique_ptr< ScannerStateMachine > sm_
Definition: scanner_v2.h:99
psen_scan_v2_standalone::ScannerV2::member_mutex_
std::mutex member_mutex_
This Mutex protects ALL members of the Scanner against concurrent access. So far there exist at least...
Definition: scanner_v2.h:97
psen_scan_v2_standalone::ScannerV2::triggerEvent
void triggerEvent()
Definition: scanner_v2.h:110
psen_scan_v2_standalone::ScannerV2
This is the implementation of the Scanner API defined by IScanner.
Definition: scanner_v2.h:60
start
ROSCPP_DECL void start()
psen_scan_v2_standalone
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
psen_scan_v2_standalone::IScanner::LaserScanCallback
std::function< void(const LaserScan &)> LaserScanCallback
Represents the user-provided callback for processing incoming scan data.
Definition: scanner_interface.h:44
scanner_state_machine.h
psen_scan_v2_standalone::IScanner
This is the API definition for external interaction with the scanner driver.
Definition: scanner_interface.h:40
psen_scan_v2_standalone::ScannerConfiguration
Higher level data type storing the configuration details of the scanner like scanner IP,...
Definition: scanner_configuration.h:34


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Jun 22 2024 02:46:12