Hello Kondo!

I’m sure the marketing department will tell you that the Kondo KHR-1 is a programmable humanoid robot capable of amazing feats.

It looks humanoid. It’s programmable – via the RCB-1 board mounted on its back. It’s certainly a robot. However, in its current state it’s nothing more than a bunch of servos held together by aluminum brackets. Only through programmability can we bring it to life.

Set aside your dreams of artificial intelligence for the moment. The first thing we need to accomplish is basic movement. The equivalent of a “Hello World!” app for the KHR-1 is the following:

Move the slider, move the head. Once you learn to move one servo, you can move many.

Communication between the PC and the RCB-1 happens through the serial port. If your computer (ie. laptop) doesn’t have a serial port, you can purchase a USB to serial port adapter.

Thankfully, the release of .NET 2.0 saw the introduction of a SerialPort class (found under the System.IO.Ports namespace). You can drag ‘n drop an instance of the SerialPort control from the Toolbox onto your Form. Here”s the Form constructor:


public Form1()
{
    InitializeComponent();
    this.serialPort1 = new System.IO.Ports.SerialPort();
    this.serialPort1.BaudRate = 115200;

    // change to whatever port # you're using
    this.serialPort1.PortName = "COM4";
    this.serialPort1.ReadTimeout = 30; // ms timeout

    try
    {
        serialPort1.Open();
    }
    catch(Exception e)
    {
        MessageBox.Show(e.Message + "nnBe sure to change the port # in code");
    }
}
 

If the serial port is successfully opened, trackbar events will be routed to the RotateHead method:


private void OnTrackbarScroll(object sender, EventArgs e)
{
    if (serialPort1.IsOpen)
        this.RotateHead((byte)this.trackBar1.Value);
}
 

To communicate with the RCB-1, fill an array of bytes and send them out the port. How do you know what bytes to send? A command reference PDF is available for download, however it’s not written in English. Fortunately, it has been translated. Here is page six from the RCB1stdraft.doc included with the download:

This page details the command used to send positional data to one or more servos. TX stands for transmission. An array of 16 bytes needs to be filled with the following information:

  • Byte 1 – The command. 0xFD to flag a servo position change.
  • Byte 2 – The board ID. The KHR-1 has two RCB-1 boards. One board controls servos 1-12, the other board controls servos 13-24.
  • Byte 3 – The servo speed. Eight speeds are supported with 0 being fastest and 7 the slowest.
  • Bytes 4-15 – The servo degree. There are 12 channels (corresponding to servos on either board) specifying the degree of rotation.
  • Byte 16 – A checksum. This is a value computed from the contents of the packet. The RCB-1 will calculate the checksum (given the contents) to determine if the data was sent correctly.

public void RotateHead(byte degree)
{
    byte[] by = new byte[16];
    byte command = 0xFD;
    byte boardId = 0;
    byte speed   = 0; // 0 = fastest, 7 = slowest

    by[0] = command;
    by[1] = boardId;
    by[2] = speed;

    // you can rotate the servos 0 to 180
    // so set unused channels to a value beyond this range
    by[3] = 255; // ch 1
    by[4] = 255; // ch 2
    by[5] = 255; // ch 3
    by[6] = 255; // ch 4
    by[7] = 255; // ch 5
    by[8] = degree; // ch 6 - the head on my kondo
    by[9]  = 255; // ch 7
    by[10] = 255; // ch 8
    by[11] = 255; // ch 9
    by[12] = 255; // ch 10
    by[13] = 255; // ch 11
    by[14] = 255; // ch 12
    by[15] = (byte)(command + boardId + speed + (255 * 11 + degree) & 0x7F);

    Trace.WriteLine("sending...");
    this.serialPort1.Write(by, 0, by.Length);
}
 

You can download the source here.

Leave a Reply