Skip to content

Commit 3cce10c

Browse files
author
Daniel Claes
committed
feature(): capture RGBD service
1 parent 39ca5cb commit 3cce10c

11 files changed

+58
-185
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ build
22
BUILD
33
Build
44
*.user
5+
*.idea

CMakeLists.txt

+14-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ find_package(
3939
catkin REQUIRED
4040
COMPONENTS
4141
sr_foundation
42+
message_generation
4243
rgbd
4344
roscpp
4445
rospy
@@ -68,6 +69,19 @@ message(STATUS "Ensenso Libraries found at ${ENSENSO_LIBRARIES}.")
6869
# add other necessary include directories
6970
include_directories(src/ ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
7071

72+
## Generate services in the 'srv' folder
73+
add_service_files(
74+
FILES
75+
CaptureRGBD.srv
76+
)
77+
78+
79+
generate_messages( DEPENDENCIES
80+
std_msgs
81+
rgbd
82+
)
83+
84+
7185
# Set source files
7286
SET(SRCS_LIB
7387
src/ensenso_nx.cpp
@@ -104,9 +118,6 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME}
104118
${ENSENSO_LIBRARIES} ${OpenCV_LIBS} ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES} ${catkin_LIBRARIES})
105119
add_dependencies(${PROJECT_NAME} ${catkin_EXPORTED_TARGETS})
106120

107-
#Build examples
108-
ADD_SUBDIRECTORY(src/examples)
109-
110121
install(DIRECTORY urdf DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
111122
install(DIRECTORY launch DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
112123
install(DIRECTORY config DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

src/ensenso_nx.cpp

+6-33
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "ros/ros.h"
33

44
void ensensoExceptionHandling (const NxLibException &ex,
5-
std::string func_nam)
5+
const std::string func_nam)
66
{
77
ROS_ERROR ("%s: NxLib error %s (%d) occurred while accessing item %s.\n", func_nam.c_str (), ex.getErrorText ().c_str (), ex.getErrorCode (),
88
ex.getItemPath ().c_str ());
@@ -86,21 +86,6 @@ namespace EnsensoNx
8686
this->configureCapture();
8787
}
8888

89-
// void Device::configureExposure(unsigned int _exposure)
90-
// {
91-
// if (_exposure == 0) //autoexposure case
92-
// {
93-
// capture_params_.auto_exposure_ = true;
94-
// }
95-
// else //manual exposure case
96-
// {
97-
// capture_params_.auto_exposure_ = false;
98-
// capture_params_.exposure_time_ = _exposure;
99-
// }
100-
//
101-
// //call protected member to set the configuration to the camera
102-
// this->configureCapture();
103-
// }
10489
void Device::preCapture() {
10590
// Capture images
10691
try {
@@ -117,7 +102,7 @@ namespace EnsensoNx
117102
{
118103
try {
119104
// Capture images
120-
//NxLibCommand (cmdCapture).execute();
105+
NxLibCommand (cmdCapture).execute();
121106

122107
// Compute Disparity Map
123108
NxLibCommand (cmdComputeDisparityMap).execute();
@@ -129,7 +114,7 @@ namespace EnsensoNx
129114
int width, height;
130115
double time_stamp;
131116
camera_[itmImages][itmPointMap].getBinaryDataInfo(&width, &height, nullptr,
132-
nullptr, nullptr, &time_stamp);
117+
nullptr, nullptr, nullptr);
133118
//std::cout << "ts1: " << std::fixed << time_stamp << std::endl;
134119
//Get 3D image raw data
135120
int nx_return_code;
@@ -177,13 +162,13 @@ namespace EnsensoNx
177162
int nx_return_code;
178163

179164
// Capture images
180-
//NxLibCommand(cmdCapture).execute();
165+
NxLibCommand (cmdCapture).execute();
181166

182167
// Compute Disparity Map
183-
NxLibCommand(cmdComputeDisparityMap).execute();
168+
NxLibCommand (cmdComputeDisparityMap).execute();
184169

185170
// Compute Point Cloud
186-
NxLibCommand(cmdComputePointMap).execute();
171+
NxLibCommand (cmdComputePointMap).execute();
187172
double time_stamp;
188173
// Get image dimensions
189174
camera_[itmImages][itmPointMap].getBinaryDataInfo(&ww, &hh, 0, 0, 0, &time_stamp);
@@ -227,14 +212,6 @@ namespace EnsensoNx
227212
kk);//checks if kk=ww*hh to set the cloud as ordered (width,height) or unordered (width=size,height=1)
228213
_p_cloud.is_dense = capture_params_.dense_cloud_;
229214

230-
//debug message
231-
// std::cout << "Cloud capture: " << std::endl <<
232-
// "\treturn code: " << nx_return_code << std::endl <<
233-
// "\tnum points: " << raw_points_.size()/3 << std::endl <<
234-
// "\twidth: " << ww << std::endl <<
235-
// "\theight: " << hh << std::endl <<
236-
// "\tvalid_points: " << kk << std::endl;
237-
238215
//return success
239216
return 1;
240217
}
@@ -245,17 +222,13 @@ namespace EnsensoNx
245222
}
246223
}
247224

248-
//PROTECTED METHODS
249225

250226
void Device::configureCapture()
251227
{
252228
//sets capture configuration to the camera
253229
camera_[itmParameters][itmCapture][itmAutoExposure] = capture_params_.auto_exposure_;
254230
camera_[itmParameters][itmCapture][itmExposure ] = (double)capture_params_.exposure_time_;//TODO check if requires cast to double.
255231

256-
//print out
257-
//std::cout << "EnsensoNx::Device: Capture params set to:" << std::endl;
258-
//capture_params_.print();
259232
}
260233

261234
}//close namespace

