Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 987c969

Browse files
author
Kai Franke
committed
add support for dynamic_reconfigure
1 parent a6bd943 commit 987c969

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ find_package(catkin REQUIRED
99
rospy
1010
sensor_msgs
1111
tf
12+
dynamic_reconfigure
1213
)
1314
catkin_python_setup()
1415

1516
# ROS message generation
1617
add_message_files(DIRECTORY msg FILES Axis.msg)
1718
generate_messages(DEPENDENCIES geometry_msgs std_msgs)
1819

20+
generate_dynamic_reconfigure_options(
21+
cfg/PTZ.cfg
22+
)
23+
1924
catkin_package(
2025
CATKIN_DEPENDS
2126
camera_info_manager_py
@@ -32,3 +37,7 @@ install(PROGRAMS
3237
nodes/teleop.py
3338
nodes/teleop_speed_control.py
3439
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
40+
41+
install(DIRECTORY
42+
cfg
43+
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

cfg/PTZ.cfg

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
PACKAGE = "axis_camera"
3+
4+
from dynamic_reconfigure.parameter_generator_catkin import *
5+
6+
gen = ParameterGenerator()
7+
8+
#gen.add("speed_control", bool_t, 0, "Speed control (true) or absolute position control (false)", False)
9+
gen.add("autofocus", bool_t, 0, "Autofocus", True)
10+
gen.add("pan", double_t, 0, "Pan value in degrees (or percent in absolute mode)", 0, -180, 180)
11+
gen.add("tilt", double_t, 0, "Tilt value in degrees (or percent in absolute mode)", -45, -90, 0)
12+
gen.add("zoom", double_t, 0, "Zoom value", 1, 1, 9999)
13+
gen.add("focus", double_t, 0, "Focus", 1, 1, 9999)
14+
gen.add("brightness", double_t, 0, "Brightness", 1, 1, 9999)
15+
16+
exit(gen.generate(PACKAGE, "axis_camera", "PTZ"))

nodes/axis_ptz.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from axis_camera.msg import Axis
1010
from std_msgs.msg import Bool
1111
import math
12+
from dynamic_reconfigure.server import Server
13+
from axis_camera.cfg import PTZConfig
1214

1315
class StateThread(threading.Thread):
1416
'''This class handles the publication of the positional state of the camera
@@ -237,6 +239,32 @@ def createCmdString(self):
237239
def mirrorCallback(self, msg):
238240
'''Command the camera with speed control or position control commands'''
239241
self.mirror = msg.data
242+
243+
def callback(self, config, level):
244+
#self.speedControl = config.speed_control
245+
246+
# create temporary message and fill with data from dynamic reconfigure
247+
temp_msg = Axis()
248+
temp_msg.pan = config.pan
249+
temp_msg.tilt = config.tilt
250+
temp_msg.zoom = config.zoom
251+
temp_msg.focus = config.focus
252+
temp_msg.brightness = config.brightness
253+
temp_msg.autofocus = config.autofocus
254+
255+
# check sanity and apply values
256+
self.cmd(temp_msg)
257+
258+
# read sanitized values and update GUI
259+
config.pan = self.msg.pan
260+
config.tilt = self.msg.tilt
261+
config.zoom = self.msg.zoom
262+
config.focus = self.msg.focus
263+
config.brightness = self.msg.brightness
264+
config.autofocus = self.msg.autofocus
265+
266+
# update GUI with sanitized values
267+
return config
240268

241269
def main():
242270
rospy.init_node("axis_twist")
@@ -253,7 +281,9 @@ def main():
253281
args[name] = rospy.get_param(rospy.search_param(name),
254282
arg_defaults[name])
255283

256-
AxisPTZ(**args)
284+
# create new PTZ object and start dynamic_reconfigure server
285+
my_ptz = AxisPTZ(**args)
286+
srv = Server(PTZConfig, my_ptz.callback)
257287
rospy.spin()
258288

259289
if __name__ == "__main__":

0 commit comments

Comments
 (0)