Robotis Servo 與 RoBoard 之連接介面

Post on 19-Jun-2015

830 views 8 download

Transcript of Robotis Servo 與 RoBoard 之連接介面

OVERVIEW

AX-12 & RX-28 的規格 AX-12 的傳輸訊號為 half duplex TTLRX-28 的傳輸訊號為 RS-485AX-12 及 RX-28 的傳輸速度為 7343bps ~ 1 Mbps

Serial Servos 的接線方式Bioloid CM-5 控制器的電路設計KRS serial USB adapter 的電路設計常見的 serial USB adapter 的電路設計

Bioloid CM-5 控制器電路 Direction_Port 可以控制 TXD, RXD 的方向

Direction_Port is high: the TxD is output as data.Direction_Port is Low: the data is input as RxD.

KRS Serial USB Adapter 電路 採用機器人控制板半雙工的設計

TxD 及 RxD 短路,在輸出資料時同時會收到訊號在 WinXP 或是 Linux 下傳輸 data 時,如果發生

context switch 不會有 data loss 的情形

常見的 Serial USB Adapter 電路

大多數機器人玩家的作法用硬體 (DTxEN) 控制 RxD, TxD 的 enable 與

disable

RB-100 Comport 簡介 RB-100 comport location

COM 1 ~ 4 的傳輸速度最高 115200 bps.

COM 4(TTL, Half-duplex)

COM 3 (TTL, Full-duplex)

COM 2 (RS-485)

COM 1(RS-232)

Power

COM 2 / RS-485

Pin # Signal Name

LineColor

1 GND Black

2 Vxx Red

3 RS485+ Other

4 RS485- Other

1 2 3 4

1 2 3 4

COM 2 / RS-485

COM 2 / RX-28 轉接線製作

Preparation

4-pin header of 2.54mm pitch

COM2 line in RoBoard Cable set

COM 2 / RX-28 轉接線製作

Solder the COM 2 line and the pin header together

Weld

GND Vxx RS-485+ RS-485-

COM 2 / RX-28 轉接線製作

Shorten the Vxx pin

COM 2 / RX-28 轉接線製作

Connect RX-28 to RoBoard's COM 2

COM 3 / Full Duplex TTL

Pin # Signal Name

LineColor

1 GND Black

2 Vxx Red

3 TXD3 Other

4 RXD3 Other

1 2 3 4

1 2 3 4

COM 3 / Full Duplex TTL

COM 3 / AX-12 轉接線製作

Preparation

RoBoard COM3 line

13 2.54mm pitch pin header

COM 3 / AX-12 轉接線製作

Short the TxD/RxD pins (yellow lines)

Vxx

TxDGND

RxD

COM 3 / AX-12 轉接線製作

Solder the COM 3 line and the pin header together

COM 3 / AX-12 轉接線製作

Shorten the Vxx pin

COM 3 / AX-12 轉接線製作

Connect AX-12 to RoBoard's COM 3

COM 4 / Half Duplex TTL

Pin # Signal Name

LineColor

1 GND Other

2 Vxx Red

3 TXRX4 Black

3 2 1

3 2 1

COM 4 / Half Duplex TTLFor older models:

DM118A/DM118B/DM118C

COM4 is an usual industrial

half-duplex port whose data-

transfer direction is controlled

by RTS signal of COM4.

RTS enabled: transfer data

RTS disabled: receive data

COM 4 / Half Duplex TTLFor the newest model:

DM118D

COM4 is equivalent to a full-

duplex port of TXD/RXD

shorted.

It is the configuration most

compatible to common serial

servos, such as Bioloid AX-12

and KONDO KRS-2552HV.

COM 4 / AX-12 轉接線製作

Preparation

13 2.54mm pitch pin headerRoBoard COM3 line

COM 4 / AX-12 轉接線製作

Solder the COM 4 line and the pin header together

Vxx

Data

GND

COM 4 / AX-12 轉接線製作

