diff --git a/dmx_driver/CMakeLists.txt b/dmx_driver/CMakeLists.txt index d1d20f1..7e1c739 100644 --- a/dmx_driver/CMakeLists.txt +++ b/dmx_driver/CMakeLists.txt @@ -1,9 +1,6 @@ cmake_minimum_required(VERSION 2.8.3) project(dmx_driver) -# Disable message generation for lisp and java -set(ENV{ROS_LANG_DISABLE} "genlisp:genjava") - ## Compile as C++11, supported in ROS Kinetic and newer # add_compile_options(-std=c++11) @@ -11,8 +8,6 @@ set(ENV{ROS_LANG_DISABLE} "genlisp:genjava") ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) ## is used, also find other catkin packages find_package(catkin REQUIRED COMPONENTS - std_msgs - message_generation ) ## System dependencies are found with CMake's conventions @@ -48,31 +43,6 @@ find_package(catkin REQUIRED COMPONENTS ## * uncomment the generate_messages entry below ## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) -## Generate messages in the 'msg' folder -add_message_files( - FILES - DmxFrame.msg - ) - -## Generate services in the 'srv' folder -add_service_files( - FILES - SetChannel.srv -) - -## Generate actions in the 'action' folder -# add_action_files( -# FILES -# Action1.action -# Action2.action -# ) - -## Generate added messages and services with any dependencies listed here -generate_messages( - DEPENDENCIES - std_msgs -) - ################################################ ## Declare ROS dynamic reconfigure parameters ## ################################################ @@ -143,7 +113,7 @@ include_directories( ## Add cmake target dependencies of the executable ## same as for the library above -# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) +# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) ## Specify libraries to link a library or executable target against # target_link_libraries(${PROJECT_NAME}_node diff --git a/dmx_driver/package.xml b/dmx_driver/package.xml index 8298def..3d85b58 100644 --- a/dmx_driver/package.xml +++ b/dmx_driver/package.xml @@ -7,7 +7,7 @@ - ernesto + Ernesto Corbellini @@ -37,6 +37,7 @@ message_runtime + dmx_msgs catkin diff --git a/dmx_driver/src/driver.py b/dmx_driver/src/driver.py index ebacc69..6ed3dc0 100755 --- a/dmx_driver/src/driver.py +++ b/dmx_driver/src/driver.py @@ -5,14 +5,13 @@ import fcntl import time import rospy -from dmx_driver.srv import SetChannel, SetChannelResponse +from dmx_driver.msg import DmxFrame class DmxDriver(object): def __init__(self, com_port="/dev/ttyUSB0"): self.rate = rospy.Rate(50) - self.dmx_frame = [0] * 512 self.BAUD_RATE = 250000 try: self.serial_device = serial.Serial(com_port, baudrate=self.BAUD_RATE, stopbits=serial.STOPBITS_TWO) @@ -20,45 +19,16 @@ def __init__(self, com_port="/dev/ttyUSB0"): rospy.logerr(str(e)) self.TIOCSBRK = getattr(termios, 'TIOCSBRK', 0x5427) self.TIOCCBRK = getattr(termios, 'TIOCCBRK', 0x5428) - self.services = [ - rospy.Service("set_channel", SetChannel, self.set_channel_srv_cb) - ] + self.dmx_frame_subscriber = rospy.Subscriber('/dmx_frame', DmxFrame, self.cb_dmx_frame, queue_size=10) def __del__(self): self.serial_device.close() def run(self): while not rospy.is_shutdown(): - self.send_frame() self.rate.sleep() - def set_channel_srv_cb(self, req): - self.set_channel(req.channel, req.value) - return SetChannelResponse() - - def set_channel(self, channel, value): - """ - Set a channel to a specific value. - :param channel: A channel value in the range [1; 512] - :param value: A value in the range [0; 255] - :return: None - """ - channel -= 1 - if channel > 511: - channel = 511 - elif channel < 0: - channel = 0 - self.dmx_frame[channel] = value - - def zero_dmx_frame(self): - """ - Put all channels of the DMX frame to zero. - :return: None - """ - for i in range(512): - self.dmx_frame[i] = 0 - - def send_frame(self): + def send_frame(self, frame): """ Send a DMX frame. :return: None @@ -66,8 +36,8 @@ def send_frame(self): # Convert frame to string # Channel 0 is the break condition serial_data = chr(0) - for i in self.dmx_frame: - serial_data += chr(i) + for i in frame: + serial_data += i # Manually emulate the serial break condition fcntl.ioctl(self.serial_device.fd, self.TIOCSBRK) time.sleep(100 / 1e6) @@ -75,30 +45,12 @@ def send_frame(self): time.sleep(100 / 1e6) self.serial_device.write(serial_data) + def cb_dmx_frame(self, data): + # type: (DmxFrame) -> None + self.send_frame(data.frame) + if __name__ == '__main__': rospy.init_node("dmx_driver") node = DmxDriver() node.run() - """ - a = 0 - s = 1 - #for i in range(10): - while 1: - dmx.set_channel(1, 128) - dmx.send_frame() - time.sleep(0.02) - time.sleep(60) - while 1: - a += s - if a > 255: - a = 255 - s = -s - if a < 0: - a = 0 - s = -s - dmx.set_channel(1, a) - dmx.set_channel(3, a) - dmx.send_frame() - time.sleep(0.02) - """ \ No newline at end of file diff --git a/dmx_msgs/CMakeLists.txt b/dmx_msgs/CMakeLists.txt new file mode 100644 index 0000000..a565860 --- /dev/null +++ b/dmx_msgs/CMakeLists.txt @@ -0,0 +1,199 @@ +cmake_minimum_required(VERSION 2.8.3) +project(dmx_msgs) + +# Disable message generation for lisp and java +set(ENV{ROS_LANG_DISABLE} "genlisp:genjava") + +## Compile as C++11, supported in ROS Kinetic and newer +# add_compile_options(-std=c++11) + +## Find catkin macros and libraries +## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) +## is used, also find other catkin packages +find_package(catkin REQUIRED COMPONENTS + std_msgs + message_generation +) + +## System dependencies are found with CMake's conventions +# find_package(Boost REQUIRED COMPONENTS system) + + +## Uncomment this if the package has a setup.py. This macro ensures +## modules and global scripts declared therein get installed +## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html +# catkin_python_setup() + +################################################ +## Declare ROS messages, services and actions ## +################################################ + +## To declare and build messages, services or actions from within this +## package, follow these steps: +## * Let MSG_DEP_SET be the set of packages whose message types you use in +## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). +## * In the file package.xml: +## * add a build_depend tag for "message_generation" +## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependency has been pulled in +## but can be declared for certainty nonetheless: +## * add a run_depend tag for "message_runtime" +## * In this file (CMakeLists.txt): +## * add "message_generation" and every package in MSG_DEP_SET to +## find_package(catkin REQUIRED COMPONENTS ...) +## * add "message_runtime" and every package in MSG_DEP_SET to +## catkin_package(CATKIN_DEPENDS ...) +## * uncomment the add_*_files sections below as needed +## and list every .msg/.srv/.action file to be processed +## * uncomment the generate_messages entry below +## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) + +## Generate messages in the 'msg' folder +add_message_files( + FILES + DmxFrame.msg + ) + +## Generate services in the 'srv' folder +add_service_files( + FILES + SetChannel.srv +) + +## Generate actions in the 'action' folder +# add_action_files( +# FILES +# Action1.action +# Action2.action +# ) + +## Generate added messages and services with any dependencies listed here +generate_messages( + DEPENDENCIES + std_msgs +) + +################################################ +## Declare ROS dynamic reconfigure parameters ## +################################################ + +## To declare and build dynamic reconfigure parameters within this +## package, follow these steps: +## * In the file package.xml: +## * add a build_depend and a run_depend tag for "dynamic_reconfigure" +## * In this file (CMakeLists.txt): +## * add "dynamic_reconfigure" to +## find_package(catkin REQUIRED COMPONENTS ...) +## * uncomment the "generate_dynamic_reconfigure_options" section below +## and list every .cfg file to be processed + +## Generate dynamic reconfigure parameters in the 'cfg' folder +# generate_dynamic_reconfigure_options( +# cfg/DynReconf1.cfg +# cfg/DynReconf2.cfg +# ) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +## INCLUDE_DIRS: uncomment this if you package contains header files +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +catkin_package( +# INCLUDE_DIRS include +# LIBRARIES dmx_driver +# CATKIN_DEPENDS other_catkin_pkg +# DEPENDS system_lib +) + +########### +## Build ## +########### + +## Specify additional locations of header files +## Your package locations should be listed before other locations +include_directories( +# include +# ${catkin_INCLUDE_DIRS} +) + +## Declare a C++ library +# add_library(${PROJECT_NAME} +# src/${PROJECT_NAME}/dmx_driver.cpp +# ) + +## Add cmake target dependencies of the library +## as an example, code may need to be generated before libraries +## either from message generation or dynamic reconfigure +# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Declare a C++ executable +## With catkin_make all packages are built within a single CMake context +## The recommended prefix ensures that target names across packages don't collide +# add_executable(${PROJECT_NAME}_node src/dmx_driver_node.cpp) + +## Rename C++ executable without prefix +## The above recommended prefix causes long target names, the following renames the +## target back to the shorter version for ease of user use +## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node" +# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "") + +## Add cmake target dependencies of the executable +## same as for the library above +# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Specify libraries to link a library or executable target against +# target_link_libraries(${PROJECT_NAME}_node +# ${catkin_LIBRARIES} +# ) + +############# +## Install ## +############# + +# all install targets should use catkin DESTINATION variables +# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html + +## Mark executable scripts (Python etc.) for installation +## in contrast to setup.py, you can choose the destination +install(PROGRAMS + src/driver.py + DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +) + +## Mark executables and/or libraries for installation +# install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_node +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark cpp header files for installation +# install(DIRECTORY include/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +# FILES_MATCHING PATTERN "*.h" +# PATTERN ".svn" EXCLUDE +# ) + +## Mark other files for installation (e.g. launch and bag files, etc.) +# install(FILES +# # myfile1 +# # myfile2 +# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +# ) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# catkin_add_gtest(${PROJECT_NAME}-test test/test_dmx_driver.cpp) +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) diff --git a/dmx_driver/msg/DmxFrame.msg b/dmx_msgs/msg/DmxFrame.msg similarity index 100% rename from dmx_driver/msg/DmxFrame.msg rename to dmx_msgs/msg/DmxFrame.msg diff --git a/dmx_msgs/package.xml b/dmx_msgs/package.xml new file mode 100644 index 0000000..1b5da89 --- /dev/null +++ b/dmx_msgs/package.xml @@ -0,0 +1,50 @@ + + + dmx_msgs + 0.0.0 + DMX messages and services. + + + + + Ernesto Corbellini + + + + + + TODO + + + + + + + + + + + + + + + + + + + message_generation + + + + message_runtime + + + catkin + + + + + + + + diff --git a/dmx_driver/srv/SetChannel.srv b/dmx_msgs/srv/SetChannel.srv similarity index 100% rename from dmx_driver/srv/SetChannel.srv rename to dmx_msgs/srv/SetChannel.srv diff --git a/optical_tracker/CMakeLists.txt b/optical_tracker/CMakeLists.txt index e1dcc88..4121574 100644 --- a/optical_tracker/CMakeLists.txt +++ b/optical_tracker/CMakeLists.txt @@ -11,6 +11,7 @@ set(ENV{ROS_LANG_DISABLE} "genlisp:genjava") ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) ## is used, also find other catkin packages find_package(catkin REQUIRED COMPONENTS + dmx_msgs dmx_driver ) diff --git a/optical_tracker/launch/blob_tracker.launch b/optical_tracker/launch/blob_tracker.launch index f04b599..ef21d61 100644 --- a/optical_tracker/launch/blob_tracker.launch +++ b/optical_tracker/launch/blob_tracker.launch @@ -1,6 +1,7 @@ + diff --git a/optical_tracker/package.xml b/optical_tracker/package.xml index b314a30..c8706ed 100644 --- a/optical_tracker/package.xml +++ b/optical_tracker/package.xml @@ -4,7 +4,7 @@ 0.0.0 Optical blob tracker - ernesto + Ernesto Corbellini @@ -17,6 +17,7 @@ geometry_msgs cv2 numpy + dmx_msgs dmx_driver catkin