मुख्य कंटेंट तक स्किप करें

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("discovered limelights:", 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("targeting results:", results)
print("-----")
print("status:", status)
print("-----")
print("temp:", ll.get_temp())
print("-----")
print("name:", ll.get_name())
print("-----")
print("fps:", ll.get_fps())
print("-----")
print("hwreport:", 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("valid targets: ", parsed_result.validity, ", pipelineIndex: ", parsed_result.pipeline_id,", Targeting Latency: ", 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("Program interrupted by user, shutting down.")
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 के माध्यम से फाइल से कैलिब्रेशन डेटा हटाता है।

वेबसॉकेट-आधारित

  • enable_websocket(): दूसरे थ्रेड में वेबसॉकेट कनेक्शन को इनिशियलाइज़ और स्टार्ट करता है।
  • disable_websocket(): वेबसॉकेट कनेक्शन को बंद करता है और थ्रेड को जोड़ता है।
  • get_latest_results(): वेबसॉकेट से प्राप्त नवीनतम परिणाम लौटाता है।

पार्सिंग

  • 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"]