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

Services, example #1

Merged
merged 9 commits into from
Mar 27, 2016
Merged
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
44 changes: 28 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,23 @@ find_package(catkin REQUIRED COMPONENTS
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )
add_message_files(
FILES
PhoXiSize.msg
)

## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )
add_service_files(
FILES
GetDeviceList.srv
ConnectCamera.srv
IsAcquiring.srv
GetFrame.srv
TriggerImage.srv
GetHardwareIdentification.srv
GetSupportedCapturingModes.srv
IsConnected.srv
)

## Generate actions in the 'action' folder
# add_action_files(
Expand All @@ -71,10 +76,10 @@ find_package(catkin REQUIRED COMPONENTS
# )

## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# sensor_msgs# std_msgs
# )
generate_messages(
DEPENDENCIES
sensor_msgs std_msgs
)

################################################
## Declare ROS dynamic reconfigure parameters ##
Expand Down Expand Up @@ -111,7 +116,8 @@ generate_dynamic_reconfigure_options(
## DEPENDS: system dependencies of this project that dependent projects also need

catkin_package(
# INCLUDE_DIRS include
CATKIN_DEPENDS message_runtime std_msgs sensor_msgs
# INCLUDE_DIRS include
# LIBRARIES pho_driver
# CATKIN_DEPENDS dynamic_reconfigure pcl_ros roscpp roslib rospy sensor_msgs std_msgs tf
# DEPENDS system_lib
Expand Down Expand Up @@ -178,6 +184,7 @@ add_dependencies(phoxi_camera_node ${PROJECT_NAME}_gencfg)
# ${catkin_LIBRARIES}
# )

#message(${PHOXI_LIBRARY})
target_link_libraries(phoxi_camera_node
debug ${catkin_LIBRARIES}
optimized ${catkin_LIBRARIES}
Expand Down Expand Up @@ -235,7 +242,12 @@ target_link_libraries(phoxi_camera_node
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
#add dynamic reconfigure api
#find_package(catkin REQUIRED dynamic_reconfigure)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)



Expand Down
39 changes: 28 additions & 11 deletions cfg/phoxi_camera.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,34 @@ from dynamic_reconfigure.parameter_generator_catkin import *

gen = ParameterGenerator()

gen.add("int_param", int_t, 0, "An Integer parameter", 50, 0, 100)
gen.add("double_param", double_t, 0, "A double parameter", .5, 0, 1)
gen.add("str_param", str_t, 0, "A string parameter", "Hello World")
gen.add("bool_param", bool_t, 0, "A Boolean parameter", True)
gen.add("size_width", int_t, 1 << 1, "An Integer parameter", 1920, 0)
gen.add("size_height", int_t, 1 << 2, "An Integer parameter", 1080, 0)
gen.add("capturing_size_width", int_t, 1 << 3, "An Integer parameter", 1920, 0)
gen.add("capturing_size_height", int_t, 1 << 4, "An Integer parameter", 1080, 0)
gen.add("capturing_scan_multiplier", int_t, 1 << 5, "An Integer parameter", 1)
gen.add("acquisition_time", double_t, 1 << 6, "A double parameter", 1.0, 0.0)

size_enum = gen.enum([ gen.const("Small", int_t, 0, "A small constant"),
gen.const("Medium", int_t, 1, "A medium constant"),
gen.const("Large", int_t, 2, "A large constant"),
gen.const("ExtraLarge", int_t, 3, "An extra large constant")],
"An enum to set size")
trigger_enum = gen.enum([gen.const("Freerun", int_t, 0, "A small constant"),
gen.const("Software", int_t, 1, "A medium constant"),
gen.const("hardware", int_t, 2, "A large constant"),
gen.const("NoValue", int_t, 3, "An extra large constant")],
"An enum to set size")

gen.add("size", int_t, 0, "A size parameter which is edited via an enum", 1, 0, 3, edit_method=size_enum)
gen.add("trigger_mode", int_t, 1 << 7, "A size parameter which is edited via an enum", 1, 0, 3, edit_method=trigger_enum)

exit(gen.generate(PACKAGE, "phoxi_camera", "Tutorials"))
timeout_enum = gen.enum([gen.const("ZeroTimeout", int_t, 0, "A small constant"),
gen.const("Infinity", int_t, -1, "A medium constant"),
gen.const("LastStored", int_t, -2, "A large constant"),
gen.const("Default", int_t, -3, "An extra large constant")],
"An enum to set size")

gen.add("timeout", int_t, 1 << 8, "A size parameter which is edited via an enum", -1, -3, 0, edit_method=timeout_enum)

gen.add("processing_settings", double_t, 1 << 9, "A double parameter", 1.0, 0.0)

gen.add("send_point_cloud", bool_t, 1 << 10, "A Boolean parameter", True)
gen.add("send_depth_map", bool_t, 1 << 11, "A Boolean parameter", True)
gen.add("send_confidence_map", bool_t, 1 << 12, "A Boolean parameter", True)
gen.add("send_texture", bool_t, 1 << 13, "A Boolean parameter", True)

exit(gen.generate(PACKAGE, "phoxi_camera_node", "Tutorials"))
2 changes: 2 additions & 0 deletions msg/PhoXiSize.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
int32 Width
int32 Height
6 changes: 4 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
<!-- Dependencies can be catkin packages or system dependencies -->
<!-- Examples: -->
<!-- Use build_depend for packages you need at compile time: -->
<!-- <build_depend>message_generation</build_depend> -->
<build_depend>message_generation</build_depend>
<!-- Use buildtool_depend for build tool packages: -->
<!-- <buildtool_depend>catkin</buildtool_depend> -->
<!-- Use run_depend for packages you need at runtime: -->
<!-- <run_depend>message_runtime</run_depend> -->
<run_depend>message_runtime</run_depend>
<!-- Use test_depend for packages you need only for testing: -->
<!-- <test_depend>gtest</test_depend> -->
<buildtool_depend>catkin</buildtool_depend>
Expand All @@ -47,6 +47,7 @@
<build_depend>rospy</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>std_srvs</build_depend>
<build_depend>tf</build_depend>
<run_depend>dynamic_reconfigure</run_depend>
<run_depend>pcl_ros</run_depend>
Expand All @@ -55,6 +56,7 @@
<run_depend>rospy</run_depend>
<run_depend>sensor_msgs</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>std_srvs</run_depend>
<run_depend>tf</run_depend>


Expand Down
27 changes: 27 additions & 0 deletions src/phoxi_camera_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
import rospy
from phoxi_camera.srv import *
from std_srvs.srv import *

if __name__ == "__main__":
rospy.init_node('phoxi_camera_example', anonymous=True)
while not rospy.is_shutdown():
rospy.wait_for_service('phoxi_camera/get_device_list')
try:
get_device_list = rospy.ServiceProxy('phoxi_camera/get_device_list', GetDeviceList)
resp1 = get_device_list()
print "devices", resp1.out
name = "noConnectedCamera-03"
res_connect = rospy.ServiceProxy('phoxi_camera/connect_camera', ConnectCamera)(name)
print "connect to", name, res_connect
if res_connect.success:
res_star_acq = rospy.ServiceProxy('phoxi_camera/start_acquisition', Empty)()
res_trig = rospy.ServiceProxy('phoxi_camera/trigger_image', TriggerImage)()
res_get_fram = rospy.ServiceProxy('phoxi_camera/get_frame', GetFrame)(-1)
print "get_frame", res_get_fram
else:
print "cant connect"
except rospy.ServiceException, e:
print "Service call failed: %s" % e
res_dis = rospy.ServiceProxy('phoxi_camera/disconnect_camera', Empty)()
print "disconnect"
Loading