AIM WebSocket 差异#

本页概述了基于 WebSocket 的 Python API 与 VEXcode AIM Python API 之间的主要区别。其中包括新增的功能、移除的类以及对多机器人控制等高级用例的支持。

其他方法#

播放本地文件#

The play_local_file method plays a sound file that is stored on the computer and outputs the sound through the robot’s speaker. This allows you to play custom .wav or .mp3 files on the robot without needing to upload them.

Usage:
robot.sound.play_local_file(filepath: str, volume = 100)

参数

描述

文件路径

A string specifying the path to a .wav or .mp3 file on the computer.

体积

可选。播放音量百分比,范围为 0 到 100。默认值为 100。

To view an implementation example, open play_sounds.py

获取相机图像#

The get_camera_image method captures the current frame from the robot’s AI Vision Sensor and returns it as a JPEG-compressed bytes object. This is typically used with tools like OpenCV for displaying a live video feed.

Usage:
robot.vision.get_camera_image()

参数

描述

此方法没有参数

To view an implementation example, see stream_video.py.

同时使用多个机器人#

You can connect to multiple robots by manually specifying each robot’s IP address when creating Robot objects.

Usage:
Robot(address)

参数

描述

地址

Optional. The IP Address of the robot. If omitted, the address in the host field of settings.json is used by default.

To view an implementation example, open multiple_robots.py.

已删除的类#

VEXcode Python API 中提供的以下类在 WebSocket 版本中不可用:

  • Controller

  • Event

仅在 VEXcode 中可用的功能#

以下功能目前不支持通过 AIM WebSocket API 使用,需要通过 VEXcode AIM 连接:

  • 更新机器人固件

  • 上传自定义图像

  • 上传自定义声音

  • Robot to robot messaging