メインコンテンツまでスキップ

Limelight Lib Python

limelightlib-pythonは、Limelightデバイスとインターフェースする最も簡単な方法です。すべてのオペレーティングシステム (MacOS、Windows、Linux)とアーキテクチャ(x86、ARM)で動作します。

インストール

pip install limelightlib-python

使用方法

import limelight
import limelightresults
import json
import time

discovered_limelights = limelight.discover_limelights(debug=True)
print("発見されたLimelight:", discovered_limelights)

if discovered_limelights:
limelight_address = discovered_limelights[0]
ll = limelight.Limelight(limelight_address)
results = ll.get_results()
status = ll.get_status()
print("-----")
print("ターゲティング結果:", results)
print("-----")
print("ステータス:", status)
print("-----")
print("温度:", ll.get_temp())
print("-----")
print("名前:", ll.get_name())
print("-----")
print("FPS:", ll.get_fps())
print("-----")
print("ハードウェアレポート:", ll.hw_report())

ll.enable_websocket()

# 現在のパイプライン設定を表示
print(ll.get_pipeline_atindex(0))

# 現在のパイプラインを更新し、ディスクにフラッシュ
pipeline_update = {
'area_max': 98.7,
'area_min': 1.98778
}
ll.update_pipeline(json.dumps(pipeline_update),flush=1)

print(ll.get_pipeline_atindex(0))

# パイプライン1に切り替え
ll.pipeline_switch(1)

# カスタムユーザーデータを更新
ll.update_python_inputs([4.2,0.1,9.87])


try:
while True:
result = ll.get_latest_results()
parsed_result = limelightresults.parse_results(result)
if parsed_result is not None:
print("有効なターゲット: ", parsed_result.validity, ", パイプラインインデックス: ", parsed_result.pipeline_id,", ターゲティングレイテンシ: ", parsed_result.targeting_latency)
#for tag in parsed_result.fiducialResults:
# print(tag.robot_pose_target_space, tag.fiducial_id)
time.sleep(1) # 最大FPSの場合は0に設定


except KeyboardInterrupt:
print("ユーザーによってプログラムが中断されました。シャットダウンします。")
finally:
ll.disable_websocket()

メソッド

RESTベース

  • get_results(): HTTP GETを介して最新の結果を取得します。
  • capture_snapshot(snapname): 指定された名前でスナップショットを撮影します。
  • upload_snapshot(snapname, image_path): 指定された名前と画像ファイルでスナップショットをアップロードします。
  • snapshot_manifest(): HTTP GETを介してスナップショットマニフェストを取得します。
  • delete_snapshots(): HTTP GETを介してすべてのスナップショットを削除します。
  • upload_neural_network(nn_type, file_path): 指定されたタイプのニューラルネットワークファイルをアップロードします。
  • hw_report(): HTTP GETを介してハードウェアレポートを取得します。
  • cal_default(): HTTP GETを介してデフォルトのキャリブレーションデータを取得します。
  • cal_file(): HTTP GETを介してファイルからキャリブレーションデータを取得します。
  • cal_eeprom(): HTTP GETを介してEEPROMからキャリブレーションデータを取得します。
  • cal_latest(): HTTP GETを介して最新のキャリブレーションデータを取得します。
  • update_cal_eeprom(cal_data): HTTP POSTを介してEEPROMのキャリブレーションデータを更新します。
  • update_cal_file(cal_data): HTTP POSTを介してファイルのキャリブレーションデータを更新します。
  • delete_cal_latest(): HTTP DELETEを介して最新のキャリブレーションデータを削除します。
  • delete_cal_eeprom(): HTTP DELETEを介してEEPROMからキャリブレーションデータを削除します。
  • delete_cal_file(): HTTP DELETEを介してファイルからキャリブレーションデータを削除します。

Websocketベース

  • enable_websocket(): 別のスレッドでWebSocket接続を初期化して開始します。
  • disable_websocket(): WebSocket接続を閉じ、スレッドを結合します。
  • get_latest_results(): WebSocketから受信した最新の結果を返します。

パース

  • limelightresults.parse_results(): 結果をパースしてGeneralResultオブジェクトを返します。

結果クラス仕様

class GeneralResult:
def __init__(self, results):
self.barcode = results.get("Barcode", [])
self.classifierResults = [ClassifierResult(item) for item in results.get("Classifier", [])]
self.detectorResults = [DetectorResult(item) for item in results.get("Detector", [])]
self.fiducialResults = [FiducialResult(item) for item in results.get("Fiducial", [])]
self.retroResults = [RetroreflectiveResult(item) for item in results.get("Retro", [])]
self.botpose = results.get("botpose", [])
self.botpose_wpiblue = results.get("botpose_wpiblue", [])
self.botpose_wpired = results.get("botpose_wpired", [])
self.capture_latency = results.get("cl", 0)
self.pipeline_id = results.get("pID", 0)
self.robot_pose_target_space = results.get("t6c_rs", [])
self.targeting_latency = results.get("tl", 0)
self.timestamp = results.get("ts", 0)
self.validity = results.get("v", 0)
self.parse_latency = 0.0


class RetroreflectiveResult:
def __init__(self, retro_data):
self.points = retro_data["pts"]
self.camera_pose_target_space = retro_data["t6c_ts"]
self.robot_pose_field_space = retro_data["t6r_fs"]
self.robot_pose_target_space = retro_data["t6r_ts"]
self.target_pose_camera_space = retro_data["t6t_cs"]
self.target_pose_robot_space = retro_data["t6t_rs"]
self.target_area = retro_data["ta"]
self.target_x_degrees = retro_data["tx"]
self.target_x_pixels = retro_data["txp"]
self.target_y_degrees = retro_data["ty"]
self.target_y_pixels = retro_data["typ"]

class FiducialResult:
def __init__(self, fiducial_data):
self.fiducial_id = fiducial_data["fID"]
self.family = fiducial_data["fam"]
self.points = fiducial_data["pts"]
self.skew = fiducial_data["skew"]
self.camera_pose_target_space = fiducial_data["t6c_ts"]
self.robot_pose_field_space = fiducial_data["t6r_fs"]
self.robot_pose_target_space = fiducial_data["t6r_ts"]
self.target_pose_camera_space = fiducial_data["t6t_cs"]
self.target_pose_robot_space = fiducial_data["t6t_rs"]
self.target_area = fiducial_data["ta"]
self.target_x_degrees = fiducial_data["tx"]
self.target_x_pixels = fiducial_data["txp"]
self.target_y_degrees = fiducial_data["ty"]
self.target_y_pixels = fiducial_data["typ"]

class DetectorResult:
def __init__(self, detector_data):
self.class_name = detector_data["class"]
self.class_id = detector_data["classID"]
self.confidence = detector_data["conf"]
self.points = detector_data["pts"]
self.target_area = detector_data["ta"]
self.target_x_degrees = detector_data["tx"]
self.target_x_pixels = detector_data["txp"]
self.target_y_degrees = detector_data["ty"]
self.target_y_pixels = detector_data["typ"]

class ClassifierResult:
def __init__(self, classifier_data):
self.class_name = classifier_data["class"]
self.class_id = classifier_data["classID"]
self.confidence = classifier_data["conf"]