Skip to content

Commit 2945642

Browse files
authored
Nodelet imgtransport feature (#30)
* uas arm modifications * image_transport added in - seg faults * image_transport added in - seg faults * Removing shared pointer for image transport and removing gdb * A couple little tweaks * removing gdb * image_transport added in - seg faults * image_transport added in - seg faults * Removing shared pointer for image transport and removing gdb * A couple little tweaks * support to change target grey value and dynamic reconfigure * fixed imagetransport, changed from imagetransport:;publisher to imagetransport::camerapublisher and made caminfo to caminfoptr * image_transport added in - seg faults * image_transport added in - seg faults * Removing shared pointer for image transport and removing gdb * A couple little tweaks * image_transport added in - seg faults * image_transport added in - seg faults * Removing shared pointer for image transport and removing gdb * support to change target grey value and dynamic reconfigure * changed dynamic reconfig levels * added support for nodelets * debugging nodelets and added a tester node to measure performance * addind params * added respawn * fix CMakeList for aarch64 flag * cleaned acquisition_nodelet launch file and added nodelet_test laucnh file for the same * changed Readme on instructions to use nodelets and changed launch files for nodelets and added example for multiple nodelets * update Readme for typos * will make changes as suggested after review in pl #30, changing names of launch files, changing dynamic recfg server namespace to fix ns issue for nodelets, nodelet manager starts by default in acquisition.launch
1 parent e1ff42b commit 2945642

23 files changed

+734
-97
lines changed

CMakeLists.txt

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ find_package(catkin REQUIRED COMPONENTS
2222
cv_bridge
2323
image_transport
2424
sensor_msgs
25+
dynamic_reconfigure
26+
nodelet
2527
)
2628

2729
#find_package(PCL REQUIRED)
@@ -31,7 +33,15 @@ find_package(catkin REQUIRED COMPONENTS
3133
###
3234
# Find Packages
3335
find_package(OpenCV REQUIRED)
34-
find_package(LibUnwind REQUIRED)
36+
# use LibUnwind only for x86_64 or x86_32 architecture
37+
# do not use LibUnwind for arm architecture
38+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64 OR x86_32)
39+
message("uses LibUnwind for x86_64 or x86_32 architecture")
40+
find_package(LibUnwind REQUIRED)
41+
endif(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64 OR x86_32)
42+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES aarch64 OR arm)
43+
message("Detected ARM architecture")
44+
endif(${CMAKE_SYSTEM_PROCESSOR} MATCHES aarch64 OR arm)
3545

3646
find_package(Boost REQUIRED)
3747
if(Boost_FOUND)
@@ -46,43 +56,83 @@ add_message_files(
4656
SpinnakerImageNames.msg
4757
)
4858