Shorten the Vxx pin

COM 4 / AX-12 轉接線製作

Connect AX-12 to RoBoard's COM 4

RB-110 Comport 簡介 RB-110 comport location

COM 1 ~ 4 的傳輸速度最高可達 750K bps. COM 5 & 6 的傳輸速度最高可達 12M bps.

COM 1(RS-232)

COM 5(TTL, Full-duplex,

FTDI Hi-Speed)

COM 4(TTL, Full-duplex)

COM 3(TTL, Full-duplex)

COM 2 (RS-485)

System Power

Servo Power

COM 6(TTL, general function,

FTDI Hi-Speed)

COM 2 / RS-485

Pin # Signal Name

LineColor

1 GND Black

2 Vxx Red

3 RS-485+ Other

4 RS-485- Other

4321

4321

COM 2 / RS-485

COM 2 / RX-28 轉接線製作

製作方法如同 RB-100 COM 2

COM 3 / Full Duplex TTL

Pin # Signal Name

LineColor

1 GND Black

2 Vxx Red

3 TXD3 Other

4 RXD3 Other

4321

4321

COM 3 / Full Duplex TTL

COM 3 / AX-12 轉接線製作

製作方法如同 RB-100 COM 3

COM 4 / Full Duplex TTL

4321

4321

Pin # Signal Name

LineColor

1 GND Black

2 Vxx Red

3 TXD4 Other

4 RXD4 Other

COM 4 / Full Duplex TTL

COM 4 / AX-12 轉接線製作

製作方法如同 RB-100 COM 3

COM 5 / Full Duplex TTL / FTDI Hi-Speed

Pin # Signal Name

Pin # Signal Name

Pin # Signal Name Pin # Signal

Name

1 GND 2 Vxx 3 TXD5 4 RXD5

1 2 3 4 1 2 3 4

Note: You can also use COM 5 as Half-Duplex TTL (same as COM 3/4)

RoBoard FTDI COMRoBoard RB-110 背面的 FTDI Chip

COM 5/AX-12 轉接線製作 製作方法如同 RB-100 COM 3

FTDI’s COM 與 RoBoard’s COM 的比較

FTDI’s COM RoBoard’s COM

Buadrate ~ 12M bps ~ 115200 bps (RB-100) ~ 750K bps (RB-110)

Latency 較長 短

FTDI COM & 原生 COMFTDI 的 Latency Time 會影響大量傳輸資料的時間左下圖 : COM3 500Kbps 送 3 次 2 byte data

右下圖 : COM5 1Mbps 送 3 次 2 byte data

COM3

500Kbps

延遲時間

COM5

1Mbps

延遲時間

COM Lib 簡介跨平台 – Win, WinCE, Linux支援 RoBoard 4 個原生 COM port :

COM1 RS232 – 全雙工COM2 RS485 – 半雙工COM3 TTL – 全雙工 , 半雙工COM4 TTL – 全雙工 (RB-110), 半雙工 (RB-110 & RB-100)

支援 RoBoard RB-110 高速 baudrate (750K bps)

COM port 初始化 (1)comN_Init(com_mode)

a) 參數 : com_mode COM_FDUPLEX – 全雙工 COM_HDUPLEX – 半雙工

b) 使用範例 : ( 以下皆以 COM3 為例 )

#include <stdio.h>#include <roboard.h>void main(void) { roboio_SetRBVer(…); com3_Init(COM_HDUPLEX); …}

COM port 初始化 (2)c) 函數回傳 :

true – 初始化成功false – 初始化失敗

d) 印出失敗訊息 :

if(com3_Init(COM_HDUPLEX) == false) printf(“%s”, roboio_GetErrMsg());

COM port 關閉 comN_Close()

a) 使用範例 :

b) 函數回傳 : 無

#include <stdio.h>#include <roboard.h>void main(void) { roboio_SetRBVer(…); com3_Init(COM_HDUPLEX); … com3_Close();}

