Exemplo n.º 1
0
    def __init__(self, hostname, username, password, flip, speed_control, frame_id="axis_camera",
                 use_encrypted_password=False, state_publishing_frequency=50, camera_id=1):
        """Initialize the PTZ driver and start publishing positional data.

        :param hostname: Hostname of the camera (without http://, can be an IP address).
        :type hostname: basestring
        :param username: If login is needed, provide a username here.
        :type username: basestring|None
        :param password: If login is needed, provide a password here.
        :type password: basestring|None
        :param flip: Whether to flip the controls (for ceiling-mounted cameras). Deprecated.
        :type flip: bool
        :param speed_control: Use speed control instead of positional. Deprecated.
        :type speed_control: bool
        :param frame_id: Id of the frame in which positinal data should be published.
        :type frame_id: basestring
        :param use_encrypted_password: Whether to use Plain HTTP Auth (False) or Digest HTTP Auth (True).
        :type use_encrypted_password: bool
        :param state_publishing_frequency: The frequency at which joint states should be published.
        :type state_publishing_frequency: int
        :param camera_id: ID (number) of the camera. Can be 1 to 4.
        :type camera_id: int
        """

        self._hostname = hostname
        self._camera_id = camera_id
        self._frame_id = frame_id

        self._state_publishing_frequency = state_publishing_frequency

        self._executing_reconfigure = False
        self._reconfigure_mutex = threading.Lock()

        self._api = None
        # autodetect the VAPIX API and connect to it; try it forever
        while self._api is None and not rospy.is_shutdown():
            try:
                self._api = VAPIX.get_api_for_camera(hostname, username, password, camera_id, use_encrypted_password)
            except (IOError, ValueError):
                rospy.loginfo(
                    "Retrying connection to VAPIX on host %s, camera %d in 2 seconds." % (hostname, camera_id))
                rospy.sleep(2)
        if rospy.is_shutdown():
            return

        if not self._api.has_ptz():
            raise RuntimeError("Camera %d on host %s doesn't have a Pan-Tilt-Zoom unit." % (self._camera_id, self._hostname))

        # Create a controller of the camera
        self._camera_controller = AxisCameraController(self._api, self, flip_vertically=flip, flip_horizontally=flip)

        # BACKWARDS COMPATIBILITY LAYER
        self.username = username  # deprecated
        self.password = password  # deprecated
        self.flip = flip  # deprecated
        self.speedControl = speed_control  # deprecated
        self.mirror = False  # deprecated

        self.msg = None  # deprecated
        self.cmdString = ""  # deprecated

        self.pub = rospy.Publisher("state", Axis, queue_size=100)  # deprecated
        self.command_subscriber = rospy.Subscriber("cmd", Axis, self.cmd, queue_size=100)  # deprecated
        self.mirror_subscriber = rospy.Subscriber("mirror", Bool, self.mirrorCallback, queue_size=100)  # deprecated

        self.srv = Server(PTZConfig, self.callback)  # deprecated

        # Needs to be after the backwards compatibility setup
        # start the publisher thread
        self._publisher_thread = PositionStreamingThread(self, self._api)
        self.st = self._publisher_thread  # deprecated
        self._publisher_thread.start()