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

Creation of enabled_callback service #62

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
20 changes: 18 additions & 2 deletions libuvc_camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@
cmake_minimum_required(VERSION 2.8.3)
project(libuvc_camera)
# Load catkin and all dependencies required for this package
find_package(catkin REQUIRED COMPONENTS roscpp camera_info_manager dynamic_reconfigure image_transport nodelet sensor_msgs)
find_package(catkin REQUIRED COMPONENTS
roscpp
camera_info_manager
dynamic_reconfigure
image_transport
nodelet
sensor_msgs
std_msgs
std_srvs
message_generation)

generate_dynamic_reconfigure_options(cfg/UVCCamera.cfg)

find_package(libuvc REQUIRED)
find_package(libuvc REQUIRED COMPONENTS)

message(STATUS "libuvc ${libuvc_VERSION_MAJOR}.${libuvc_VERSION_MINOR}.${libuvc_VERSION_PATCH}")

generate_messages(
DEPENDENCIES
std_msgs
std_srvs
)

catkin_package(
CATKIN_DEPENDS
roscpp
Expand Down
5 changes: 5 additions & 0 deletions libuvc_camera/include/libuvc_camera/camera_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <dynamic_reconfigure/server.h>
#include <camera_info_manager/camera_info_manager.h>
#include <boost/thread/mutex.hpp>
#include <std_srvs/SetBool.h>

#include <libuvc_camera/UVCCameraConfig.h>

Expand All @@ -21,6 +22,10 @@ class CameraDriver {
bool Start();
void Stop();

ros::ServiceServer enableCamera;

bool enabled_callback(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res);

private:
enum State {
kInitial = 0,
Expand Down
4 changes: 4 additions & 0 deletions libuvc_camera/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,28 @@
<!-- Use build_depend for packages you need at compile time: -->
<!-- <build_depend>message_generation</build_depend> -->
<build_depend>roscpp</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>camera_info_manager</build_depend>
<build_depend>dynamic_reconfigure</build_depend>
<build_depend>image_transport</build_depend>
<build_depend>libuvc</build_depend>
<build_depend>nodelet</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>std_srvs</build_depend>
<!-- Use buildtool_depend for build tool packages: -->
<!-- <buildtool_depend>catkin</buildtool_depend> -->
<buildtool_depend>catkin</buildtool_depend>
<!-- Use run_depend for packages you need at runtime: -->
<!-- <run_depend>message_runtime</run_depend> -->
<run_depend>roscpp</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>camera_info_manager</run_depend>
<run_depend>dynamic_reconfigure</run_depend>
<run_depend>image_transport</run_depend>
<run_depend>libuvc</run_depend>
<run_depend>nodelet</run_depend>
<run_depend>sensor_msgs</run_depend>
<run_depend>std_srvs</run_depend>
<!-- Use test_depend for packages you need only for testing: -->
<!-- <test_depend>gtest</test_depend> -->

Expand Down
14 changes: 14 additions & 0 deletions libuvc_camera/src/camera_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ CameraDriver::CameraDriver(ros::NodeHandle nh, ros::NodeHandle priv_nh)
config_server_(mutex_, priv_nh_),
config_changed_(false),
cinfo_manager_(nh) {
enableCamera = nh.advertiseService("/camera_bottom_front_driver/enabled", &CameraDriver::enabled_callback, this);
cam_pub_ = it_.advertiseCamera("image_raw", 1, false);
}

Expand Down Expand Up @@ -99,6 +100,19 @@ void CameraDriver::Stop() {
state_ = kInitial;
}

bool CameraDriver::enabled_callback(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res) {
if((state_ == kRunning) && (req.data == false)) {
Stop();
res.message = "Camera stopped";
} else if ((state_ == kInitial) && (req.data == true)) {
Start();
res.message = "Camera started";
}
res.success = true;
return true;

}

void CameraDriver::ReconfigureCallback(UVCCameraConfig &new_config, uint32_t level) {
boost::recursive_mutex::scoped_lock lock(mutex_);

Expand Down
1 change: 1 addition & 0 deletions libuvc_camera/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ int main (int argc, char **argv) {
if (!driver.Start())
return -1;

//We do not start the driver right away
ros::spin();

driver.Stop();
Expand Down
12 changes: 6 additions & 6 deletions libuvc_camera/src/nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ void CameraNodelet::onInit() {
ros::NodeHandle priv_nh(getPrivateNodeHandle());

driver_.reset(new CameraDriver(nh, priv_nh));
if (driver_->Start()) {
running_ = true;
} else {
NODELET_ERROR("Unable to open camera.");
driver_.reset();
}
// if (driver_->Start()) {
// running_ = true;
// } else {
// NODELET_ERROR("Unable to open camera.");
// driver_.reset();
// }
}

};
Expand Down