設定 COM Port 傳輸格式(1)

AX-12 datesheet :

設定 COM Port 傳輸格式(2)

comN_SetFormat(bsize, sbit, parity)a) 參數一 : bsize

COM_BYTESIZE5 – 1 個 byte 為 5 bitCOM_BYTESIZE6 – 1 個 byte 為 6 bitCOM_BYTESIZE7 – 1 個 byte 為 7 bitCOM_BYTESIZE8 – 1 個 byte 為 8 bit

b) 參數二 : sbitCOM_STOPBIT1 – 使用 1 個停止位元COM_STOPBIT2 – 使用 2 個停止位元

c) 參數三 : parityCOM_NOPARITY – 不使用同位COM_ODDPARITY – 使用奇同位COM_EVENPARITY – 使用偶同位

設定 COM Port 傳輸格式(3)

d) 使用範例 :

#include <stdio.h>#include <roboard.h>void main(void) { roboio_SetRBVer(…); com3_Init(COM_HDUPLEX); com3_SetFormat(COM_BYTESIZE8, COM_STOPBIT1, COM_NOPARITY); …

com3_Close();}

設定 COM Port Buadrate(1)AX-12 伺服馬達支援的 baudrate :

設定 COM Port Buadrate(2)comN_SetBaud(baud)

a) 參數 : baudCOMBAUD_748800BPSCOMBAUD_499200BPS -> RB-110 連接 AX-12 的速度上限COMBAUD_249600BPSCOMBAUD_115200BPS -> RB-100 連接 AX-12 的速度上限COMBAUD_57600BPSCOMBAUD_38400BPSCOMBAUD_19200BPSCOMBAUD_9600BPSCOMBAUD_4800BPSCOMBAUD_2400BPSCOMBAUD_1200BPSCOMBAUD_300BPSCOMBAUD_50BPS

設定 COM Port Buadrate(3)b) 使用範例 :

#include <stdio.h>#include <roboard.h>void main(void) { roboio_SetRBVer(…); com3_Init(COM_HDUPLEX); com3_SetFormat(COM_BYTESIZE8, COM_STOPBIT1, COM_NOPARITY); com3_SetBaud(COMBAUD_9600BPS); …

com3_Close();}

傳送 & 接收Datasheet 中的範例之一 : 讀取 ID = 1 的馬達溫度

使用 COM Port 傳送資料comN_Send(array, number)

a) 參數一 : array – 傳送資料的陣列名稱b) 參數二 : number – 要傳送的封包 (byte) 數c) 使用範例 : COM3 傳送 8 byte data

#include <stdio.h>#include <roboard.h>void main(void) { unsigned char send_data[11] = {0xff, 0xff, 0x01, 0x04, 0x02, 0x2b,

0x01, 0xcc, 0, 0, 0}; // SetRBVer & Init & SetFormat & SetBaud … com3_Send(send_data, 8); …}

使用 COM Port 接收資料comN_Receive(array, number)

a) 參數一 : array – 接收資料的陣列名稱b) 參數二 : number – 要接收的封包 (byte) 數c) 使用範例 : COM3 接收 7 bytes 資料

#include <stdio.h>#include <roboard.h>void main(void) { unsigned char get_data[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // SetRBVer & Init & SetFormat & SetBaud … com3_Receive(get_data, 7); …}

傳送 & 接收注意事項COM2 :

使用 com_Receive() 時不會收到 com_Send() 的資料COM3 & COM4 :

使用 com_Receive() 時會收到 com_Send() 的資料 , 必須先將 com_Send() 送出的 data 讀完 , 才能讀到馬達回傳的 data

使用 COM Port 控制 Serial 伺服馬達(1)

