Skip to content

Commit 59d31e3

Browse files
committed
Add CMake option to enable registers logging
Improve sensors logging Modify `ll_activate_sync` to enable SYNC output for both camera sensors
1 parent 00cd1e8 commit 59d31e3

File tree

5 files changed

+78
-28
lines changed

5 files changed

+78
-28
lines changed

CMakeLists.txt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ endif()
3030
option(BUILD_VIDEO "Build the ZED Open Capture Video Modules (only for Linux)" ON)
3131
option(BUILD_SENSORS "Build the ZED Open Capture Sensors Modules" ON)
3232
option(BUILD_EXAMPLES "Build the ZED Open Capture examples" ON)
33+
option(DEBUG_CAM_REG "Add functions to log the values of the registers of camera" OFF)
3334

3435
############################################################################
3536
# Sources
@@ -72,6 +73,11 @@ list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake")
7273

7374
############################################################################
7475
# Generate libraries
76+
if(DEBUG_CAM_REG)
77+
message("* Registers logging available")
78+
add_definitions(-DSENSOR_LOG_AVAILABLE)
79+
endif()
80+
7581
if(BUILD_SENSORS)
7682
message("* Sensors module available")
7783
add_definitions(-DSENSORS_MOD_AVAILABLE)
@@ -162,16 +168,18 @@ if(BUILD_EXAMPLES)
162168
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
163169
)
164170

165-
##### Video with AEG/AGC reisters log
166-
add_executable(${PROJECT_NAME}_video_reg_log "${PROJECT_SOURCE_DIR}/examples/zed_oc_video_reg_log.cpp")
167-
set_target_properties(${PROJECT_NAME}_video_reg_log PROPERTIES PREFIX "")
168-
target_link_libraries(${PROJECT_NAME}_video_reg_log
169-
${PROJECT_NAME}
170-
${OpenCV_LIBS}
171-
)
172-
install(TARGETS ${PROJECT_NAME}_video_reg_log
173-
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
174-
)
171+
if(DEBUG_CAM_REG)
172+
##### Video with AEG/AGC reisters log
173+
add_executable(${PROJECT_NAME}_video_reg_log "${PROJECT_SOURCE_DIR}/examples/zed_oc_video_reg_log.cpp")
174+
set_target_properties(${PROJECT_NAME}_video_reg_log PROPERTIES PREFIX "")
175+
target_link_libraries(${PROJECT_NAME}_video_reg_log
176+
${PROJECT_NAME}
177+
${OpenCV_LIBS}
178+
)
179+
install(TARGETS ${PROJECT_NAME}_video_reg_log
180+
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
181+
)
182+
endif()
175183
endif()
176184

177185
if(BUILD_SENSORS)

examples/zed_oc_control_example.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ void handleKeyboard( sl_oc::video::VideoCapture &cap, int key )
245245

246246
switch(key)
247247
{
248+
#ifdef SENSOR_LOG_AVAILABLE
248249
case 'L':
249250
{
250251
logging = !logging;
@@ -260,6 +261,7 @@ void handleKeyboard( sl_oc::video::VideoCapture &cap, int key )
260261
std::cout << std::string("*** AEC/AGC registers reset: ") << (res?std::string("OK"):std::string("KO")) << std::endl;
261262
}
262263
break;
264+
#endif
263265

264266
case 'l':
265267
{
@@ -346,8 +348,10 @@ void handleKeyboard( sl_oc::video::VideoCapture &cap, int key )
346348
std::cout << " * '+' -> Increase the current control value" << std::endl;
347349
std::cout << " * '-' -> Decrease the current control value" << std::endl;
348350
std::cout << " * '0' .. '9' -> Set the current control value" << std::endl;
351+
#ifdef SENSOR_LOG_AVAILABLE
349352
std::cout << " * 'L' -> Toggle AGC/AEC registers logging" << std::endl;
350353
std::cout << " * 'f' -> Fix AGC/AEC registers" << std::endl;
354+
#endif
351355
}
352356
}
353357

