Skip to content

Module blueye.sdk.guestport

View Source
import logging

from typing import TYPE_CHECKING, Optional

import blueye.protocol as bp

from packaging import version

from .camera import Camera

if TYPE_CHECKING:

    from .drone import Drone

logger = logging.getLogger(__name__)

class Peripheral:

    def __init__(

        self, parent_drone: "Drone", port_number: bp.GuestPortNumber, device: bp.GuestPortDevice

    ):

        self.parent_drone = parent_drone

        self.port_number: bp.GuestPortNumber = port_number

        self.name: str = device.name

        self.manufacturer: str = device.manufacturer

        self.serial_number: str = device.serial_number

        self.depth_rating: float = device.depth_rating

        self.required_blunux_version: str = device.required_blunux_version

        self.device_id: bp.GuestPortDeviceID = device.device_id

        if self.required_blunux_version != "":

            if version.parse(self.required_blunux_version) > version.parse(

                parent_drone.software_version_short

            ):

                logger.warning(

                    f"Peripheral {self.name} requires Blunux version "

                    f"{self.required_blunux_version}, but the drone is running "

                    f"{parent_drone.software_version_short}"

                )

class GuestPortCamera(Camera, Peripheral):

    def __init__(

        self, parent_drone: "Drone", port_number: bp.GuestPortNumber, device: bp.GuestPortDevice

    ):

        Camera.__init__(self, parent_drone, is_guestport_camera=True)

        Peripheral.__init__(self, parent_drone, port_number, device)

class GuestPortLight(Peripheral):

    def __init__(

        self, parent_drone: "Drone", port_number: bp.GuestPortNumber, device: bp.GuestPortDevice

    ):

        Peripheral.__init__(self, parent_drone, port_number, device)

    def set_intensity(self, intensity: float):

        self.parent_drone._ctrl_client.set_guest_port_lights(intensity)

    def get_intensity(self) -> Optional[float]:

        return self.parent_drone.telemetry.get(bp.GuestPortLightsTel).lights.value

class Gripper(Peripheral):

    def __init__(

        self, parent_drone: "Drone", port_number: bp.GuestPortNumber, device: bp.GuestPortDevice

    ):

        """

        Initializes a new Gripper object.

        *Arguments*:

        * parent_drone (Drone): The parent Drone object that this Gripper is attached to.

        * port_number (GuestPortNumber): The guest port number that this Gripper is attached to.

        * device (GuestPortDevice): The guest port device that this Gripper is attached to.

        """

        Peripheral.__init__(self, parent_drone, port_number, device)

        self._grip_velocity = 0

        self._rotation_velocity = 0

    @property

    def grip_velocity(self) -> float:

        """

        Gets or sets the current grip velocity of the Gripper.

        When used as a getter, returns the current grip velocity of the Gripper.

        When used as a setter, sets the grip velocity of the Gripper to the specified value.

        *Arguments*:

        * value (float): The new grip velocity to set. Must be a float between -1.0 and 1.0.

        *Returns*:

        * grip_velocity (float): The current grip velocity of the Gripper.

        """

        return self._grip_velocity

    @grip_velocity.setter

    def grip_velocity(self, value: float):

        if value < -1.0 or value > 1.0:

            raise ValueError("Grip velocity must be between -1.0 and 1.0.")

        self._grip_velocity = value

        self.parent_drone._ctrl_client.set_gripper_velocities(

            self._grip_velocity, self._rotation_velocity

        )

    @property

    def rotation_velocity(self) -> float:

        """

        Gets or sets the current rotation velocity of the Gripper.

        When used as a getter, returns the current rotation velocity of the Gripper.

        When used as a setter, sets the rotation velocity of the Gripper to the specified value.

        *Arguments*:

        * value (float): The new rotation velocity to set. Must be a float between -1.0 and 1.0.

        *Returns*:

        * rotation_velocity (float): The current rotation velocity of the Gripper.

        """

        return self._rotation_velocity

    @rotation_velocity.setter

    def rotation_velocity(self, value: float):

        if value < -1.0 or value > 1.0:

            raise ValueError("Rotation velocity must be between -1.0 and 1.0.")

        self._rotation_velocity = value

        self.parent_drone._ctrl_client.set_gripper_velocities(

            self._grip_velocity, self._rotation_velocity

        )