comN_ServoTRX(carray, csize, barray, bsize)a) 參數一 : carray – 傳送馬達指令的陣列名稱b) 參數二 : csize – 要傳送的封包 (byte) 數c) 參數三 : barray – 接收馬達回傳資料的陣列名稱d) 參數四 : bsize – 要接收的封包 (byte) 數 ( 不包含

RoBoard TX 送出的 byte 數 )

使用 COM Port 控制 Serial 伺服馬達(2)

d) 使用範例 : COM3 ping AX-12 伺服馬達

#include <stdio.h>#include <roboard.h>void main(void) { unsigned char send_data[11] = {0xff, 0xff, 0x01, 0x04, 0x02, 0x2b, 0x01, 0xcc, 0, 0, 0}; unsigned char get_data[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // SetRBVer & Init & SetFormat & SetBaud … com3_ServoTRX(send_data, 8, get_data, 7); …}

Bioloid AX-12 範例#include <stdio.h>#include <roboard.h>int main(void) { unsigned char send_data[11] = {0xff, 0xff, 0x01, 0x07, 0x03, 0x1e, 0x00, 0x02, 0x00, 0x02, 0x00}; int i; unsigned char get_data[6]; roboio_SetRBVer(RB_100); com4_Init(COM_HDUPLEX); com4_SetFormat(COM_BYTESIZE8, COM_STOPBIT1, COM_NOPARITY); com4_SetBaud(COMBAUD_115200BPS); send_data[10] = ~(send_data[2] + send_data[3] + send_data[4] + send_data[5] + send_data[6] + send_data[7] + send_data[8] + send_data[9]); com4_ServoTRX(send_data, 11, get_data, 6); for(i=0; i<6; i++) printf(“%d. read data = %d\n”, i, get_data[i]); com4_Close(); return 0;}

USB2DynamixelDynamixel SDK 是由 ROBOTIS 所發布的開放源

碼,可透過 USB2Dynamixel 由 PC 端 USB 連接至 Servos 。

USB2Dynamixel 可將 PC 端 USB 訊號轉成 TTL、 RS485 以及 RS232 。

Dynamixel SDK for RoBoardDynamixel SDK for RoBoard 則是將

Dynamixel SDK 移植到 RoBoard 的 Serial Port 上,讓使用者可直接透過 RoBoard 的 Serial

Port 連接 Dynami-xel servos ,省掉中間的轉接器。

Installation解壓縮 “ Dynamixel SDK for RoBoard.rar”

在不同版本的資料夾中: bin: 函式庫的二位元檔案; example: 與原始 Dynamixel SDK 相同的範例程式碼; src: 函式庫的程式碼。

VS2008 專案中的設定在建立 VS2008 的新專案之後,請先行設定新專案

的屬性。

VS2008 專案中的設定設定 Additional Include Directories :

路徑 1: “using COM3” 中的 “ src” ; 路徑 2: RoBoIO 資料夾中的 “ Include” 。

VS2008 專案中的設定設定 Additional Library Directories :

路徑 1: “using COM3” 中的 “ bin” ; 路徑 2: RoBoIO 資料夾中的 “ Lib”。 .

VS2008 專案中的設定設定 Additional Dependencies :

檔案 1: 加入 Dynamixel_DLL_COM3.lib ; 檔案 2: 加入 RoBoIO_DLL.lib 。

Dynamixel SDK for RoBoad

使用者端軟體

Dynamixel SDK for RoBoad

使用者端軟體

硬體抽象層

Dynamixel SDK for RoBoad

使用者端軟體

硬體抽象層

硬體驅動程式

Dynamixel SDK for RoBoad

使用者端軟體

硬體抽象層

硬體驅動程式

硬體

Dynamixel SDK for RoBoad

使用者端軟體

硬體抽象層

硬體驅動程式

硬體

Include Header files……

#include "dynamixel.h"

#include "roboard_dll.h“

……

int main()

{

roboio_SetRBVer(…);

……

// use API of Dynamixel SDK here

……

}

RB_100 or RB_110

基本函式使用介紹dxl_initialize()