examples/zed_oc_video_reg_log.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,22 @@ int main(int argc, char *argv[])
6060
// Enable AGC/AEG registers logging
6161
cap.enableAecAgcSensLogging(false);
6262

63+
uint64_t last_ts=0;
64+
uint16_t not_a_new_frame = 0;
65+
int frame_timeout_msec = 100;
66+
6367
int f_count = 0;
6468
// Infinite video grabbing loop
6569
while (1)
6670
{
6771
// Get last available frame
68-
const sl_oc::video::Frame frame = cap.getLastFrame();
72+
const sl_oc::video::Frame frame = cap.getLastFrame(frame_timeout_msec);
6973

7074
// ----> If the frame is valid we can display it
71-
if(frame.data!=nullptr)
75+
if(frame.data!=nullptr && frame.timestamp!=last_ts)
7276
{
77+
last_ts = frame.timestamp;
78+
not_a_new_frame=0;
7379
#ifdef TEST_FPS
7480
if(lastFrameTs!=0)
7581
{
@@ -88,13 +94,12 @@ int main(int argc, char *argv[])
8894
lastFrameTs = frame.timestamp;
8995
#endif
9096

91-
92-
if (f_count%10==0)
93-
{
94-
cap.saveAllISPRegisters("ov580_lr_"+std::to_string(f_count)+".csv");
95-
cap.saveAllSensorsRegisters("ov4689_lr_"+std::to_string(f_count)+".csv");
96-
std::cout<<" Save Data for f_count "<<f_count<<std::endl;
97-
}
97+
// if (f_count!=0 && f_count%10==0)
98+
// {
99+
// cap.saveAllISPRegisters("ov580_lr_"+std::to_string(f_count)+".csv");
100+
// cap.saveAllSensorsRegisters("ov4689_lr_"+std::to_string(f_count)+".csv");
101+
// std::cout<<" Save Data for f_count "<<f_count<<std::endl;
102+
// }
98103

99104

100105
// ----> Conversion from YUV 4:2:2 to BGR for visualization
@@ -107,6 +112,21 @@ int main(int argc, char *argv[])
107112
// Show frame
108113
cv::imshow( "Stream RGB", frameBGR );
109114
}
115+
else
116+
{
117+
not_a_new_frame++;
118+
std::cout << "Not a new frame #" << not_a_new_frame << std::endl;
119+
120+
if( not_a_new_frame>=(1000/frame_timeout_msec)) // Lost connection for 1 seconds
121+
{
122+
cap.saveAllISPRegisters("ov580_lr_"+std::to_string(f_count)+"_not_a_new _frame.csv");
123+
cap.saveAllSensorsRegisters("ov4689_lr_"+std::to_string(f_count)+"_not_a_new _frame.csv");
124+
std::cout<<" Save Data for f_count "<<f_count<<std::endl;
125+
126+
std::cout << "Camera connection lost. Closing..." << std::endl;
127+
break;
128+
}
129+
}
110130
// <---- If the frame is valid we can display it
111131

112132
// ----> Keyboard handling

include/videocapture.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ class SL_OC_EXPORT VideoCapture
340340
*/
341341
int getSerialNumber();
342342

343+
#ifdef SENSOR_LOG_AVAILABLE
343344
/*!
344345
* \brief Start logging to file of AEG/AGC camera registers
345346
* \param enable set to true to enable logging
@@ -348,7 +349,6 @@ class SL_OC_EXPORT VideoCapture
348349
*/
349350
bool enableAecAgcSensLogging(bool enable, int frame_skip=10);
350351

351-
352352
/*!
353353
* \brief Save all ISP camera registers into a file
354354
* \param filename csv filename
@@ -362,6 +362,7 @@ class SL_OC_EXPORT VideoCapture
362362
* \note CSV file will contain Adress , L value, R value
363363
*/
364364
void saveAllSensorsRegisters(std::string filename);
365+
#endif
365366

366367

367368
#ifdef SENSORS_MOD_AVAILABLE
@@ -452,10 +453,10 @@ class SL_OC_EXPORT VideoCapture
452453
return std::string(buf);
453454
}
454455

456+
#ifdef SENSOR_LOG_AVAILABLE
455457
void saveLogDataLeft();
456458
void saveLogDataRight();
457-
458-
459+
#endif
459460

460461
private:
461462
// Flags
@@ -495,6 +496,7 @@ class SL_OC_EXPORT VideoCapture
495496

496497
bool mFirstFrame=true; //!< Used to initialize the timestamp start point
497498

499+
#ifdef SENSOR_LOG_AVAILABLE
498500
// ----> Registers logging
499501
bool mLogEnable=false;
500502
std::string mLogFilenameLeft;
@@ -503,6 +505,7 @@ class SL_OC_EXPORT VideoCapture
503505
std::ofstream mLogFileRight;
504506
int mLogFrameSkip=10;
505507
// <---- Registers logging
508+
#endif
506509

507510

508511
#ifdef SENSORS_MOD_AVAILABLE

src/videocapture.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#include <cmath> // for round
4242

43+
#define IOCTL_RETRY 3
4344

4445
#define READ_MODE 1
4546
#define WRITE_MODE 2
@@ -656,8 +657,6 @@ int VideoCapture::input_set_framerate(int fps)
656657
return xioctl(mFileDesc, VIDIOC_S_PARM, &streamparm);
657658
}
658659

