diff --git a/nodes/axis_ptz.py b/nodes/axis_ptz.py index 3ba095c..a4a576f 100755 --- a/nodes/axis_ptz.py +++ b/nodes/axis_ptz.py @@ -35,8 +35,9 @@ def run(self): def queryCameraPosition(self): '''Using Axis VAPIX protocol, described in the comments at the top of this file, is used to query the state of the camera''' - conn = httplib.HTTPConnection(self.axis.hostname) queryParams = { 'query':'position' } + conn = httplib.HTTPConnection(self.axis.hostname) + try: conn.request("GET", "/axis-cgi/com/ptz.cgi?%s" % urllib.urlencode(queryParams)) @@ -69,21 +70,24 @@ def queryCameraPosition(self): def publishCameraState(self): '''Publish camera state to a ROS message''' - if self.cameraPosition is not None: - self.msg.pan = float(self.cameraPosition['pan']) - if self.axis.flip: - self.adjustForFlippedOrientation() - self.msg.tilt = float(self.cameraPosition['tilt']) - self.msg.zoom = float(self.cameraPosition['zoom']) - self.msg.iris = 0.0 - if 'iris' in self.cameraPosition: - self.msg.iris = float(self.cameraPosition['iris']) - self.msg.focus = 0.0 - if 'focus' in self.cameraPosition: - self.msg.focus = float(self.cameraPosition['focus']) - if 'autofocus' in self.cameraPosition: - self.msg.autofocus = (self.cameraPosition['autofocus'] == 'on') - self.axis.pub.publish(self.msg) + try: + if self.cameraPosition is not None: + self.msg.pan = float(self.cameraPosition['pan']) + if self.axis.flip: + self.adjustForFlippedOrientation() + self.msg.tilt = float(self.cameraPosition['tilt']) + self.msg.zoom = float(self.cameraPosition['zoom']) + self.msg.iris = 0.0 + if 'iris' in self.cameraPosition: + self.msg.iris = float(self.cameraPosition['iris']) + self.msg.focus = 0.0 + if 'focus' in self.cameraPosition: + self.msg.focus = float(self.cameraPosition['focus']) + if 'autofocus' in self.cameraPosition: + self.msg.autofocus = (self.cameraPosition['autofocus'] == 'on') + self.axis.pub.publish(self.msg) + except KeyError as e: + rospy.logwarn("Camera not ready for polling its telemetry: " + repr(e.message)) def adjustForFlippedOrientation(self): '''Correct pan and tilt parameters if camera is mounted backwards and @@ -303,4 +307,4 @@ def main(): if __name__ == "__main__": main() - \ No newline at end of file +