32路舵機控制-高級指令

從 YFRobotwiki
跳到: 導覽搜尋

1 - 外部EEPROM 讀寫指令

存儲數據 -- EEW / EER(了解即可)

EEW/EER 指令是用来写、读外部EEPROM 数据的。使用这些指令的前提是舵机控制器上有 EEPROM 芯片及固件支持。我们使用的芯片为 IIC 24C256(实际,根据到手控制板决定),它有32768字节空间。

1、写指令格式 -- EEW  (该指令对应上位机软件的“下载”功能)
:EEW -<addr>,<byte>,<byte>,<byte>,...,<byte><cr>

:*<addr> = 写指令起始地址位,十进制
:*<byte> = 被写入的一个字节数据, 十进制

2、读指令格式 -- EER
:EER <addr> ; <nbytes>

:*<addr> = 读数据起始地址位,十进制
:*<nBytes> = 读取数据的字节数,十进制

注意:使用读写指令,格式必须严格遵守,否则读写失败!了解即可!

控制指令集

以下這些指令可以允許用戶播放動作組,程序提供了兩個「播放器」可以各自單獨播放動作組。兩個「播放器」可以同時使用,並且當「播放器」在播放動作組時,其他舵機指令也可以使用!

但需要注意下面兩點:

  • 同時播放兩個動作組時,確保動作組中使用的舵機不重複,否則結果不可預測。
  • 播放動作組中的舵機,不能向其再發送其他舵機指令,否則結果不可預測。

1、播放動作組

PL <p>SQ <s> [SM <m>] [IX <i>] [PA <pa>] [ONCE] <cr> -- 符号<X> 中的为参数的数字,[] 中为可选参数
  • PL <p> 播放器 p 值, 0 或 1
  • SQ <s> 序列號 s 值, 從 0 到 127
  • SM <m> 速度百分比 m 值, 從 -200 到 200 單位:% 默認 100%
  • IX <i> 開始執行步 i 值, 從 0 到 255 默認 0
  • PA <a> 步驟之間停頓 a 值, 從 0 到 65535 單位:ms 默認 0
  • ONCE 指定播放動作組只執行一次
  • <cr> 結束回車符,ASCII碼中的13。

2、停止播放

PL <p><cr>
立即停止播放

3、改變播放速度

PL <p>SM <m><cr>
改變播放速度。

注意:

已經播放某個有效的動作組該指令才能有效。
速度值可以設置為0,這時,舵機將會停止運行,但是動作組仍然在播放(相當於暫停)。

4、改變播放間隔時間

PL <p>PA <pa><cr>
指令改變了播放動作組時,每個動作之間的停頓時間。

注意:

已經播放某個有效的動作組該指令才能有效。

5、跳轉至動作組中的某個動作

SQ <s> [IX <i>] [T <t>]<cr>
指令可以直接跳轉至動作組中的某個動作

注意:

該指令獨立於兩個播放器,在兩個播放器都在播放動作組時,仍然可以發送。
和其他舵機移動指令一樣,該指令不可以使用正在使用中的舵機;若使用,結果不可預測


6、查詢一個播放器

QPL <p><cr>
指令用以查詢某個播放器的狀態信息
指令將返回4位元組的信息:
1.正在播放的動作組序列號(如果沒有播放,返回255)
2.現在所在步數
3.將要執行到哪一步
4.正在執行的動作剩餘時間,單位100ms(例如 還剩下700ms,返回值將為 7)


控制指令例子

PL 0 SQ 5 <cr>

播放器0播放動作組5。從0步開始,100%運行速度,步驟之間沒有間隔,往複不間斷執行。

PL 0 SM -50 <cr>

設置播放器0反方向播放 50%的運行速度。

PL 0 SM 0 <cr>

設置播放器0播放速度為0 (暫停播放)

PL 0 SM 200 <cr>

設置播放器0正方向播放 200%的運行速度。

PL 0 PA 1000 <cr>

設置播放器0播放的動作組,每個動作之間間隔(停頓)1000ms 。

PL 0 <cr>

停止播放器0。

SQ 20 IX 3 <cr>

跳轉至序列20動作組中的第3步動作。

SQ 20 IX 5 T2000 <p><cr>

跳轉至序列20動作組中的第5步動作,耗時2s。

PL 1 SQ 15 IX 2 SM -70 ONCE <cr>

播放器1播放動作組15。從2步開始,反向70%運行速度,步驟之間沒有間隔,執行一次。




2 - 芯片內部寄存器控制及EEPROM讀寫指令

寄存器常規信息

Number Name Minimum Maximum Default Description
0 Eable 0 65535 0 A bit field() that enables various features of the SSC-32.
1 Transmit Delay 0 65535 600 The delay,in microseconds,before transmitting the first byte of a response from the SSC-32.
2 Transmit Pacing 0 65535 70 The delay,in microseconds,between bytes in a response from the SSC-32.
3-31 (Reserved) --- --- --- ---
32-63 Initial Pulse Offset -100 100 0 The initial value of the pulse offset(P0) for each servo. Register 32 corresponds to servo #0, register 33 to servo #1,etc.
64-95 Initial Pulse Width 0 65535 1500 The initial value of the pulse width for each servo. Register 64 corresponds to servo #0, register 65 to servo #1, etc. A value of 0 leaves the servo output at a continuous logic '0'; a value of 65535 leaves the servo output at a continuous logic '1'. All other values are clipped to the range 500 - 2500 microseconds.
96-255 (Reserved) --- --- --- ---
注意:寄存器 0-15 是全局使用的,影響着控制板的所有操作; 32-255是用於每個舵機的配置,所以都是32位一組。


使能寄存器位定義

