Skip to content

Commit bd51054

Browse files
committed
add file
1 parent e67802a commit bd51054

11 files changed

Lines changed: 97 additions & 55 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,4 @@ if (NOT CMAKE_BUILD_TYPE)
1111
endif ()
1212

1313
add_subdirectory(infinite_sense_core)
14-
15-
add_executable(${PROJECT_NAME}_zmq_node
16-
example/ZMQ/main.cpp
17-
)
18-
target_link_libraries(${PROJECT_NAME}_zmq_node PRIVATE
19-
infinite_sense_core
20-
)
14+
add_subdirectory(example)

example/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(example)
3+
4+
add_subdirectory(GigeCam)

example/CustomCam/CMakeLists.txt

Whitespace-only changes.

example/GigeCam/CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(gige_cam VERSION 1.0)
4+
5+
set(CMAKE_CXX_STANDARD 17)
6+
7+
if (NOT CMAKE_BUILD_TYPE)
8+
set(CMAKE_BUILD_TYPE Release)
9+
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -O3 -Wall")
10+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wall")
11+
endif ()
12+
13+
14+
# 检测平台并设置相关变量
15+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
16+
set(PLATFORM_DIR "arm")
17+
set(MVCAM_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/mvcam/lib/aarch64)
18+
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "amd64")
19+
set(PLATFORM_DIR "x86")
20+
set(MVCAM_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/mvcam/lib/x86/64)
21+
else ()
22+
message(STATUS "Unknown Architecture")
23+
set(PLATFORM_DIR "Unknown")
24+
endif ()
25+
message(STATUS "Find MVCAM_LIB_DIR : ${MVCAM_LIB_DIR}")
26+
27+
28+
add_executable(${PROJECT_NAME}
29+
main.cpp
30+
mv_cam.cpp
31+
mv_cam.h
32+
)
33+
target_link_directories(${PROJECT_NAME} PRIVATE
34+
${MVCAM_LIB_DIR}
35+
)
36+
37+
target_link_libraries(${PROJECT_NAME} PRIVATE
38+
infinite_sense_core
39+
MvCameraControl
40+
)
41+
42+
target_include_directories(${PROJECT_NAME} PRIVATE
43+
mvcam/include
44+
)
45+
set_target_properties(${PROJECT_NAME} PROPERTIES
46+
INSTALL_RPATH "$ORIGIN"
47+
)

example/GigeCam/main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
#include "mv_cam.h"
33
using namespace infinite_sense;
44
int main() {
5-
65
// 1.创建同步器
76
Synchronizer synchronizer;
87
synchronizer.SetUsbLink("/dev/ttyACM0", 460800);
98
// 2.配置同步接口
10-
std::map<std::string, TriggerDevice> params;
11-
params["camera_1"] = CAM_1;
12-
const auto mv_cam = std::make_shared<MvCam>(params);
9+
std::map<std::string, TriggerDevice> params = {{"camera_1", CAM_1}};
10+
auto mv_cam = std::make_shared<MvCam>();
11+
mv_cam->SetParams(params);
1312
synchronizer.UseCam(mv_cam);
1413

1514
// 3.开启同步

example/GigeCam/mv_cam.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,17 @@ bool MvCam::Initialization() {
148148
return false;
149149
}
150150
}
151-
void MvCam::Restart() {
152-
Stop();
153-
std::this_thread::sleep_for(std::chrono::milliseconds{500});
154-
if (!Initialization()) {
155-
LOG(INFO) << "Camera initialization failed after restart!";
156-
} else {
157-
Start();
158-
LOG(INFO) << "Cameras successfully restarted!";
159-
}
160-
}
161151

