Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test node that accepts device' serial number as ROS Param and publishes. #7

Open
wants to merge 1 commit into
base: por_indigo
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ target_link_libraries(openni2_wrapper ${catkin_LIBRARIES} ${PC_OPENNI2_LIBRARIES
add_executable(test_wrapper test/test_wrapper.cpp )
target_link_libraries(test_wrapper openni2_wrapper ${Boost_LIBRARIES})

add_executable(camera_serial_faker test/camera_serial_faker.cpp)
target_link_libraries(camera_serial_faker ${catkin_LIBRARIES} ${PC_OPENNI2_LIBRARIES})
Copy link

@geoffreychiou geoffreychiou Jul 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need the add_dependencies for the services to generate before building this. At a glance the CI looks like it can't find the service header.

Errors     << openni2_camera:make /root/catkin_ws/logs/openni2_camera/build.make.000.log
/root/catkin_ws/src/openni2_camera/test/camera_serial_faker.cpp:31:38: fatal error: openni2_camera/GetSerial.h: No such file or directory
 #include <openni2_camera/GetSerial.h>
                                      ^
compilation terminated.
make[2]: *** [CMakeFiles/camera_serial_faker.dir/test/camera_serial_faker.cpp.o] Error 1
make[1]: *** [CMakeFiles/camera_serial_faker.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2

Edit: Sorry, looks like I forgot to click submit.


add_library(openni2_driver_lib
src/openni2_driver.cpp
)
Expand Down Expand Up @@ -75,7 +78,7 @@ if (UNIX AND NOT APPLE)
set(ADDITIONAL_EXECUTABLES "usb_reset")
endif()

install(TARGETS openni2_wrapper openni2_camera_nodelet openni2_camera_node list_devices openni2_driver_lib ${ADDITIONAL_EXECUTABLES}
install(TARGETS openni2_wrapper openni2_camera_nodelet openni2_camera_node list_devices openni2_driver_lib camera_serial_faker ${ADDITIONAL_EXECUTABLES}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
Expand Down
74 changes: 74 additions & 0 deletions test/camera_serial_faker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2018, PlusOne Robotics
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Plus One Robotics, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/

#include <openni2_camera/GetSerial.h>
#include <ros/ros.h>

class CameraSerialFaker
{
public:
CameraSerialFaker(const ros::NodeHandle &nh, const ros::NodeHandle &pnh)
: nh_(nh), pnh_(pnh)
{
// Get serial number from parameter server
if (pnh_.getParam("serial", serial_) && !serial_.empty())
{
get_serial_service_ = nh_.advertiseService("get_serial", &CameraSerialFaker::getSerial, this);
}
}

~CameraSerialFaker() { }

bool getSerial(openni2_camera::GetSerial::Request &request,
openni2_camera::GetSerial::Response &response)
{
response.serial = serial_;
return true;
}

private:
ros::NodeHandle nh_;
ros::NodeHandle pnh_;
ros::ServiceServer get_serial_service_;
std::string serial_;
};

int main(int argc, char** argv)
{
ros::init(argc, argv, "camera_serial_faker");

ros::NodeHandle nh;
ros::NodeHandle pnh("~");

CameraSerialFaker serial_faker(nh, pnh);
ros::spin();

return 0;
}