Mech-Eye API 2.3.4
API reference documentation for Mech-Eye 3D Laser Profiler
All Classes Functions Variables Typedefs Enumerations Enumerator Pages
api_util.h
1/*******************************************************************************
2 *BSD 3-Clause License
3 *
4 *Copyright (c) 2016-2024, Mech-Mind Robotics
5 *All rights reserved.
6 *
7 *Redistribution and use in source and binary forms, with or without
8 *modification, are permitted provided that the following conditions are met:
9 *
10 *1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 *2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 *3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 *AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 *DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 *SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 *CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 *OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 *OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ******************************************************************************/
32
33#pragma once
34#include <iostream>
35#include <set>
36#include <utility>
37#include <regex>
38#include <iomanip>
39#include "ErrorStatus.h"
40#include "CommonTypes.h"
41#include "Profiler.h"
42#include "ProfilerInfo.h"
43
47inline void printProfilerInfo(const mmind::eye::ProfilerInfo& profilerInfo)
48{
49 std::cout << "........................................." << std::endl;
50 std::cout << "Profiler Model Name: " << profilerInfo.model << std::endl;
51 std::cout << "Controller Serial Number: " << profilerInfo.controllerSN << std::endl;
52 std::cout << "Sensor Serial Number: " << profilerInfo.sensorSN << std::endl;
53 std::cout << "Profiler IP Address: " << profilerInfo.ipAddress << std::endl;
54 std::cout << "Profiler IP Subnet Mask: " << profilerInfo.subnetMask << std::endl;
55 std::cout << "Profiler IP Assignment Method: "
56 << mmind::eye::ipAssignmentMethodToString(profilerInfo.ipAssignmentMethod)
57 << std::endl;
58 std::cout << "Hardware Version: "
59 << "V" << profilerInfo.hardwareVersion.toString() << std::endl;
60 std::cout << "Firmware Version: "
61 << "V" << profilerInfo.firmwareVersion.toString() << std::endl;
62 std::cout << "........................................." << std::endl;
63 std::cout << std::endl;
64}
65
66inline void printProfilerStatus(const mmind::eye::ProfilerStatus& profilerStatus)
67{
68 std::cout << ".....Profiler temperatures....." << std::endl;
69 std::cout << "Controller CPU: " << std::setprecision(4)
70 << profilerStatus.temperature.controllerCpuTemperature << "°C" << std::endl;
71 std::cout << "Sensor CPU: " << std::setprecision(4)
72 << profilerStatus.temperature.sensorCpuTemperature << "°C" << std::endl;
73 std::cout << "..............................." << std::endl;
74 std::cout << std::endl;
75}
76
81inline bool findAndConnect(mmind::eye::Profiler& profiler)
82{
83 std::cout << "Find Mech-Eye 3D Laser Profilers..." << std::endl;
84 std::vector<mmind::eye::ProfilerInfo> profilerInfoList =
86
87 if (profilerInfoList.empty()) {
88 std::cout << "No Mech-Eye 3D Laser Profiler found." << std::endl;
89 return false;
90 }
91
92 for (int i = 0; i < profilerInfoList.size(); i++) {
93 std::cout << "Mech-Eye 3D Laser profiler index : " << i << std::endl;
94 printProfilerInfo(profilerInfoList[i]);
95 }
96
97 std::cout << "Please enter the profiler index you want to connect: ";
98 unsigned inputIndex = 0;
99
100 while (true) {
101 std::string str;
102 std::cin >> str;
103 if (std::regex_match(str.begin(), str.end(), std::regex{"[0-9]+"}) &&
104 atoi(str.c_str()) < profilerInfoList.size()) {
105 inputIndex = atoi(str.c_str());
106 break;
107 }
108 std::cout << "Input invalid! Please enter the profiler index you want to connect: ";
109 }
110
112 status = profiler.connect(profilerInfoList[inputIndex]);
113
114 if (!status.isOK()) {
115 showError(status);
116 return false;
117 }
118
119 std::cout << "Connect Mech-Eye 3D Laser Profiler Successfully." << std::endl;
120 return true;
121}
122
123inline std::vector<mmind::eye::Profiler> findAndConnectMultiProfiler()
124{
125 std::cout << "Find Mech-Eye 3D Laser Profilers..." << std::endl;
126 std::vector<mmind::eye::ProfilerInfo> profilerInfoList =
128
129 if (profilerInfoList.empty()) {
130 std::cout << "No Mech-Eye 3D Laser Profilers found." << std::endl;
131 return {};
132 }
133
134 for (int i = 0; i < profilerInfoList.size(); i++) {
135 std::cout << "Mech-Eye 3D Laser Profiler index : " << i << std::endl;
136 printProfilerInfo(profilerInfoList[i]);
137 }
138
139 std::string str;
140 std::set<unsigned> indices;
141
142 while (true) {
143 std::cout << "Please enter the device index you want to connect: " << std::endl;
144 std::cout << "Enter the character 'c' to terminate adding devices" << std::endl;
145
146 std::cin >> str;
147 if (str == "c")
148 break;
149 if (std::regex_match(str.begin(), str.end(), std::regex{"[0-9]+"}) &&
150 atoi(str.c_str()) < profilerInfoList.size())
151 indices.insert(atoi(str.c_str()));
152 else
153 std::cout << "Input invalid. Please enter the device index you want to connect: ";
154 }
155
156 std::vector<mmind::eye::Profiler> profilerList{};
157
158 auto iter = indices.cbegin();
159 for (int i = 0; i < indices.size(); ++i, ++iter) {
160 mmind::eye::Profiler profiler;
161 auto status = profiler.connect(profilerInfoList[*iter]);
162 if (status.isOK())
163 profilerList.push_back(profiler);
164 else
165 showError(status);
166 }
167
168 return profilerList;
169}
170
171inline bool confirmCapture()
172{
173 std::cout << "Do you want the profiler to capture image? Please input y/n to confirm: "
174 << std::endl;
175 while (true) {
176 std::string confirmStr;
177 std::cin >> confirmStr;
178 if (confirmStr == "y") {
179 return true;
180 } else if (confirmStr == "n") {
181 std::cout << "program ends!" << std::endl;
182 return false;
183 } else {
184 std::cout << "Please input y/n again!" << std::endl;
185 }
186 }
187}
Operates the laser profiler. Use Profiler::connect to connect an available laser profiler,...
Definition Profiler.h:68
static std::vector< ProfilerInfo > discoverProfilers()
Discovers all available laser profilers, and returns the laser profiler information list....
ErrorStatus connect(const ProfilerInfo &info, unsigned int timeoutMs=5000)
Connects to a laser profiler via ProfilerInfo.
std::string toString() const
Converts a Version object to a string.
Definition Version.h:71
Describes the types of errors.
Definition ErrorStatus.h:12
bool isOK() const
Returns true if the operation succeeded.
Definition ErrorStatus.h:71
Describes the laser profiler information.
Version hardwareVersion
The version of the hardware. The hardware cannot be upgraded.
Version firmwareVersion
The version of the firmware. The firmware can be upgraded.
std::string subnetMask
The IP subnet mask of the laser profiler.
IpAssignmentMethod ipAssignmentMethod
The IP address assignment method of the laser profiler.
std::string model
The laser profiler model.
std::string controllerSN
The controller serial number.
std::string sensorSN
The sensor serial number.
std::string ipAddress
The IP address of the laser profiler.
Describes the laser profiler's statuses.
Definition Profiler.h:58
float controllerCpuTemperature
The temperature (in °C) of the controller CPU.
Definition Profiler.h:50
float sensorCpuTemperature
The temperature (in °C) of the FPGA.
Definition Profiler.h:51