開啟對應的 COM Port 並進行初始化設定,執行成功回傳 1

,失敗則回傳 0 。使用範例:

int main() {

roboio_SetRBVer(…);

if( dxl_initialize() )

printf( "Succeed to open COM Port !\n" );

else

printf( "Failed to open COM Port !\n" );

……

}

基本函式使用介紹dxl_terminate()

關閉由 dxl_initialize() 開啟的 COM Port 。

使用範例:int main(){

......dxl_terminate();

return 0;}

基本函式使用介紹dxl_set_baud( int baudnum )

設定 baudnum 指定 RoBoard 端傳輸速率。dxl_get_baud()

取得目前傳輸速率的 baudnum ,如尚未設定則回傳 0xff 。使用範例:

If( dxl_get_baud()==0xff )

dxl_set_baud( 16 ); // Set 115200 bps

COM Port 傳輸速率由於 Dynamixel SDK for RoBoard 是透過 RoBoIO

來控制 COM Port ,所以 baudnum 對應之傳輸速率與原始的 Dynamixel SDK 稍有不同。

Baudnum Set BPS Target BPS Tolerance

3 499200 500000 0.16 %

7 249600 250000 0.16 %

16 115200 115200 0.00 %

34 57600 57600 0.00 %

103 19200 19200 0.00%

207 9600 9600 0.00 %

基本函式使用介紹dxl_read_byte( int id, int address )

從 Servo 的 EEPROM 和 RAM 中讀取一個 byte 的值。dxl_write_byte(int id,int address,int value) 將 value 寫入 EEPROM 和 RAM 中,一次寫入一個 byte

。使用範例:int pos;

pos = dxl_read_byte( ID, 36) + dxl_read_byte( ID, 37) *

0x100;

dxl_write_byte( ID, 3, NEW_ID );

基本函式使用介紹dxl_read_word( int id, int address )

從 Servo 的 EEPROM 和 RAM 中一次讀取 2 個 bytes 的值。dxl_write_word(int id,int address,int value)

將 value 拆成 2 個 bytes 一次寫入 EEPROM 和 RAM 中。

使用範例:

int pos;

pos = dxl_read_word( ID, 36 );

dxl_write_byte( ID, 30, NEW_POS );

API Reference

其餘的 API 為獲得 Servo 的狀態、工具函式以及收發 packet 的 API ,其使用方式請參考

ROBOTIS e-Manual

-> Software Help -> Dynamixel SDK -> API Reference

範例程式 SyncWrite.cppDynamixel SDK Dynamixel SDK for RoBoard

// Windows version

#include <windows.h>

……

#include "dynamixel.h"

……

int main()

{

......

}

// Windows version

#include <windows.h>

……

#include "dynamixel.h"

#include "roboard_dll.h“……

int main()

{

……

roboio_SetRBVer(…);……

}

COM Lib of RoBoIO在 RoBoard 上除了使用 Dynamixel SDK for

RoBoard 可以控制 Dynamixel Servos ,也可以直接使用 COM Lib 經由 Serial Port 收發訊號。

Dynamixel Servos 的 Packet 格式可參考 Servo 的 Manual。

Dynamixel RX-28在 RoBoard 官網上的 Code & Video 可以下載利用 COM2 控制 Dynamixel RX-28 的範例程式。

Dynamixel RX-28RBSample_RX28:

bin:

二位元檔案。 RoBoIO:

Header files 和 Library 檔案。 VC2005CE:

可在 winCE 下運作的 VS2005

的專案檔。

Dynamixel RX-28RBSample_RX28:

VC2005XP:

在 winXP 下運作的 VS2005

的專案檔。 Make.LINUX:

Linux 系統下的 gcc Makefile

檔案。 RX28_C2.cpp:

範例程式碼。

RBSample_RX28範例程式 RX28_C2.cpp 中,使用 COM Lib 控制 RX-28 的程式流程:

Question ?