49-
generate_messages(
50-
DEPENDENCIES
51-
std_msgs
52-
)
59+
generate_dynamic_reconfigure_options(
60+
cfg/spinnaker_cam.cfg
5361

54-
catkin_package(
55-
INCLUDE_DIRS include
56-
CATKIN_DEPENDS roscpp std_msgs message_runtime
57-
DEPENDS OpenCV LibUnwind
5862
)
5963

60-
include_directories(
61-
${PROJECT_INCLUDE_DIR}
62-
${catkin_INCLUDE_DIRS}
63-
${SPINNAKER_INCLUDE_DIR}
64-
${OpenCV_INCLUDE_DIRS}
65-
${Boost_INCLUDE_DIR}
66-
${LibUnwind_INCLUDE_DIRS}
64+
generate_messages(
65+
DEPENDENCIES
66+
std_msgs
6767
)
68-
69-
link_directories( ${SPINNAKER_LIB_DIR} )
70-
71-
set (LIBS ${LibUnwind_LIBRARIES} Spinnaker ${OpenCV_LIBS} ${Boost_GENERAL})
68+
## setting catkin_package, include_directories and libs based on architecture
69+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64 OR x86_32)
70+
catkin_package(
71+
INCLUDE_DIRS include
72+
CATKIN_DEPENDS roscpp std_msgs message_runtime nodelet
73+
DEPENDS OpenCV LibUnwind
74+
)
75+
76+
include_directories(
77+
${PROJECT_INCLUDE_DIR}
78+
${catkin_INCLUDE_DIRS}
79+
${SPINNAKER_INCLUDE_DIR}
80+
${OpenCV_INCLUDE_DIRS}
81+
${Boost_INCLUDE_DIR}
82+
${LibUnwind_INCLUDE_DIRS}
83+
)
84+
85+
link_directories( ${SPINNAKER_LIB_DIR} )
86+
87+
set (LIBS ${LibUnwind_LIBRARIES} Spinnaker ${OpenCV_LIBS} ${Boost_GENERAL})
88+
89+
endif(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64 OR x86_32)
90+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES aarch64 OR arm)
91+
catkin_package(
92+
INCLUDE_DIRS include
93+
CATKIN_DEPENDS roscpp std_msgs message_runtime nodelet
94+
DEPENDS OpenCV
95+
)
96+
97+
include_directories(
98+
${PROJECT_INCLUDE_DIR}
99+
${catkin_INCLUDE_DIRS}
100+
${SPINNAKER_INCLUDE_DIR}
101+
${OpenCV_INCLUDE_DIRS}
102+
${Boost_INCLUDE_DIR}
103+
)
104+
105+
link_directories( ${SPINNAKER_LIB_DIR} )
106+
107+
set (LIBS Spinnaker ${OpenCV_LIBS} ${Boost_GENERAL})
108+
109+
endif(${CMAKE_SYSTEM_PROCESSOR} MATCHES aarch64 OR arm)
72110

73111
add_library (acquilib SHARED
74112
src/capture.cpp
75113
src/camera.cpp
76114
)
77115

