Skip to content

Commit 4e5f125

Browse files
Feature/error handling (#57)
* handling ros shutdown to exit the node gracefully * Fixing rebase conflicts * Little stuff to match with dev Co-authored-by: Vikrant Shah <[email protected]>
1 parent 15aeb14 commit 4e5f125

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

src/camera.cpp

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,38 @@ void acquisition::Camera::deinit() {
3737
}
3838

3939
ImagePtr acquisition::Camera::grab_frame() {
40-
ImagePtr pResultImage = pCam_->GetNextImage(GET_NEXT_IMAGE_TIMEOUT_);
41-
// Check if the Image is complete
40+
ImagePtr pResultImage;
41+
try{
42+
pResultImage = pCam_->GetNextImage(GET_NEXT_IMAGE_TIMEOUT_);
43+
// Check if the Image is complete
4244

43-
if (pResultImage->IsIncomplete()) {
44-
45-
ROS_WARN_STREAM("Image incomplete with image status " << pResultImage->GetImageStatus() << "!");
45+
if (pResultImage->IsIncomplete()) {
4646

47-
} else {
47+
ROS_WARN_STREAM("Image incomplete with image status " << pResultImage->GetImageStatus() << "!");
4848

49-
timestamp_ = pResultImage->GetTimeStamp();
50-
51-
if (frameID_ >= 0) {
52-
lastFrameID_ = frameID_;
53-
frameID_ = pResultImage->GetFrameID();
54-
ROS_WARN_STREAM_COND(frameID_ > lastFrameID_ + 1,"Frames are being skipped!");
5549
} else {
56-
frameID_ = pResultImage->GetFrameID();
57-
ROS_ASSERT_MSG(frameID_ == 0 ,"First frame ID was not zero! Might cause sync issues later...");
50+
51+
timestamp_ = pResultImage->GetTimeStamp();
52+
53+
if (frameID_ >= 0) {
54+
lastFrameID_ = frameID_;
55+
frameID_ = pResultImage->GetFrameID();
56+
ROS_WARN_STREAM_COND(frameID_ > lastFrameID_ + 1,"Frames are being skipped!");
57+
} else {
58+
frameID_ = pResultImage->GetFrameID();
59+
ROS_ASSERT_MSG(frameID_ == 0 ,"First frame ID was not zero! Might cause sync issues later...");
60+
}
61+
5862
}
5963

64+
ROS_DEBUG_STREAM("Grabbed frame from camera " << get_id() << " with timestamp " << timestamp_*1000);
65+
return pResultImage;
66+
}
67+
catch(Spinnaker::Exception &e){
68+
ROS_FATAL_STREAM(e.what()<<"\n Likely reason is that slaves are not triggered. Check GPIO cables\n");
6069
}
6170

62-
ROS_DEBUG_STREAM("Grabbed frame from camera " << get_id() << " with timestamp " << timestamp_*1000);
63-
return pResultImage;
71+
return pResultImage;
6472
}
6573

6674
// Returns last timestamp
@@ -80,8 +88,14 @@ int acquisition::Camera::get_frame_id() {
8088

8189
Mat acquisition::Camera::grab_mat_frame() {
8290

83-
ImagePtr pResultImage = grab_frame();
84-
return convert_to_mat(pResultImage);
91+
try{
92+
ImagePtr pResultImage = grab_frame();
93+
return convert_to_mat(pResultImage);
94+
}
95+
catch(Spinnaker::Exception &e){
96+
ros::shutdown();
97+
}
98+
8599

86100
}
87101

src/capture.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ acquisition::Capture::~Capture(){
2323

2424
ROS_INFO_STREAM("Releasing camera pointers...");
2525
cams.clear();
26-
26+
2727
ROS_INFO_STREAM("Releasing system instance...");
2828
system_->ReleaseInstance();
2929

@@ -38,8 +38,6 @@ acquisition::Capture::~Capture(){
3838
//reset it_
3939
it_.reset();
4040

41-
ros::shutdown();
42-
4341
}
4442

4543
acquisition::Capture::Capture() {
@@ -1064,6 +1062,8 @@ void acquisition::Capture::run_soft_trig() {
10641062
catch(...){
10651063
ROS_FATAL_STREAM("Some unknown exception occured. \v Exiting gracefully, \n possible reason could be Camera Disconnection...");
10661064
}
1065+
ros::shutdown();
1066+
//raise(SIGINT);
10671067
}
10681068

10691069
float acquisition::Capture::mem_usage() {

0 commit comments

Comments
 (0)