Broken Data Wires LEGO MINDSTORMS NXT

無效的資料線
Broken Data Wires

當在程式中隨意組合指令時,可能會有四種不適當的資料線連結發生. 這樣的錯誤都是無效的連結並以灰色表示. 有無效資料線的程式就無法下載到NXT.
While there is no way to improperly order blocks in a program, there are four ways to improperly connect them using data wires. Such connection errors create “broken” data wires that are colored gray. Programs containing broken data wires cannot be downloaded to the NXT.

四種可能的資料線錯誤如下:
The four possible data wire errors are:

資料型態不符 Type mismatch

每種資料線都負責特定的資料傳輸. 例如,從某個指令資料集線器的邏輯連接埠拉出的資料線將會傳輸邏輯資料,就只能連結到另一個集線器中同屬接收邏輯資料的連接埠上.
Each data wire carries a specific type of data between programming blocks. For example, if a data wire is dragged from a logic output plug on a block’s data hub, it will be carrying logic data. This data wire can only connect to a logic input plug on another block’s data hub.

同樣的理由,數值輸出連接埠必須連結到數值輸入連接埠上,而文字的連結埠也就只能連結到文字連接埠上.For the same reason, number output plugs must be connected to number input plugs and text output plugs must be connected to text input plugs.

如果用資料線試圖連結不同的資料時,資料型態不符的錯誤狀況就會產生.例如,將邏輯輸出連接埠連到文字輸入連接埠.
A type mismatch error occurs if you connect a data wire between plugs that handle different types of data, for example, connecting a logic output plug to a text input plug.

要避免這樣的錯誤發生,就必須留意該連接埠的資料型態.
Avoid this error be paying particular attention to the data types of the plugs you are attaching data wires to.

範例: Example:
假設要在NXT螢幕上顯示數字 Suppose you would like to display a number on your NXT’s screen.

在下方的第一個程式中,帶有數字的資料線試著要連到文字輸入埠時,該資料線就會呈現灰色的無效狀態.那麼這個程式是無法執行且不能下載到NXT上.
In the first program shown below, a data wire is attempting to carry number data to a text input port. The data wire is “broken” and colored gray. This program is invalid and cannot be downloaded.

Image

在正確的程式中,可以使用文字格式指令(在進階指令面板中),先將數字資料轉換成文字,然後再將文字格式指令的文字輸出連到顯示指令的文字輸入上. 那麼這個程式會是可行且可被下載.
In the corrected program, a Text Format block (found in the Advanced block palette) has been added to first convert the number data to text. Then the text output from the Text Format block is carried to the Display block’s text input plug. This program is valid and can be downloaded.

Image

循環 Cycle

使用若干指令跟資料線是可以讓資料線連到同一指令兩次,而這就造成循環,且會產生無效的資料線讓程式無效.
Given any set of blocks and wires, if you are able to follow a wire path that visits the same block twice, you have a cycle. This will cause broken data wires and an invalid program.

解決方式是從循環中移除一條或是多條資料線.
The solution is to remove one or more wires from the cycle.

範例 Example:
假設要在程式中,讓馬達的執行時間從現有的執行時間加倍,也就是乘以二,之後再將數值送回馬達的輸入連接埠上.
Suppose you want to create a program that keeps doubling the duration value for a motor by reading the motor’s current duration, multiplying it by two, and then feeding it back to the motor’s input plug.

這樣的程式將不能執行,因為這些資料線產生了循環.可以看出資料線都連到這些指令兩次.
The program below will not work because the data wires create a cycle. You can see that the wire path visits each of these blocks twice.

Image

在迴圈中加上一個數值變數來傳遞乘上二之後的執行時間.將可以解決此問題.
The program below solves the problem by using a number variable to send the doubled duration back in the loop.

Image

缺少輸入端 Missing input

沒有資料來源的資料線將沒有作用.因為沒有資料可供傳遞會是無效的狀態.
A data wire without a data source cannot function; it has no data to carry and will be marked as broken.

例如在資料集線器中,有些屬性是有成對的輸入與輸出連接埠. 那麼這些輸出連接埠只有在資料線連結到輸入連接埠且有資料來源時才會作用.
For instance, on a data hub that has both input and output plugs for a certain property, the output plug will only work if another data wire is also connected to the input plug providing the output plug with a data source.

範例: Example:
假設要透過另一個指令資料集線器來傳遞資料.
Suppose you want to pass data through another block’s data hub.

在下列程式中, 因為沒有資料從輸入連接埠傳送進來所以資料線會呈現灰色無效的狀態,則該程式是無效且無法下載.
In the program below, the broken data wire (in gray) has no data to carry because nothing is “passed through” from the input plug. This program is invalid and cannot be downloaded.

Image

在下列正確的程式中,有輸入資料連結到輸入連接埠. 來自於聲控感應器指令的數值資料可以藉由數學指令而傳遞到數字轉文字指令.
In the corrected program below, an input data wire has been connected to the input plug. Number data from the Sound Sensor block can now be passed through the Math block to the Text Convert block.

Image

過多資料輸入 Too many inputs

超過一條的資料線連到同一個輸入連接埠時會產生無效的資料線.並且會是無效程式.
More than one data wire connected to the same input plug will cause broken data wires and an invalid program.

篩除或是移除多餘的資料線就可以解決這樣的問題,這樣每個輸入連接埠只會連到一個輸出連接埠.
The solution to this problem is to delete or move broken data wires so that each input plug is connected to only one output plug.

下圖表示含有無效資料線的程式跟修改後的程式.
The illustrations below show an invalid program with broken data wires and then a corrected program.

Image

Image

刪除資料線 Deleting a data wire

點選右邊的連接埠就可以篩除一條從左方連到右方連接埠的資料線.
To delete a data wire that stretches from left to right between two data plugs, click on the right plug.