78-
add_dependencies(acquilib ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
116+
add_dependencies(acquilib ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_gencfg)
79117
target_link_libraries(acquilib ${LIBS} ${catkin_LIBRARIES})
80118

119+
add_library(capture_nodelet src/capture_nodelet.cpp src/subscriber_nodelet.cpp)
120+
target_link_libraries(capture_nodelet acquilib ${catkin_LIBRARIES})
121+
81122
add_executable (acquisition_node src/acquisition_node.cpp)
82-
add_dependencies(acquisition_node acquilib ${catkin_EXPORTED_TARGETS})
123+
add_dependencies(acquisition_node acquilib ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_gencfg)
83124
target_link_libraries (acquisition_node acquilib ${LIBS} ${catkin_LIBRARIES})
84125

85-
install(TARGETS acquilib acquisition_node
126+
127+
add_executable (acquisition_nodelet src/acquisition_nodelet.cpp)
128+
add_dependencies(acquisition_nodelet acquilib capture_nodelet ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_gencfg)
129+
target_link_libraries (acquisition_nodelet acquilib capture_nodelet ${LIBS} ${catkin_LIBRARIES})
130+
131+
add_executable (nodelet_test src/nodelet_test.cpp)
132+
add_dependencies(nodelet_test ${catkin_EXPORTED_TARGETS})
133+
target_link_libraries (nodelet_test capture_nodelet ${LIBS} ${catkin_LIBRARIES})
134+
135+
install(TARGETS acquilib acquisition_node capture_nodelet acquisition_nodelet nodelet_test
86136
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
87137
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
88138
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}

README.md

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# spinnaker_camera_driver
1+
# spinnaker_sdk_camera_driver
22

33
These are the ros drivers for running the Pt Grey (FLIR) cameras that use the Spinnaker SDK. This code has been tested with various Point Grey Blackfly S (BFS) cameras.
44

@@ -13,6 +13,8 @@ The pre-requisites for this repo include:
1313
* spinnaker (download from [Pt Grey's website](https://www.ptgrey.com/support/downloads))
1414
* ros-kinetic-cv-bridge
1515
* ros-kinetic-image-transport
16+
17+
# Incase of x86_64 or x86_32 architecture, install the following:
1618
* libunwind-dev
1719

1820
```bash
@@ -21,6 +23,11 @@ The pre-requisites for this repo include:
2123
# after installing ros, install other pre-requisites with:
2224

2325
sudo apt install libunwind-dev ros-kinetic-cv-bridge ros-kinetic-image-transport
26+
27+
# if you use arm64 (aarch64), install pre-requisites with:
28+
29+
sudo apt install ros-kinetic-cv-bridge ros-kinetic-image-transport
30+
2431
```
2532

2633
### Installing
@@ -39,7 +46,13 @@ source ~/spinnaker_ws/devel/setup.bash
3946

4047
Modify the `params/test_params.yaml` file replacing the cam-ids and master cam serial number to match your camera's serial number. Then run the code as:
4148
```bash
42-
roslaunch spinnaker_sdk_camera_driver acquisition.launch
49+
# To launch nodelet verison of driver, use #
50+
51+
roslaunch spinnaker_camera_driver acquisition_nodelet.launch
52+
53+
# To launch node version of driver, use
54+
55+
roslaunch spinnaker_camera_driver acquisition.launch
4356
# Test that the images are being published by running
4457
rqt_image_view
4558
```
@@ -51,8 +64,8 @@ All the parameters can be set via the launch file or via the yaml config_file.
5164
Binning for cameras, when changing from 2 to 1 cameras need to be unplugged and replugged
5265
* ~color (bool, default: false)
5366
Should color images be used (only works on models that support color images)
54-
* ~exp (int, default: 0)
55-
Exposure setting for cameras
67+
* ~exposure_time (int, default: 0, 0:auto)
68+
Exposure setting for cameras, also available as dynamic reconfiguarble parameter.
5669
* ~frames (int, default: 50)
5770
Number of frames to save/view 0=ON
5871
* ~live (bool, default: false)
@@ -74,7 +87,7 @@ All the parameters can be set via the launch file or via the yaml config_file.
7487
* ~utstamps (bool, default:false)
7588
Flag whether each image should have Unique timestamps vs the master cams time stamp for all
7689
* ~max_rate_save (bool, default: false)
77-
Flag for max rate mode which is when the master triggers the slaves and saves images at maximum rate possible. This is the multithreaded mode"
90+
Flag for max rate mode which is when the master triggers the slaves and saves images at maximum rate possible. This is the multithreaded mode
7891

7992
### System configuration parameters
8093
* ~cam_ids (yaml sequence or array)
@@ -86,7 +99,27 @@ This is the names that would be given to the cameras for filenames and rostopics
8699
* ~skip (int)
87100
Number of frames to be skipped initially to flush the buffer
88101
* ~delay (float)
89-
Secs to wait in the deinit/init sequence
102+
Secs to wait in the deinit/init sequence.
103+
104+
105+
### Dynamic Reconfigure parameters
106+
* ~target_grey_val (double)
107+
Target Grey Value is a parameter that helps to compensate for various lighting conditions by adjusting brightness to achieve optimal imaging results. The value is linear and is a percentage of the maximum pixel value.
108+
Explained in detail at [FLIR webpage](https://www.flir.com/support-center/iis/machine-vision/application-note/using-auto-exposure-in-blackfly-s/).
109+
110+
Setting target_grey_val invokes setting AutoExposureTargetGreyValueAuto to 'off' and AutoExposureTargetGreyValue is set to target_grey_val.
111+
* ~exposure_time (int, default= 0, 0:auto)
112+
Exposure time for the sensor.
113+
When Exposure time is set within minimum and maximum exposure time limits(varies with camera model), ExposureAuto is set to 'off' and ExposureTime is set to exposure_time param value.
114+
115+
When exposure_time is set to 0(zero), the ExposureAuto is set to 'Continuous', enabling auto exposure.
116+
117+
### nodelet details
118+
* ~nodelet_manager_name (string, default: vision_nodelet_manager)
119+
Specify the name of the nodelet_manager under which nodelet to be launched.
120+
* ~start_nodelet_manager (bool, default: false)
121+
If set True, nodelet_manager of name $(arg nodelet_manager_name) will be launched.
122+
If set False(default), the acquisition/capture_nodelet waits for the nodelet_manager name $(arg nodelet_manager_name).
90123

91124
### Camera info message details
92125
* ~image_width (int)
@@ -100,9 +133,11 @@ This is the names that would be given to the cameras for filenames and rostopics
100133
Specified as [fx 0 cx 0 fy cy 0 0 1]
101134
* ~projection_coeffs (array of arrays)
102135
Projection coefficients of all the cameras in the array. Must match the number of cam_ids provided.
136+
For case of Monocular camera, if projection_coeffs is not set, intrinsic_coeff will be used to set, P[1:3,1:3]=K
103137
* ~rectification_coeffs (array of arrays)
104138
Rectification coefficients of all the cameras in the array. Must match the number of cam_ids provided.
105139

140+
106141
## Multicamera Master-Slave Setup
107142
When using multiple cameras, we have found that the only way to keep images between different cameras synched is by using a master-slave setup using the GPIO connector. So this is the only way we support multicamera operation with this code. A general guide for multi camera setup is available at https://www.ptgrey.com/tan/11052, however note that we use a slightly different setup with our package.
108143
Refer to the `params/multi-cam_example.yaml` for an example on how to setup the configuration. You must specify a master_cam which must be one of the cameras in the cam_ids list. This master camera is the camera that is either explicitly software triggered by the code or triggered internally via a counter at a given frame rate. All the other cameras are triggered externally when the master camera triggers. In order to make this work, the wiring must be such that the external signal from the master camera **Line2** is connected to **Line3** on all slave cameras. To connect cameras in this way:

cfg/spinnaker_cam.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
PACKAGE = "spinnaker_sdk_camera_driver"
3+
4+
from dynamic_reconfigure.parameter_generator_catkin import *
5+
6+
gen = ParameterGenerator()
7+
8+
9+
gen.add("target_grey_val", double_t, 1, "Set Target Grey Value", 50, 4, 90)
10+
gen.add("exposure_time", int_t, 2, "Set Exposure time (0:auto)", 0, 0, 15000)
11+
12+
13+
exit(gen.generate(PACKAGE, "spinnaker_sdk_camera_driver", "spinnaker_cam"))

include/spinnaker_sdk_camera_driver/camera.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ namespace acquisition {
4545
void setResolutionPixels(int width, int height);
4646
void setBufferSize(int numBuf);
4747
void adcBitDepth(gcstring bitDep);
48+
void targetGreyValueTest();
4849

4950
// void set_acquisition_mode_continuous();
5051
// void set_frame_rate(float);

include/spinnaker_sdk_camera_driver/capture.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77

88
#include <boost/archive/binary_oarchive.hpp>
99
#include <boost/filesystem.hpp>
10-
10+
//ROS
11+
#include "std_msgs/Float64.h"
1112
#include "std_msgs/String.h"
13+
//Dynamic reconfigure
14+
#include <dynamic_reconfigure/server.h>
15+
#include <spinnaker_sdk_camera_driver/spinnaker_camConfig.h>
16+
1217
#include "spinnaker_sdk_camera_driver/SpinnakerImageNames.h"
1318

1419
#include <sstream>
20+
#include <image_transport/image_transport.h>
1521

1622
using namespace Spinnaker;
1723
using namespace Spinnaker::GenApi;
@@ -27,6 +33,7 @@ namespace acquisition {
2733

2834
~Capture();
2935
Capture();
36+
Capture( ros::NodeHandle node,ros::NodeHandle private_nh);
3037

3138
void load_cameras();
3239

@@ -58,6 +65,7 @@ namespace acquisition {
5865
void get_mat_images();
5966
void update_grid();
6067
void export_to_ROS();
68+
void dynamicReconfigureCallback(spinnaker_sdk_camera_driver::spinnaker_camConfig &config, uint32_t level);
6169

6270
float mem_usage();
6371

@@ -123,13 +131,18 @@ namespace acquisition {
123131
// ros variables
124132
ros::NodeHandle nh_;
125133
ros::NodeHandle nh_pvt_;
134+
//image_transport::ImageTransport it_;
135+
image_transport::ImageTransport it_;
136+
dynamic_reconfigure::Server<spinnaker_sdk_camera_driver::spinnaker_camConfig>* dynamicReCfgServer_;
126137

127138
ros::Publisher acquisition_pub;
128-
vector<ros::Publisher> camera_image_pubs;
129-
vector<ros::Publisher> camera_info_pubs;
139+
//vector<ros::Publisher> camera_image_pubs;
140+
vector<image_transport::CameraPublisher> camera_image_pubs;
141+
//vector<ros::Publisher> camera_info_pubs;
142+
130143

131144
vector<sensor_msgs::ImagePtr> img_msgs;
132-
vector<sensor_msgs::CameraInfo> cam_info_msgs;
145+
vector<sensor_msgs::CameraInfoPtr> cam_info_msgs;
133146
spinnaker_sdk_camera_driver::SpinnakerImageNames mesg;
134147
boost::mutex queue_mutex_;
135148
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Created by pushyami on 1/10/19.
3+
//
4+
5+
#ifndef SPINNAKER_SDK_CAMERA_DRIVER_CAPTURE_NODELET_H
6+
#define SPINNAKER_SDK_CAMERA_DRIVER_CAPTURE_NODELET_H
7+
8+
#endif //SPINNAKER_SDK_CAMERA_DRIVER_CAPTURE_NODELET_H
9+
10+
#include <nodelet/nodelet.h>
11+
#include "capture.h"
12+
namespace acquisition {
13+
class capture_nodelet: public nodelet::Nodelet
14+
{
15+
16+
public:
17+
capture_nodelet(){}
18+
~capture_nodelet(){
19+
if (pubThread_) {
20+
pubThread_->interrupt();
21+
pubThread_->join();
22+
}
23+
}
24+
virtual void onInit();
25+
26+
boost::shared_ptr<Capture> inst_;
27+
std::shared_ptr<boost::thread> pubThread_;
28+
29+
};
30+
31+
}
32+

include/spinnaker_sdk_camera_driver/std_include.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include <cv_bridge/cv_bridge.h>
1616
#include "sensor_msgs/Image.h"
1717
#include "sensor_msgs/CameraInfo.h"
18+
#include "std_msgs/String.h"
19+
#include <image_transport/image_transport.h>
20+
#include "sensor_msgs/Image.h"
1821

1922

2023
// Standard Libs
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Created by pushyami on 1/15/19.
3+
//
4+
5+
#ifndef SPINNAKER_SDK_CAMERA_DRIVER_SUBSCRIBER_NODELET_H
6+
#define SPINNAKER_SDK_CAMERA_DRIVER_SUBSCRIBER_NODELET_H
7+
8+
#endif //SPINNAKER_SDK_CAMERA_DRIVER_SUBSCRIBER_NODELET_H
9+
#include "spinnaker_sdk_camera_driver/std_include.h"
10+
#include <nodelet/nodelet.h>
11+
#include "capture.h"
12+
namespace acquisition {
13+
class subscriber_nodelet: public nodelet::Nodelet
14+
{
15+
16+
public:
17+
subscriber_nodelet(){}
18+
~subscriber_nodelet(){}
19+
virtual void onInit();
20+
void chatterCallback(const sensor_msgs::Image::ConstPtr& msg);
21+
std::shared_ptr<image_transport::ImageTransport> it_;
22+
image_transport::Subscriber image_sub_;
23+
24+
};
25+
26+
}

0 commit comments

Comments
 (0)