Voltecx 目前為測試版。macOS 版先推出,Windows 與 Linux 安裝包仍在測試中。測試版。macOS 版先推出,Windows 與 Linux 版仍在測試。⁠最新消息
文件

通訊鏈路 (commLink)

把最多四個數值從一個控制器送到另一個,並帶有匯流排的時序:送出速率、延遲、依種子產生的抖動與遺失。

commLink

元件參考 · English

分類: 控制 · 種類: {"block":"commLink","kind":"control"}

何時使用

用在監控器透過 PMBus、CAN 或 UART 與轉換器溝通的地方:晚到的設定值、要花幾毫秒的狀態回報、遺失的訊息。只模擬時序,不是通訊協定堆疊:沒有位址、仲裁、檢查碼或重送。

接腳

接腳 訊號域 意義
in1 訊號 訊息的第一個數值
in2 訊號 第二個數值(width 為 2 以上才送出)
in3 訊號 第三個數值(width 為 3 以上才送出)
in4 訊號 第四個數值(width 為 4 才送出)
out1 訊號 最後送達訊息的第一個數值,保持不變
out2 訊號 送達的第二個數值
out3 訊號 送達的第三個數值
out4 訊號 送達的第四個數值
fresh 訊號 每次訊息抵達後 pulse 秒內為 1,否則為 0
lost 訊號 到目前為止遺失的訊息數

常用參數

  • rate: Messages per second, sent at t = k/rate; 0 sends a message whenever an input moves past deadband (預設值: 1k)
  • latency: Fixed delay from sending to arrival (預設值: 1m)
  • jitter: Most extra delay per message, drawn from 0 to jitter with the seed; every message arrives within latency + jitter (預設值: 0)
  • loss: Probability that a message is lost, 0 to 1, drawn with the seed; the lost output counts them (預設值: 0)
  • width: Values per message, 1 to 4: inputs in1 … in<width>, outputs out1 … out<width> (預設值: 1)

參數

鍵 單位 預設值 典型範圍 說明
rate Hz 1k Messages per second, sent at t = k/rate; 0 sends a message whenever an input moves past deadband
latency s 1m Fixed delay from sending to arrival
jitter s 0 Most extra delay per message, drawn from 0 to jitter with the seed; every message arrives within latency + jitter
loss — 0 Probability that a message is lost, 0 to 1, drawn with the seed; the lost output counts them
width — 1 Values per message, 1 to 4: inputs in1 … in<width>, outputs out1 … out<width>
seed — 1 Number that picks the jitter and loss pattern; the same seed gives the same run
deadband — 0 Send on change only: how far an input must move from the last message before a new one is sent
y0 — 0 Outputs until the first message arrives
pulse s 100u How long fresh stays 1 after each arrival; keep it above maxStep to see it in a fixed-step recording

參數說明在兩種語言中都是英文。

模型

rate 大於 0 時,送出端從 t = 0 起在 t = k/rate 讀取 in1 … in<width>;rate 為 0 時,只要某個輸入離上次送出的值超過 deadband 就送出。每則訊息以機率 loss 遺失,並在送出時計入 lost。沒有遺失的訊息在送出後 latency + jitter·u 抵達,u 在 0 到 1 之間均勻分布,而且不會比前一則訊息早到,所以匯流排保持順序,每則訊息都在 latency + jitter 內抵達。輸出保持最後送達的訊息,第一則抵達前為 y0;每次抵達後 fresh 在 pulse 秒內為 1。抽樣只取決於 seed 與訊息編號,所以相同種子在每次執行與兩個求解器中都得到相同的抖動與遺失。送出時刻、抵達時刻與脈波結束時刻都是事件,求解器會剛好落在上面。已有 4096 則訊息在路上時送出的訊息會被丟棄並計為遺失。

常見錯誤

  • rate 為 0 且輸入連續變化時,每個求解步都會送出一則訊息。請給 deadband 一個值,或改用固定速率,讓匯流排的負擔接近真實情形。
  • 固定步長的紀錄只保留格點,所以比 maxStep 短的脈波可能落在格點之間。請讓 pulse 大於 maxStep,並小於訊息間隔,否則 fresh 會一直是 1。
  • 程式碼產生會把這個方塊當成僅供模擬而略過。實際硬體上由匯流排驅動程式傳送訊息,所以請分別產生兩端的程式碼。

規格書與來源

沒有規格書。以下是由位元率推算的典型數字,不是出自標準:PMBus 在 100 kHz 讀寫一個字約需 0.5 ms,主機以 10 到 100 Hz 輪詢(rate 10 到 100、latency 0.5m、jitter 最多 1m)。CAN 在 500 kbit/s 送出 8 位元組的訊框約需 0.27 ms,優先權較低的訊框要等前面的訊框(latency 0.3m、jitter 0.3m 到 1m)。UART 在 115200 baud 每位元組需 87 µs,8 位元組約 0.7 ms(latency 0.7m)。loss 代表匯流排重送之後應用程式仍收不到的訊息。

範例

以指令 file.openExample 開啟範例,名稱為 demo:commLink.


由 cargo xtask reference 依使用說明文字與參數規格產生,請勿手動編輯。