def device_to_peripheral(

    parent_drone: "Drone", port_number: bp.GuestPortNumber, device: bp.GuestPortDevice

) -> Peripheral:

    logger.debug(f"Found a {device.name} at port {port_number}")

    if device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUEYE_CAM:

        peripheral = GuestPortCamera(parent_drone, port_number, device)

    elif (

        device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUEYE_LIGHT

        or device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUEYE_LIGHT_PAIR

        or device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUE_ROBOTICS_LUMEN

    ):

        peripheral = GuestPortLight(parent_drone, port_number, device)

    elif (

        device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUE_ROBOTICS_NEWTON

        or device.device_id

        == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUE_ROBOTICS_DETACHABLE_NEWTON

        or device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUEPRINT_LAB_REACH_ALPHA

    ):

        peripheral = Gripper(parent_drone, port_number, device)

    else:

        peripheral = Peripheral(parent_drone, port_number, device)

    return peripheral

Variables

TYPE_CHECKING
logger

Functions

device_to_peripheral

def device_to_peripheral(
    parent_drone: 'Drone',
    port_number: blueye.protocol.types.message_formats.GuestPortNumber,
    device: blueye.protocol.types.message_formats.GuestPortDevice
) -> blueye.sdk.guestport.Peripheral
View Source
def device_to_peripheral(

    parent_drone: "Drone", port_number: bp.GuestPortNumber, device: bp.GuestPortDevice

) -> Peripheral:

    logger.debug(f"Found a {device.name} at port {port_number}")

    if device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUEYE_CAM:

        peripheral = GuestPortCamera(parent_drone, port_number, device)

    elif (

        device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUEYE_LIGHT

        or device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUEYE_LIGHT_PAIR

        or device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUE_ROBOTICS_LUMEN

    ):

        peripheral = GuestPortLight(parent_drone, port_number, device)

    elif (

        device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUE_ROBOTICS_NEWTON

        or device.device_id

        == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUE_ROBOTICS_DETACHABLE_NEWTON

        or device.device_id == bp.GuestPortDeviceID.GUEST_PORT_DEVICE_ID_BLUEPRINT_LAB_REACH_ALPHA

    ):

        peripheral = Gripper(parent_drone, port_number, device)

    else:

        peripheral = Peripheral(parent_drone, port_number, device)

    return peripheral

Classes

Gripper