src/ensenso_nx_node.cpp

+23-22
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ bool EnsensoNxNode::publishRGBD()
8888
//Get a single capture from camera and publish the point cloud
8989
if ( camera_->capture(image_) == 1 )
9090
{
91-
//get time
92-
ros::Time ts = ros::Time::now();
93-
94-
//publish the cloud
95-
//image_.timestamp = (pcl::uint64_t)(ts.toSec()*1e9); //TODO: should be set by the EnsensoNx::Device class
9691
image_.frame_id = frame_name_;
9792
sr::rgbd::toData(image_, rgbd_msg.data);
9893

@@ -124,24 +119,30 @@ bool EnsensoNxNode::publishCloud()
124119
return false;
125120
}
126121

127-
bool EnsensoNxNode::publishServiceCallback(std_srvs::Trigger::Request &_request,
128-
std_srvs::Trigger::Response &_reply)
122+
bool EnsensoNxNode::publishServiceCallback(ensenso_nx::CaptureRGBD::Request &_request,
123+
ensenso_nx::CaptureRGBD::Response &_reply)
129124
{
125+
if (_request.exposure == 0) {
126+
capture_params_.auto_exposure_ = true;
127+
capture_params_.exposure_time_ = 0;
128+
}
129+
else {
130+
capture_params_.auto_exposure_ = false;
131+
capture_params_.exposure_time_ = _request.exposure;
132+
133+
}
134+
135+
camera_->configureCapture(capture_params_);
136+
137+
if ( camera_->capture(image_) == 1 ) {
138+
image_.frame_id = frame_name_;
139+
sr::rgbd::toData(image_, rgbd_msg.data);
140+
_reply.rgbd_image = rgbd_msg;
141+
_reply.success = true;
142+
}
143+
else {
144+
_reply.success = false;
145+
}
130146

131-
// capture_params_.auto_exposure_ = true;
132-
// capture_params_.dense_cloud_ = true;
133-
// camera_->configureCapture(capture_params_);
134-
//
135-
do_publish = true;
136-
// if (this->publish()){
137-
// _reply.message = "Successfully published.";
138-
// _reply.success = true;
139-
// }
140-
// else {
141-
// _reply.message = "Failed to publish.";
142-
// _reply.success = false;
143-
// }
144-
145-
//return
146147
return true;
147148
}

src/ensenso_nx_node.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
//this package dependencies
2121
#include <ensenso_nx/ensenso_nx_paramsConfig.h> //ROS dynamic configure
22+
#include <ensenso_nx/CaptureRGBD.h>
2223

2324
//enum run mode
2425
enum RunMode {SERVER=0,PUBLISHER};
@@ -92,8 +93,8 @@ class EnsensoNxNode
9293

9394
protected:
9495
//Service callback implementing the point cloud capture
95-
bool publishServiceCallback(std_srvs::Trigger::Request &_request,
96-
std_srvs::Trigger::Response &_reply);
96+
bool publishServiceCallback(ensenso_nx::CaptureRGBD::Request &_request,
97+
ensenso_nx::CaptureRGBD::Response &_reply);
9798

9899
};
99100
#endif

src/ensenso_nx_node_main.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ int main(int argc, char **argv)
1717
//node loop
1818
while ( ros::ok() )
1919
{
20-
ensenso.preCapture();
2120
//execute pending callbacks
2221
ros::spinOnce();
23-
if (ensenso.do_publish) {
24-
ensenso.publish();
25-
ensenso.do_publish = false;
26-
}
22+
2723
//switch according run mode
2824
switch(ensenso.runMode())
2925
{

src/examples/CMakeLists.txt

-7
This file was deleted.

src/examples/ex1_simple_capture.cpp

-53
This file was deleted.

src/examples/ex2_save_depth_image.cpp

-47
This file was deleted.

srv/CaptureRGBD.srv

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#Request/Reply for RGBDImage
2+
3+
# Request:
4+
# exposure in milliseconds (0 indicates autoexposure)
5+
uint32 exposure
6+
---
7+
8+
# Reply with the size of the captured rgbd_image
9+
rgbd/RGBDImage rgbd_image
10+
bool success

srv/PointCloudAsService.srv

-13
This file was deleted.

0 commit comments

Comments
 (0)