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 电子工作室