Tuesday, December 7, 2010

[KTX-PC] Serial Communication

1         Overview

The CPU board, VS-RC003, on the KTX robots has Serial Communication feature, which allows user to operate your robot by your own software by sending commands to read and write its memory space.

2         Setting up CPU Board

2.1       Preparing RM2 and Firmware

Following items are required for this serial communication feature.
-          RobovieMaker2 version 1.0.0.9 or later
-          CPU board firmware version 13 or later
To check your version of RM2, go to “Help -> About RobovieMaker2”.
To check your version of Firmware, go to “Project preference -> CPU preferences”
If your version of the software or the firmware is too old, please download and install the latest version.

2.2       Changing setting of the CPU board

To activate serial communication on the CPU board, it is required to change the setting of CN6 or CN7.
First, start RM2 and establish connection, then click on “Project preference -> CPU preference”.   On the new window comes up, you will find “Serial Setting”.  Please change the communication type of the port you are using to “Command Port”.  It will not allow you to set both CN6 and CN7 to “command port”.
After changing the settings, click on “Apply” and transfer the preference to CPU board.

2.3       Specification of the Serial communication Port

If you are connecting external micro controller board to the CPU board, you will need to at least connect TXD, RXD, and GND. 

Cable Color
CN6 (Game Controller Port)
CN7 (Expansion board connector port)
P1
Brown
P0.8/TXD1
P0.0/TXD0
P2
Red
P0.9/RXD1
P0.0/TXD0   
P0.1/RXD0 + P0.25/AD0.4/Aout
P3
Orange
P0.5/MISO0
P0.1/RXD0 + P0.25/AD0.4/Aout
Reset
P4
Yellow
P0.6/MOSI0/CAP0.2
P0.14/EINT1/SDA1
P5
Green
P0.7
P0.2/SCL0
P6
Blue
P0.4/SCK0/CAP0.1
P0.3/SDA0
P7
Purple
VBATTD
VBATTD
P8
Grey
+5V
+5V
P9
White
+3.3V
+3.3V
P10
Black
GND
GND

2.4       Port Setting

Following is the setting of Serial communication port
  • Baud rate:  115200bps
  •  Data bit:  8
  •  Parity: NONE
  •  Stop Bit: 1

3         Setting up VS-IX003

For KTX-Lite, KTX-17, and KTX-Gladiator, you will need an expansion board, VS-IX003, to operate serial communication. 
If you are using KTX-PC series, the robot already have an embedded Serial communication board on the I/O board.   Therefore, there is no additional device required for serial communication on KTX-PC.

3.1       Installing Driver

3.2       Connecting VS-IX003

4         Communication Protocol

Basically, you will write and read 1 byte of data in the memory space inside CPU board.
Variable number 64 to 127 is the space for user defined variables.  Please do not overwrite other memory spaces, unless you know what you are doing.

You can download PDF version of this memory map here.

 

4.1       Character, Prompt, and Sending command

The message used in the communication is 1 byte.  After sending the message, the CPU board will echo back the command you have sent.  The prompt character is “#”.  To process the sent command, you will send 2 byte message, CR+LF (‘\r\n’ or 0x0A, 0x0D).

4.2         Values and Endian

The value (numbers) inside the communication message is always written in hexadecimal.   It is not case sensitive.  Please describe the representation of characters in minimum of 1 byte (2 characters). 
Additionally, Memory map in the CPU board follows the little endian.  Since each variable defined in the CPU board uses 2 bytes, you will first write lower byte and then write upper byte.  For example, if you are writing “0x1234” and “0x5678” into consecutive variables, you will send the command in the order of “0x34, 0x12, 0x78, 0x56”.
Moreover, if you receive 2 byte of data, “0xABCD”, the correct reading will be “0xCDAB”.

4.3        Writing values into Memory

The command to write the value to specific address of memory is given below.
w XXXXXX YY ZZ…\r\n
Write commands always begin with the symbol “w”. 
“XXXXXX” represents the address to write to, written in 6 digits hexadecimal. 
“YY” and “ZZ” are the data you will be writing, and you can separate each 1byte of value by space.  If you are sending series of values, make sure that there is one or more space between the 1 byte values. 
After sending the data, send “\r\n” to process the command.     

4.4         Reading values from Memory

The command to read the values from specific address of memory is given below.
r XXXXXX YY\r\n
Read commands always begin with the symbol “r”. 
“XXXXXX” represents the address to write to, written in 6 digits hexadecimal. 
“YY” is the value to specify the size of the data you will be reading. 
After sending the data, send “\r\n” to process the command.     
Once the command is processed, you will receive a message from CPU board.
# XXXXXX ZZ ZZ….
“#” is a prompt, and “XXXXXX” is the address and “ZZ ZZ….” Is the data you got from CPU board.
Example:
Send r 2009ea 05
Return #2009ea 00 00 00 00 00

4.5       Address of Memory Map

