toddlerbot.sensing package

Submodules

toddlerbot.sensing.FSR module

class toddlerbot.sensing.FSR.FSR(baud_rate=115200)

Bases: object

A class for interfacing with the FSR sensors on the robot.

close()

Closes the connection to the FSR interface.

This method closes the serial connection to the FSR (Force Sensing Resistor) interface and prints a confirmation message indicating that the connection has been successfully closed.

get_state()

Reads the most recent Force Sensitive Resistor (FSR) values from the serial port and returns them as percentages.

The function attempts to read the FSR values, which are expected to be in the range of 0 to 100 percent. If no valid data is available, it returns (0, 0). The function retries up to two additional times if an error occurs during the reading process.

Returns:

A tuple containing two float values representing the FSR values as percentages. Returns (0, 0) if no valid data is available or if an error persists after retries.

Return type:

tuple

toddlerbot.sensing.IMU module

toddlerbot.sensing.camera module

class toddlerbot.sensing.camera.AprilTagDetector(families: str = 'tag36h11')

Bases: object

AprilTag detector class.

detect(img: ndarray[Any, dtype[uint8]], intrinsics: Dict[str, float] | ndarray[Any, dtype[float32]], tag_size: float) List[Detection]

Detect AprilTags in an image and estimate their poses.

Parameters:
  • img (npt.NDArray[np.uint8]) – The input image in BGR format.

  • intrinsics (Dict[str, float] | npt.NDArray[np.float32]) – Camera intrinsics, either as a dictionary with keys ‘fx’, ‘fy’, ‘cx’, ‘cy’ or as a 3x3 intrinsic matrix.

  • tag_size (float) – The size of the AprilTag in meters.

Returns:

A list of detected AprilTags with pose estimates.

Return type:

List[apriltag.Detection]

vis_tag(img: ndarray[Any, dtype[uint8]], results: List[Detection]) ndarray[Any, dtype[uint8]]

Visualizes detected AprilTags on an image by drawing bounding boxes, centers, and labels.

Parameters:
  • img (npt.NDArray[np.uint8]) – The input image on which to draw the detections.

  • results (List[apriltag.Detection]) – A list of AprilTag detection results, each containing corner points, center, tag family, and tag ID.

Returns:

The image with visualized AprilTag detections.

Return type:

npt.NDArray[np.uint8]

class toddlerbot.sensing.camera.Camera(side, width=640, height=480)

Bases: object

Camera class for capturing images and detecting AprilTags.

close()

Releases the video capture object and closes all OpenCV windows.

This method should be called to properly release the resources associated with the video capture and to close any OpenCV windows that were opened during the process.

detect_tags(tag_size: float = 0.03)

Detects AprilTags in the current frame and computes their poses.

This method captures a frame from the camera, detects AprilTags using the specified tag size, and calculates their poses relative to the camera. The poses are returned as a dictionary mapping tag IDs to their transformation matrices.

Parameters:

tag_size (float) – The size of the AprilTags in meters. Default is 0.03.

Returns:

A dictionary where keys are tag IDs and values are 4x4 transformation matrices representing the pose of each detected tag in the camera frame.

Return type:

Dict[int, npt.NDArray[np.float32]]

get_frame()

Captures and returns a single frame from the video stream.

Raises:

Exception – If the frame could not be captured.

Returns:

The captured video frame.

Return type:

numpy.ndarray

get_jpeg()

Converts the current video frame to JPEG format and returns it along with the RGB frame.

Returns:

A tuple containing:
  • jpeg (numpy.ndarray): The encoded JPEG image.

  • frame_rgb (numpy.ndarray): The RGB representation of the current video frame.

Return type:

tuple

toddlerbot.sensing.microphone module

toddlerbot.sensing.speaker module

Module contents