class Gripper(
    parent_drone: 'Drone',
    port_number: blueye.protocol.types.message_formats.GuestPortNumber,
    device: blueye.protocol.types.message_formats.GuestPortDevice
)
View Source
class Gripper(Peripheral):

    def __init__(

        self, parent_drone: "Drone", port_number: bp.GuestPortNumber, device: bp.GuestPortDevice

    ):

        """

        Initializes a new Gripper object.

        *Arguments*:

        * parent_drone (Drone): The parent Drone object that this Gripper is attached to.

        * port_number (GuestPortNumber): The guest port number that this Gripper is attached to.

        * device (GuestPortDevice): The guest port device that this Gripper is attached to.

        """

        Peripheral.__init__(self, parent_drone, port_number, device)

        self._grip_velocity = 0

        self._rotation_velocity = 0

    @property

    def grip_velocity(self) -> float:

        """

        Gets or sets the current grip velocity of the Gripper.

        When used as a getter, returns the current grip velocity of the Gripper.

        When used as a setter, sets the grip velocity of the Gripper to the specified value.

        *Arguments*:

        * value (float): The new grip velocity to set. Must be a float between -1.0 and 1.0.

        *Returns*:

        * grip_velocity (float): The current grip velocity of the Gripper.

        """

        return self._grip_velocity

    @grip_velocity.setter

    def grip_velocity(self, value: float):

        if value < -1.0 or value > 1.0:

            raise ValueError("Grip velocity must be between -1.0 and 1.0.")

        self._grip_velocity = value

        self.parent_drone._ctrl_client.set_gripper_velocities(

            self._grip_velocity, self._rotation_velocity

        )

    @property

    def rotation_velocity(self) -> float:

        """

        Gets or sets the current rotation velocity of the Gripper.

        When used as a getter, returns the current rotation velocity of the Gripper.

        When used as a setter, sets the rotation velocity of the Gripper to the specified value.

        *Arguments*:

        * value (float): The new rotation velocity to set. Must be a float between -1.0 and 1.0.

        *Returns*:

        * rotation_velocity (float): The current rotation velocity of the Gripper.

        """

        return self._rotation_velocity

    @rotation_velocity.setter

    def rotation_velocity(self, value: float):

        if value < -1.0 or value > 1.0:

            raise ValueError("Rotation velocity must be between -1.0 and 1.0.")

        self._rotation_velocity = value

        self.parent_drone._ctrl_client.set_gripper_velocities(

            self._grip_velocity, self._rotation_velocity

        )

Ancestors (in MRO)

  • blueye.sdk.guestport.Peripheral

Instance variables

grip_velocity

Gets or sets the current grip velocity of the Gripper.

When used as a getter, returns the current grip velocity of the Gripper.

When used as a setter, sets the grip velocity of the Gripper to the specified value.

Arguments:

  • value (float): The new grip velocity to set. Must be a float between -1.0 and 1.0.

Returns:

  • grip_velocity (float): The current grip velocity of the Gripper.
rotation_velocity

Gets or sets the current rotation velocity of the Gripper.

When used as a getter, returns the current rotation velocity of the Gripper.

When used as a setter, sets the rotation velocity of the Gripper to the specified value.

Arguments:

  • value (float): The new rotation velocity to set. Must be a float between -1.0 and 1.0.

Returns:

  • rotation_velocity (float): The current rotation velocity of the Gripper.

GuestPortCamera

class GuestPortCamera(
    parent_drone: 'Drone',
    port_number: blueye.protocol.types.message_formats.GuestPortNumber,
    device: blueye.protocol.types.message_formats.GuestPortDevice
)
View Source
class GuestPortCamera(Camera, Peripheral):

    def __init__(

        self, parent_drone: "Drone", port_number: bp.GuestPortNumber, device: bp.GuestPortDevice

    ):

        Camera.__init__(self, parent_drone, is_guestport_camera=True)

        Peripheral.__init__(self, parent_drone, port_number, device)

Ancestors (in MRO)

  • blueye.sdk.camera.Camera
  • blueye.sdk.guestport.Peripheral

Instance variables

bitrate

Set or get the video stream bitrate

Arguments:

  • bitrate (int): Set the video stream bitrate in bits, valid values are in range (1 000 000..16 000 000)

Returns:

  • bitrate (int): The H264 video stream bitrate
bitrate_still_picture

Set or get the bitrate for the still picture stream

Arguments:

  • bitrate (int): Set the still picture stream bitrate in bits, valid values are in range (1 000 000 .. 300 000 000). Default value is 100 000 000.

Returns:

  • bitrate (int): The still picture stream bitrate
exposure

Set or get the camera exposure

Arguments:

  • exposure (int): Set the camera exposure time. Unit is thousandths of a second, ie. 5 = 5s/1000. Valid values are in the range (1 .. 5000) or -1 for auto exposure

Returns:

  • exposure (int): Get the camera exposure
framerate

Set or get the camera frame rate

Arguments:

  • framerate (int): Set the camera frame rate in frames per second. Valid values are 25 or 30

Returns:

  • framerate (int): Get the camera frame rate
