Skip to main content

minros gömülü mesajlaşma protokolünün Python portu (pub/sub, reliability, std_msgs)

Project description

minrospy

minros gömülü mesajlaşma kütüphanesinin Python portu. Bayt tabanlı transportlar (seri port, TCP, loopback…) üzerinde çalışan, ROS benzeri hafif bir pub/sub protokolü sağlar. Wire formatı C++ minros ile birebir uyumludur — bir MCU'da çalışan minros düğümü ile bir PC'de çalışan minrospy düğümü doğrudan haberleşebilir.

Mimari

C++ kütüphanesinin katmanları korunmuştur. Core (wireframe/framer/parser/broker) ve RawNode güvenilirlikten habersizdir; seq diye bir wire alanı yoktur. Reliable, RawNode'un public pub/sub API'sini kullanan bağımsız bir overlay'dir: seq'i payload'ın önüne opak bir önek olarak koyar, ACK'i normal bir kanaldan (CH249) yollar.

Katman Modül Sorumluluk
Wire formatı core/wireframe.py Frame sabitleri + CRC-8/SMBUS
Framer core/framer.py Payload → wire frame (opak head önekli)
Parser core/parser.py Byte akışı → frame (durum makinesi)
Broker core/broker.py CH_ID bazında dağıtım
RawNode raw_node.py Saf ham byte API (reliability'den habersiz)
Reliable overlays/reliability/reliable.py seq / ACK / retransmit / dedup — RawNode üzerine overlay
Node node.py RawNode + Reliable üzerine tipli yüksek seviye sarmalayıcı
interfaces interfaces/ MsgBase + aileler: std_msgs/ (Float32, …), geometry_msgs/ (Vector3, Twist, …)

Frame formatı

[HEADER 'mros'(4)] [LEN(1)] [CH_ID(1)] [PAYLOAD(1..248)] [CRC-8(1)]
  • LEN = CH_ID + PAYLOAD uzunluğu (2..249)
  • CRC = CRC-8/SMBUS (poly 0x07, init 0x00) — DATA byte'ları üzerinden
  • Çok baytlı alanlar little-endian
  • Core SEQ bilmez. Güvenilir mesajlarda Reliable, PAYLOAD'ın önüne 1 baytlık seq öneki koyar ([SEQ][user bytes]); ACK frame'leri CH249'da [RESP][CH][SEQ] taşır. Bu, core için opak veridir.

Transport

Transport dört callable tutar:

Transport(
    send_bytes = lambda data: ...,   # bytes yaz
    read_bytes = lambda n: ...,      # en fazla n bytes oku -> bytes
    get_size   = lambda: ...,        # okunmaya hazır byte sayısı -> int
    get_time   = lambda: ...,        # ms cinsinden zaman -> int
)

Kullanım — tipli API

from minrospy import Node, Transport
from minrospy.interfaces.geometry_msgs import Twist, Vector3

node = Node()
node.transport = Transport(send_bytes=..., read_bytes=..., get_size=..., get_time=...)

# Publisher
pub = node.create_publisher(Twist, ch_id=1)
pub.publish(Twist(Vector3(0.5, 0, 0), Vector3(0, 0, 0.2)))

# Subscriber — callback doğrudan tipli mesaj alır
node.create_subscription(Twist, ch_id=1, cb=lambda msg: print(msg.linear.x))

# Güvenilir publisher (ACK + retransmit) — retransmit otonomdur, callback gerekmez
pub = node.create_publisher(Twist, ch_id=2, reliable=True)
if not pub.publish(Twist(...)):
    ...  # önceki mesaj hâlâ uçuşta (ACK bekleniyor), sonra dene

# Güvenilir subscriber
node.create_subscription(Twist, ch_id=2, cb=lambda msg: ..., reliable=True)

while True:
    node.spin_once()   # parser + reliable tick birlikte

Kullanım — düşük seviye API

RawNode saf ham byte transporttur; güvenilirlik isteyen Reliable overlay'ini takar.

from minrospy import RawNode, Reliable, Transport

node = RawNode()
node.transport = Transport(...)

# Unreliable — callback ham payload alır
node.subscribe(5, lambda payload: print(payload))
node.publish(5, b"\xde\xad\xbe\xef")

# Reliable — overlay'i node'a tak (dedup + otomatik ACK + otonom retransmit)
rel = Reliable(node)
rel.subscribe(6, lambda payload: print("reliable:", payload))

while True:
    node.spin_once()   # gelen baytlar
    rel.tick()         # timeout/retransmit
    if rel.can_send(6):
        rel.publish(6, b"\x01\x02")

Pyserial ile gerçek transport örneği

import time, serial
from minrospy import Node, Transport
from minrospy.interfaces.std_msgs import Float32

ser = serial.Serial("/dev/ttyUSB0", 115200, timeout=0)
node = Node()
node.transport = Transport(
    send_bytes=ser.write,
    read_bytes=ser.read,
    get_size=lambda: ser.in_waiting,
    get_time=lambda: int(time.monotonic() * 1000),
)

node.create_subscription(Float32, 1, lambda m: print("sıcaklık:", m.value))
while True:
    node.spin_once()

Testler

python minrospy/tests/test_minrospy.py
# veya
python -m pytest minrospy/tests

Wire uyumluluğu, C++ minros ile paylaşılan tarafsız altın vektörlere karşı conformance/ altında doğrulanır; iki implementasyon birbirinden kayarsa testlerden biri kırmızıya döner:

./conformance/run.sh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

minrospy-0.1.0.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

minrospy-0.1.0-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

Details for the file minrospy-0.1.0.tar.gz.

File metadata

  • Download URL: minrospy-0.1.0.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for minrospy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8dff787a951a4048aac9cfec5b9031027fb1401d94e0d222ec4aff0e952e2bed
MD5 e41971321c0ee5f86492f0306dcf6d8a
BLAKE2b-256 d36653cd060dbc82f29b7719c9e2a1d6f1f8446dd45dc9dd5392fdcec115383e

See more details on using hashes here.

File details

Details for the file minrospy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: minrospy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for minrospy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 afbaa41134937d5c4b9547a3dda69e90417c4ec5533e08ee00028dc0596398b2
MD5 05bb19ac55ce4be97ef77e4d8cd00068
BLAKE2b-256 a43affa8fc95f5233b87a7f19a094bd1a0b3595c377bf6ebb97be8383d5120a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page