162152
void MvCam::Stop() {
163153
Disable();
164154
std::this_thread::sleep_for(std::chrono::milliseconds{500});
165-
for (auto &cam_thread : cam_threads_) {
155+
for (auto &cam_thread : cam_threads) {
166156
while (cam_thread.joinable()) {
167157
cam_thread.join();
168158
}
169159
}
170-
cam_threads_.clear();
171-
cam_threads_.shrink_to_fit();
160+
cam_threads.clear();
161+
cam_threads.shrink_to_fit();
172162
for (size_t i = 0; i < handles_.size(); ++i) {
173163
int n_ret = MV_OK;
174164
n_ret = MV_CC_StopGrabbing(handles_[i]);
@@ -193,7 +183,7 @@ void MvCam::Receive(void *handle, const std::string &name) {
193183
MV_FRAME_OUT st_out_frame;
194184
CamData cam_data;
195185
Messenger &messenger = Messenger::GetInstance();
196-
while (is_running_) {
186+
while (is_running) {
197187
memset(&st_out_frame, 0, sizeof(MV_FRAME_OUT));
198188
int n_ret = MV_CC_GetImageBuffer(handle, &st_out_frame, 10);
199189
if (n_ret == MV_OK) {
@@ -203,11 +193,11 @@ void MvCam::Receive(void *handle, const std::string &name) {
203193
LOG(ERROR) << "Get ExposureTime fail! n_ret [0x" << std::hex << n_ret << "]";
204194
}
205195
// 这里的time_stamp_us是相机触发时间,需要加上曝光时间的一半,以获得相机拍摄的时间
206-
if (params_.find(name) == params_.end()) {
196+
if (params.find(name) == params.end()) {
207197
LOG(ERROR) << "cam " << name << " not found!";
208198
}
209199
else {
210-
if (uint64_t time; GET_LAST_TRIGGER_STATUS(params_[name], time)) {
200+
if (uint64_t time; GET_LAST_TRIGGER_STATUS(params[name], time)) {
211201
cam_data.time_stamp_us = time + static_cast<uint64_t>(expose_time.fCurValue / 2.);
212202
}
213203
else {
@@ -272,7 +262,7 @@ void MvCam::Start() {
272262
name = "cam_" + std::to_string(cam_index++);
273263
LOG(WARNING) << "Camera name is empty,create name " << name;
274264
}
275-
cam_threads_.emplace_back(&MvCam::Receive, this, handle, name);
265+
cam_threads.emplace_back(&MvCam::Receive, this, handle, name);
276266
LOG(INFO) << "Camera name is " << name << " start";
277267
}
278268
}

example/GigeCam/mv_cam.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace infinite_sense {
44
class MvCam final : public Sensor {
55
public:
6-
explicit MvCam(const std::map<std::string, TriggerDevice>& params) : params_(params) {}
76
~MvCam() override;
87

98
bool Initialization() override;
@@ -12,10 +11,7 @@ class MvCam final : public Sensor {
1211

1312
private:
1413
void Receive(void* handle, const std::string&) override;
15-
bool is_running_{false};
1614
std::vector<int> rets_;
1715
std::vector<void*> handles_;
18-
std::vector<std::thread> cam_threads_;
19-
std::map<std::string, TriggerDevice> params_;
2016
};
2117
} // namespace infinite_sense

infinite_sense_core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ add_library(${PROJECT_NAME} SHARED
2828
src/net.cpp
2929
src/messenger.cpp
3030
src/ptp.cpp
31+
src/sensor.cpp
3132
)
3233
target_link_directories(${PROJECT_NAME} PUBLIC
3334
${CMAKE_INSTALL_RPATH}

infinite_sense_core/include/sensor.h

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,31 @@
22
#include <thread>
33
#include <vector>
44
#include "messenger.h"
5+
#include "trigger.h"
56
namespace infinite_sense {
67
class Sensor {
78
public:
89
Sensor();
9-
explicit Sensor(const std::map<std::string, TriggerDevice>& params) : params_(params) {}
1010
virtual ~Sensor();
1111

12-
Sensor(const Sensor&) = delete;
13-
Sensor& operator=(const Sensor&) = delete;
12+
virtual bool Initialization() = 0;
1413

15-
virtual bool Initialization();
16-
virtual void Stop();
17-
virtual void Start();
18-
virtual void Restart() {
19-
Stop();
20-
std::this_thread::sleep_for(std::chrono::milliseconds{500});
21-
if (!Initialization()) {
22-
LOG(INFO) << "Camera initialization failed after restart!";
23-
} else {
24-
Start();
25-
LOG(INFO) << "Cameras successfully restarted!";
26-
}
27-
}
28-
void Enable() { is_running_ = true; }
29-
void Disable() { is_running_ = false; }
14+
virtual void Stop() = 0;
15+
16+
virtual void Start() = 0;
17+
18+
void Restart();
19+
void Enable() { is_running = true; }
20+
void Disable() { is_running = false; }
21+
void SetParams(const std::map<std::string, TriggerDevice> &params_in) { params = params_in; };
3022

3123
private:
32-
virtual void Receive(void* handle, const std::string&);
33-
bool is_running_{false};
34-
std::vector<std::thread> cam_threads_{};
35-
std::map<std::string, TriggerDevice> params_{};
24+
virtual void Receive(void *handle, const std::string &) = 0;
25+
26+
protected:
27+
bool is_running{false};
28+
std::vector<std::thread> cam_threads{};
29+
std::map<std::string, TriggerDevice> params{};
3630
};
3731

3832
} // namespace infinite_sense

infinite_sense_core/src/sensor.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "sensor.h"
2+
3+
namespace infinite_sense {
4+
Sensor::Sensor() = default;
5+
6+
Sensor::~Sensor() = default;
7+
8+
void Sensor::Restart() {
9+
Stop();
10+
std::this_thread::sleep_for(std::chrono::milliseconds{500});
11+
if (!Initialization()) {
12+
LOG(INFO) << "Camera initialization failed after restart!";
13+
} else {
14+
Start();
15+
LOG(INFO) << "Cameras successfully restarted!";
16+
}
17+
}
18+
} // namespace infinite_sense

0 commit comments

Comments
 (0)