hue

Set or get the camera hue

Arguments:

  • hue (int): Set the camera hue. Valid values are in the range (-40..40)

Returns:

  • hue (int): Get the camera hue
is_recording

Get or set the camera recording state

Arguments:

  • start_recording (bool): Set to True to start a recording, set to False to stop the current recording.

Returns:

  • Recording state (bool): True if the camera is currently recording, False if not
record_time

Set or get the duration of the current camera recording

Returns:

  • record_time (int): The length in seconds of the current recording, -1 if the camera is not currently recording
resolution

Set or get the camera resolution

Arguments:

  • resolution (int): Set the camera in vertical pixels. Valid values are 720 or 1080

Returns:

  • resolution (int): Get the camera resolution
whitebalance

Set or get the camera white balance

Arguments:

  • white_balance (int): Set the camera white balance. Valid values are in the range (2800..9300) or -1 for auto white balance

Returns:

  • white_balance (int): Get the camera white balance

Methods

take_picture

def take_picture(
    self
)

Takes a still picture and stores it locally on the drone

These pictures can be downloaded with the Blueye App, or by any WebDAV compatible client.

View Source
    def take_picture(self):

        """Takes a still picture and stores it locally on the drone

        These pictures can be downloaded with the Blueye App, or by any WebDAV compatible client.

        """

        self._parent_drone._ctrl_client.take_still_picture()

GuestPortLight

class GuestPortLight(
    parent_drone: 'Drone',
    port_number: blueye.protocol.types.message_formats.GuestPortNumber,
    device: blueye.protocol.types.message_formats.GuestPortDevice
)
View Source
class GuestPortLight(Peripheral):

    def __init__(

        self, parent_drone: "Drone", port_number: bp.GuestPortNumber, device: bp.GuestPortDevice

    ):

        Peripheral.__init__(self, parent_drone, port_number, device)

    def set_intensity(self, intensity: float):

        self.parent_drone._ctrl_client.set_guest_port_lights(intensity)

    def get_intensity(self) -> Optional[float]:

        return self.parent_drone.telemetry.get(bp.GuestPortLightsTel).lights.value

Ancestors (in MRO)

  • blueye.sdk.guestport.Peripheral

Methods

get_intensity

def get_intensity(
    self
) -> Optional[float]
View Source
    def get_intensity(self) -> Optional[float]:

        return self.parent_drone.telemetry.get(bp.GuestPortLightsTel).lights.value

set_intensity

def set_intensity(
    self,
    intensity: float
)
View Source
    def set_intensity(self, intensity: float):

        self.parent_drone._ctrl_client.set_guest_port_lights(intensity)

Peripheral

class Peripheral(
    parent_drone: 'Drone',
    port_number: blueye.protocol.types.message_formats.GuestPortNumber,
    device: blueye.protocol.types.message_formats.GuestPortDevice
)
View Source
class Peripheral:

    def __init__(

        self, parent_drone: "Drone", port_number: bp.GuestPortNumber, device: bp.GuestPortDevice

    ):

        self.parent_drone = parent_drone

        self.port_number: bp.GuestPortNumber = port_number

        self.name: str = device.name

        self.manufacturer: str = device.manufacturer

        self.serial_number: str = device.serial_number

        self.depth_rating: float = device.depth_rating

        self.required_blunux_version: str = device.required_blunux_version

        self.device_id: bp.GuestPortDeviceID = device.device_id

        if self.required_blunux_version != "":

            if version.parse(self.required_blunux_version) > version.parse(

                parent_drone.software_version_short

            ):

                logger.warning(

                    f"Peripheral {self.name} requires Blunux version "

                    f"{self.required_blunux_version}, but the drone is running "

                    f"{parent_drone.software_version_short}"

                )

Descendants

  • blueye.sdk.guestport.GuestPortCamera
  • blueye.sdk.guestport.GuestPortLight
  • blueye.sdk.guestport.Gripper