IRSOL
C++ code implementing socket server for interacting with Baumer camera.
main.cpp File Reference

Demonstrates how to get and set camera features using irsol::camera::Interface. More...

#include "irsol/irsol.hpp"

Go to the source code of this file.

Macros

#define PROGRAM_NAME   "camera-feature-demo"
 

Functions

const std::string getProgramName ()
 Returns the program name for logging.
 
void demoCameraFeatures (irsol::camera::Interface &cam)
 Initializes camera and logs various feature values.
 
int main ()
 Main entry point for the feature demo application.
 

Detailed Description

Demonstrates how to get and set camera features using irsol::camera::Interface.

Demonstrates basic creation and serialization of protocol messages using irsol::protocol.

Definition in file main.cpp.

Macro Definition Documentation

◆ PROGRAM_NAME

#define PROGRAM_NAME   "camera-feature-demo"

Function Documentation

◆ demoCameraFeatures()

void demoCameraFeatures ( irsol::camera::Interface cam)

Initializes camera and logs various feature values.

Definition at line 18 of file main.cpp.

19{
20 IRSOL_LOG_INFO("=== Discovering all camera features ===");
22
23 IRSOL_LOG_INFO("=== Original Camera Information ===");
25
26 IRSOL_LOG_INFO("=== Reading Common Camera Parameters ===");
27 auto mode = cam.getParam<std::string>("AcquisitionMode");
28 IRSOL_LOG_INFO("AcquisitionMode: {}", mode);
29
30 auto fpsEnable = cam.getParam<bool>("AcquisitionFrameRateEnable");
31 auto fps = cam.getParam<double>("AcquisitionFrameRate");
32 IRSOL_LOG_INFO("AcquisitionFrameRateEnable: {}", fpsEnable);
33 IRSOL_LOG_INFO("AcquisitionFrameRate: {:.2f}", fps);
34
35 auto exposure = cam.getExposure();
36 IRSOL_LOG_INFO("Current exposure time: {}", irsol::utils::durationToString(exposure));
37
38 IRSOL_LOG_INFO("=== Modifying Parameters ===");
39 // Set exposure
40 auto newExposure = std::chrono::microseconds(15000);
41 auto actualNewExposure = cam.setExposure(newExposure);
43 "New exposure set to: {}, actual value now: {}",
45 irsol::utils::durationToString(actualNewExposure));
46
47 // Set FPS (requires enabling first)
48 auto newAcquisitionFrameRateEnable = true;
49 auto actualAcquisitionFrameRateEnable =
50 cam.setParam("AcquisitionFrameRateEnable", newAcquisitionFrameRateEnable);
52 "New acquisition frame rate enablement set to: {}, actual value now: {}",
53 newAcquisitionFrameRateEnable,
54 actualAcquisitionFrameRateEnable);
55 auto newAcquisitionFrameRate = 12.5;
56 auto actualAcquisitionFrameRate = cam.setParam("AcquisitionFrameRate", newAcquisitionFrameRate);
58 "New acquisition frame rate set to: {}, actual value now: {}",
59 newAcquisitionFrameRate,
60 actualAcquisitionFrameRate);
61
62 // Change acquisition mode to SingleFrame
63 cam.setParam("AcquisitionMode", "SingleFrame");
64 IRSOL_LOG_INFO("AcquisitionMode set to SingleFrame");
65
66 // Use setMultiParam for grouped settings
67 cam.setMultiParam({
68 {"OffsetX", 0},
69 {"OffsetY", 0},
70 {"Height", 124},
71 });
72 IRSOL_LOG_INFO("Updated Offset and Height window");
73
74 IRSOL_LOG_INFO("=== Capturing Image ===");
75 auto image = cam.captureImage();
76 if(image.IsEmpty()) {
77 IRSOL_LOG_WARN("Image is empty.");
78 } else {
80 "Captured image: {}x{} ({} bytes)", image.GetHeight(), image.GetWidth(), image.GetSize());
81 }
82
83 IRSOL_LOG_INFO("=== Reading Back New Parameter Values ===");
84 IRSOL_LOG_INFO("AcquisitionFrameRate: {:.2f}", cam.getParam<double>("AcquisitionFrameRate"));
86 IRSOL_LOG_INFO("AcquisitionMode: {}", cam.getParam<std::string>("AcquisitionMode"));
87
88 IRSOL_LOG_INFO("=== Final Camera Information ===");
90}
std::string cameraStatusAsString() const
Get current camera status.
image_t captureImage(std::optional< irsol::types::duration_t > timeout=std::nullopt)
Capture a single image from the camera.
T setParam(const std::string &param, T value)
Set a camera parameter of arbitrary type T.
T getParam(const std::string &param) const
Retrieve a camera parameter of arbitrary type T.
irsol::types::duration_t setExposure(irsol::types::duration_t exposure)
Set the exposure time of the camera.
void setMultiParam(const std::unordered_map< std::string, camera_param_t > &params)
Set multiple parameters in one call.
irsol::types::duration_t getExposure() const
Get the current exposure time from the camera.
#define IRSOL_LOG_INFO(...)
Logs an info-level message using the default logger.
Definition logging.hpp:92
#define IRSOL_LOG_WARN(...)
Logs a warning-level message using the default logger.
Definition logging.hpp:93
std::string discoverCameraFeatures(Interface &cam)
Discovers all camera features and their permissions.
Definition discovery.cpp:47
std::string durationToString(irsol::types::duration_t dr)
Converts a duration to a human-readable string.
Definition utils.cpp:133

◆ getProgramName()

const std::string getProgramName ( )

Returns the program name for logging.

Definition at line 8 of file main.cpp.

9{
10#ifndef PROGRAM_NAME
11#define PROGRAM_NAME "camera-feature-demo"
12#endif
13 return PROGRAM_NAME;
14}
#define PROGRAM_NAME

◆ main()

int main ( )

Main entry point for the feature demo application.

Definition at line 94 of file main.cpp.

95{
96 // Initialize logging
97 std::string logPath = "logs/" + getProgramName() + ".log";
98 irsol::initLogging(logPath.c_str(), spdlog::level::debug);
100
101 // Create camera interface
103
104 IRSOL_ASSERT_FATAL(cam.isConnected(), "Camera is not connected");
105
106 // Run feature demo
108
109 return 0;
110}
static Interface HalfResolution()
Factory method to create a camera interface using half sensor resolution.
Definition interface.cpp:63
const std::string getProgramName()
Returns the program name, typically used for logging. If PROGRAM_NAME is not defined at compile time,...
Definition main.cpp:12
void demoCameraFeatures(irsol::camera::Interface &cam)
Initializes camera and logs various feature values.
Definition main.cpp:18
void initAssertHandler()
Initializes the assertion handler system.
Definition assert.cpp:14
#define IRSOL_ASSERT_FATAL
Fatal-level assertion macro.
Definition assert.hpp:135
void initLogging(const char *fileSinkFilename="logs/irsol.log", std::optional< spdlog::level::level_enum > minLogLevel=std::nullopt)
Initializes the irsol logging system.
Definition logging.cpp:108