659-
#define IOCTL_RETRY 3
660-
661660
int VideoCapture::xioctl(int fd, uint64_t IOCTL_X, void *arg)
662661
{
663662
int ret = 0;
@@ -835,6 +834,7 @@ void VideoCapture::grabThreadFunc()
835834
}
836835
#endif
837836

837+
#ifdef SENSOR_LOG_AVAILABLE
838838
// ----> AEC/AGC register logging
839839
if(mLogEnable)
840840
{
@@ -851,6 +851,7 @@ void VideoCapture::grabThreadFunc()
851851
}
852852
}
853853
// <---- AEC/AGC register logging
854+
#endif
854855

855856
mNewFrame=true;
856857
}
@@ -1371,11 +1372,23 @@ int VideoCapture::ll_isp_set_exposure(unsigned char ucExpH, unsigned char ucExpM
13711372

13721373
void VideoCapture::ll_activate_sync()
13731374
{
1374-
uint8_t sync_val = 0x0;
1375-
if (ll_read_sensor_register(0, 1, 0x3002, &sync_val) == 0)
1375+
uint8_t sync_val_left = 0x0;
1376+
uint8_t sync_val_right = 0x0;
1377+
1378+
// Activate VSYNC output for both camera sensors
1379+
1380+
if (ll_read_sensor_register(0, 1, 0x3002, &sync_val_left) == 0)
13761381
{
1377-
sync_val = sync_val | 0x80;
1378-
ll_write_sensor_register(0, 1, 0x3002, sync_val);
1382+
sync_val_left = sync_val_left | 0x80;
1383+
1384+
ll_write_sensor_register(0, 1, 0x3002, sync_val_left);
1385+
}
1386+
1387+
if (ll_read_sensor_register(1, 1, 0x3002, &sync_val_right) == 0)
1388+
{
1389+
sync_val_right = sync_val_right | 0x80;
1390+
1391+
ll_write_sensor_register(1, 1, 0x3002, sync_val_left);
13791392
}
13801393
}
13811394

@@ -1911,6 +1924,7 @@ int VideoCapture::calcGainValue(int rawGain)
19111924
return gain;
19121925
}
19131926

1927+
#ifdef SENSOR_LOG_AVAILABLE
19141928
bool VideoCapture::enableAecAgcSensLogging(bool enable, int frame_skip/*=10*/)
19151929
{
19161930
if(!enable)
@@ -2107,6 +2121,7 @@ bool VideoCapture::resetAGCAECregisters() {
21072121

21082122
return res==0;
21092123
}
2124+
#endif
21102125

21112126
#ifdef SENSORS_MOD_AVAILABLE
21122127
bool VideoCapture::enableSensorSync( sensors::SensorCapture* sensCap )

0 commit comments

Comments
 (0)