The relation between the address we will use in the communication message and the numbering of the variables are following.
Fist, the starting address of the memory map of the variables is “200800”.
The memory map has 256 variable spaces of 0 ~ 255 and one variable space is signed 2 bytes.  Therefore, the size of the memory space is 256 x 2 = 512 byte.
The address corresponding to the variable in memory map can be calculated as “200800 + [variable number]”.
For example, the address of the user definable variable space #119 (hexadecimal number of 119 is 77) is “200800 + 77 x 2 = 2008ee”.
To write the value, “0x3d10”, into the variable #119, you will send the write command, “w 2008ee 10 3d\r\n”.  Also, to read the variable #132 (Gyro sensor value for x coordinate), you will send command, “r 200908 00 00\r\n”

5         Controlling Robot by Serial Communication

This section will describe how to operate a robot through serial communication by simulating game controller inputs.
This approach will overwrites the values of the memory map of the game controller input (variable number of 241, 244 ~ 247).

5.1       Setting up RM2 and Starting up Robot

First, please transfer any remote operation map into your robot.  You can use sample remote operation map or your own operation map.  The motion data assigned to the map can be any motion data you have.  Also, please set the “mode switch” to the mode you assigned your operation map.  Make sure that the USB cable is unplugged, and then, start your robot.

5.2       Starting and Stopping Serial Communication 

First, to start serial communication, you write “0x000” in the address “0x2009e0” (variable number 240).  Once you configure the communication port to serial communication, the command sent from remote controller will be ignored.
To end serial communication, you will write “0x0001”. 
w 2009e0 00 00\r\n         :               start serial communication
w 2009e0 01 00\r\n         :               Stop serial communication and return its control
Due to endianness, the upper byte and lower byte are reversed.

5.3       Turning ON/OFF Servo Motors

To turning on and off servo motors, you will write into the address “0x2009f6” (variable number 251). 
w 2009f6 01 00\r\n          :               servo motor on
w 2009f6 00 00\r\n          :               servo motor off

5.4       Simulating Remote Control Inputs

To simulate remote control button inputs, you will write into the address “0x2009e2” (variable number 241).
[Upper byte]
0
0
0
0
0
0
0
0
Left
Down
Right
Up
Start
R3
L3
Select

[Lower byte]
0
0
0
0
0
0
0
0
Square
Cross
Circle
Triangle
R1
L1
R2
L2

w 2009e2 10 00\r\n         :               Triangle button is activated
w 2009e2 04 10\r\n         :               L1 and Up button is activated
Once you write a value in the address, it will save the value until you write another value in it.  Therefore, please write “0x000” to the address when you finish the motion.

5.5       Analog Stick Inputs

To simulate analog stick inputs, you will write in the address “0x2009e8” ~ “0x2009ee” (variable number 244 ~ 247).  The value can be the range from -128 to 127 (0xff80 ~ 0x007f). 

5.6       Getting Status of Operation Map

You can retrieve the status of the operation map by reading following addresses.
Address “0x2009f0”        :               Map number of current operation map (0 ~ 3)
Address “0x2009f4”        :               Status of analog stick (0 = disabled, 1 = enabled)
Address “0x2009fa”        :               Status of the motion playing (0 is idling, 1 is playing)

5.7       Example Play Motion Command

w 2009e0 00 00\r\n             :               Take over the control for serial communication
w 2009f6 01 00\r\n              :               Turning on the servo motors
w 2009e2 10 00\r\n             :               Simulate triangle button input ON
w 2009e2 10 00\r\n             :               Simulate triangle button input OFF
w 2009e0 01 00\r\n             :               Return the control

5 comments:

  1. Hi Masahiro-sama,
    thanks for a very helpful blog post!
    I am working on interfacing a VS-RC003 with a zigbee radio so I'll be connecting to CN6 as you describe in section 2.3
    Do you know if the VS-RC003's UART uses 3.3v or 5v logic levels ? It looks like the VS-IX003 serial comm board uses a SiLabs cp2102 chip - suggesting 3.3v levels, but if you know for sure it would be helpful to have confirmation.
    Thanks,
    Zachary

    ReplyDelete
  2. Hi Zachary,
    I found an example for creating bluetooth expansion board for VS-RC003.
    http://lets-robot.com/modules/roboviemaker2/index.php?id=41
    It is written in Japanese...

    If you follow the same wire system as other expansion board,
    - Brown: RX
    - Red: TX
    - White: 3.3V
    - Black: GND

    As you mentioned, please use 3.3V logic level.
    I have not deeply look into it yet, but 3.3V logic level should work.

    Thanks

    ReplyDelete
  3. Thank you for the response!
    That article looks helpful, and it is good to have confirmation. One other question; do you know where I can find the latest version of RobovieMaker2 in English? I am currently running version 1.0.0.8 which does not have the serial feature (as you mention, version 1.0.0.9 or later is needed).
    Cheers,
    Zachary

    ReplyDelete
  4. Currently all the software and files are under protected directory.
    I will move some files to the non protected folder for you.
    or,
    If you can send me email, I can send email back to you with the latest RM2.

    If you purchased your robot from us, send me email with your name and copy of your invoice.
    I will give you the password.

    masahiroATkumotek.com

    Thanks,
    Masahiro

    ReplyDelete
  5. Now, only protected source is things related to SDK. Everything else is all accessible to anybody!!!

    ReplyDelete