Bit Name Definition
15(msb) Global Disable If '1',disables all of the featured controlled by the Enable register.

If '0',the individual bit values will be used to enable or disable the features.

14-4 (Reserved) ---
3 Initial Pulse Width Enable If '1',disables all of the featured controlled by the Enable register.

If '0',the individual bit values will be used to enable or disable the features.

2 Initial Pulse Offset Enable If '1',disables all of the featured controlled by the Enable register.

If '0',the individual bit values will be used to enable or disable the features.

1 TX Delay/Pacing Enable If '1',disables all of the featured controlled by the Enable register.

If '0',the individual bit values will be used to enable or disable the features.

0(1sb) Startup String Enable If '1',enables execution of the startup string when power is applied to the SSC-32.

If '0',the startup string will not be executed.


寄存器讀寫

Command Argument Description Examples
Register write: R<r> = <n><cr> r = reg number,0-255 n = value Programs the value of a register. Spaces are optional around the register number and value. R0=1023 <cr>

R32 = -50 <cr>

Register read: R<r><cr> r = reg number,0-255 Displays the value of a register, followed by a carriage return.The displayed value is in ASCII format, and is terminated with a carriage return. R0<cr>
result:1023<cr>

R32<cr>

result: -50 <cr>
Set to defaults: RDFLT <cr> none Sets all of the registers to their default values. When the command is complete the SSC-32 will transmit the string OK<cr>. RDFLT<cr>
result:OK<cr>
注意:寄存器 0-15 的配置 -- 在熟悉後再下使用,否則使用簡單的 R = 1/0 即可(主要使用的是使能上電自動執行)。


其他寄存器指令

Command Argument Description Examples
STOP<n><cr> 0-31 Immediately stops the specified servo at its current position.A space is optional before the servo number. STOP0<cr>

STOP31<cr>

停止某個舵機。如果該舵機正在執行,其他舵機將繼續運行,該舵機停止直到該動作完成。
注意:
  • EER and EEW 指令不適用於內部的EEPROM. 僅用於外部存儲EEPROM.
  • 寄存器讀寫指令和啟動字符串指令是適用於內部EEPROM的(控制芯片的EEPROM)。


啟動字符串

Command Argument Description/Examples
Delete characters: SSDEL<n><cr> 0-255 Deletes <n> characters from the end of the startup string. If <n> is greater than the length of the startup string, then SSDEL deleter the entire string.

SSDEL 5 <cr>

-Deleted the last 5 characters of the startup string

SSDEL 255 <cr>

-Deletes the entire startup string
Concatenate: SSCAT <string> <cr> Up to 100 ASCII characters Concatenates <string> to the current startup string. The blank space immediately following "SSCAT" is ignored, but all other spaces are part of the string. The string is terminated by a carriage return, and may not contain embedded carriage returns. Commands in the startup string are terminated with a semicolon (including the last command).

SSCAT #0P1000#1P2000T3000;<cr> SSCAT PL0 SQ5 SM50;<cr>

Display startup string: SS <cr> none Displays the entire startup string, surrounded by quotation marks and followed by a carriage return.

SS <cr>

result: "#0P1000#1P2000T3000;PL0 SQ5 SM50;"<cr>
停止某個舵機。
注意:
  • 啟用字符串是需要控制板重新上電的,當然使能啟動字符串寄存器位也需要設置。重新上電之後,啟用字符串指令需要再其他寄存器指令執行結束後才執行(例如:初始化舵機角度)
  • 啟用字符串的最大字符串長度為100 ,超過這個部分的做忽略處理。
  • 在啟用字符串指令中不能使用以下指令: EER, EEW, R=, SSCAT, SSDEL.
  • SS 查詢指令和SSCAT 設置字符串指令的執行都需要數百毫秒的時間,根據波特率決定。在舵機運行或者播放動作組過程中不應該使用這兩個指令。
  • 執行SSDEL 或者 SSCAT指令時,控制板不能掉電。確定指令執行完成後,使用 SS 指令查詢等待回應。
  • 每次啟動字符串的改變了都是需要消耗主芯片的EEPROM。EEPROM 典型的最大可寫次數 100000 。所以在使用中不能快速改變啟動字符串,這將可能導致 ATmega 處理器的EEPROM 永久性的損壞。


啟用字符串例子

Command Result
SSDEL 255 <cr>

SS <cr>

""<cr>
SSCAT #0P2000T5000;<cr>

SS <cr>

"#0P2000T5000;"<cr>
SSCAT XXXX<cr>

SSC <cr>

"#0P2000T5000;XXXX"<cr>
SSDEL 4 <cr>

SS <cr>

"#0P2000T5000;"<cr>
SSDEL 6 <cr>

SS <cr>

"#0P2000"<cr>
SSCAT #1P1000T4000;PL0SQ5;<cr>

SS <cr>

"#0P2000#1P1000T4000;PL0SQ5;"<cr>


附加例子

Command Result
RDFLT Set all registers to default values
SSDEL 255 Erase the startup string
R0 Display register 0
R0=2

R1=2000 R2=1000

Set TX delay to 2000uS and TX pacing to 1000uS. (R0=2: Bit 1 of R0 enables TX delay/pacing.)
R0=12

R32=50 R64=1000

Set the pulse offset for servo 0 to 50 and the initial pulse width to 1000. (Bits 2 and 3 of R0 enable pulse offset and pulse width.)
R0=13

SSDEL 255 SSCAT #0P1500T5000;

Move R0 slowly to a pulse width of 1500 at startup. Assume the initial pulse width is set as in the previous example. (Bit 0 of R0 enables the startup string.)
SS Display the current startup string.




返回首頁

更多建議和問題歡迎反饋至 YFRobot論壇

購買方式:YFRobot 電子工作室