There are a lot of possible combinations of hardware, firmware and languages for programming Bioloid. I think that the table below show the the main combinations.
You can choose from the easy but limited Robotis own tool (Roboplus Task) and only your CM-5 or CM-510 to a SBC or “embedded” PC like Roboard and any language which can manage a serial port connection, like C, C++, Java, Python,…
Programming Bioloid: choose hardware, firmware and languages
Robotis oficially supports the programming solutions with the blue background:
The dark blue, RoboPlus Tasks , is the only one in which you can create the motions with RoboPlus Motion and execute it in CM-5/CM-510 with the program create with RoboPlus Tasks, after downloading the generated executable into the CM-5/CM-510, of course.
The clear blue, Embedded C SDK and Dynamixel SDK , are two distinct SDK offered and supported by Robotis, but currently there is no command to execute the motions created with RoboPlus Motion .
Using a PC, SBC (Single Board Computer), PDA, Mobile or other light and battery powered computer
Using a serial port connection with your more beloved programming language:
USB2Dynamixel
If you have any device with a USB host and a FTDI driver you can use USB2Dynamixel to command programatically your Dynamixel servos using the Dynamixel protocol . You only will need your CM-5 or CM-510 to connect your Dynamixel to the battery.
Serial port cable
Same as the previous option but instead of using the USB2Dynamixel you only will need the serial cable and the “Toss Mode” launched with the ‘t' command from the “Manage Mode”
Wireless control
Instead of only sending and receiving data, with the previous wireless connections you can command remotely your robot using the standard firmware and the “Toss Mode” launched with the ‘t' command from the “Manage Mode”. You will need to command it using the Dynamixel protocol .
With these options and the CM-510 you will find a little problem… there is no way to read your sensor values! Well, you can use this firmware that offers a “Toss Mode” that supports reading CM-510 ports.
The intent of this code is to be clear and easy to understand, it not pretend to be the best code to do the job. By the way, this great HTML formatting has been created with http://www.bedaux.net/cpp2html
This method create the command to read the position. :
int Dynamixel::getReadAX12PositionCommand(byte id)
{
//OXFF 0XFF ID LENGTH INSTRUCTION PARAMETER1 …PARAMETER N CHECK SUM
int pos = 0;
buffer[pos++] = 0xff;
buffer[pos++] = 0xff;
buffer[pos++] = id;
// length = 4
buffer[pos++] = 4; //placeholder
//the instruction, read => 2
buffer[pos++] = 2;
// pos registers 36 and 37
buffer[pos++] = 36;
//bytes to read
buffer[pos++] = 2;
byte checksum = checkSumatory(buffer, pos);
buffer[pos++] = checksum;
return pos;
}
And this one will send the command to the Dynamixel bus:
int Dynamixel::getPosition(SerialPort *serialPort, int idAX12)
{
int ret=0;
int n=getReadAX12PositionCommand(idAX12);
long l=serialPort->sendArray(buffer,n);
Sleep(2);
memset(bufferIn,0,BufferSize);
n=serialPort->getArray(bufferIn, 8);
short pos = -1;
if (n>7)
{
pos = fromHexHLConversion(bufferIn[5], bufferIn[6]);
}
if (pos<0 || pos > 1023)
ret=-2;
else
ret=pos;
return ret;
}
This is the main block of a simple Dynamixel example program using serial port.
Do you want to use the usb2dybnamixel? Changing it will be very easy.
int _tmain(int argc, _TCHAR* argv[])
{
int error=0;
int idAX12=17;
SerialPort serialPort;
Dynamixel dynamixel;
if (serialPort.connect(L"COM1")==0) {
dynamixel.sentTossModeCommand(&serialPort);
int pos=dynamixel.getPosition(&serialPort, idAX12);
if (pos>250 && pos <1023)
dynamixel.setPosition(&serialPort, idAX12, pos-100);
else
printf ("\nPosition <%i> under 250 or over 1023", pos);
serialPort.disconnect();
}
else {
printf ("\nCan't open serial port");
error=-1;
}
return error;
}
The C “Hello World” servo program is based in the original Robotis example.
4.- You should create a folder for your CM-5 program, for example c:\myprojects\cm5\helloworld Copy there the previously downloaded helloworld.zip and unzip it.
When loaded you should see an screen with two equal values as a correct "Checksum" check (in this example the value is 81, it's calculated from the source code). If the values are not equal there is an error in the transmission.
5.- Every time you press the red MODE button the servo should spin
My main Bioloid project is to build a robot that will have some interesting (non easily predictable but reasonable) behaviours.
I think that the source code and some comments could be used as help or an advanced tutorial about programming and ATMega with C.
AntOne 3.6 is based in a PDA that has the software for the behaviour and a CM-510 (ATMega 2561) that control the hardware (servos and sensors). But I discovered that standard CM-510 firmware has no command to get sensor values, so I programmed another with that function. But then I thought that it would be interesting to embed some perception functions in the CM-510.
Bioloid controllers, CM-5(ATMega128) and CM-510 (ATMega2561), and Arduino (ATmega168) use very similar ATMega microcontrollers, so it's easy to use Arduino to control AX-12 servos.
But, obviously, yo should have a working knowledge about ATMega microcontrollers programming.
You can get detailed information and source code in the next links:
From time to time I receive questions about how to start programming the CM-5/CM-510 with C.
I think it’s necessay to have a working knowledge about:
1. C programming
2. CM-5/CM-510 programming
3. Dynamixel protocol
1. C programming
I think “C Programming for Microcontrollers
is a fast and very practical introduction to C and microcontrolers
programming, but I’m a not sure if it an easy way to start learning C.If
you a want a more structured and deeper introduction to the C
programming language, this is a pretty good and free introduction:
I’m creating a little program for the CM-510 that could be used
to get sensor values from a PC (or other extern controller) with the
standard dynamixel protocol and with :
- the usb2dynamixel and any language you want that supports serial comms or using the Robotis libraries (C, C++, Java, C#, …)
- or the standard serial cable and any language that support serial communications
This program set the CM-510 (with their sensors) as if it were another standard dynamixel itemthat you can query.
You should get used to the WinAVR environment, it uses “make”,
and a must is to know the AX12+ protocol and the some knowledge about
programming ATMega128.
The next few lines are the core to positioning an AX12+ motor with
the C programming language:(It requires some communication and
interruption initialization functions, below you can download the full
example)
gbpParameter[0] = P_GOAL_POSITION_L; //Address of goal
gbpParameter[1] = 0×00; //Writing Data P_GOAL_POSITION_L
gbpParameter[2] = 0×02; //Writing Data P_GOAL_POSITION_H
gbpParameter[3] = 0×00; //Writing Data P_GOAL_SPEED_L
gbpParameter[4] = 0×01; //Writing Data P_GOAL_SPEED_H
bTxPacketLength = TxPacket(bID,INST_WRITE,5);
bRxPacketLength = RxPacket(DEFAULT_RETURN_PACKET_SIZE);
TxPacket uses the global gbpParameter array to receive the parameters, and bID is the AX12+ ID to move.
You should have a working knowledge about the AX12+ protocol explained “AX-12.pdf“, you should have understood the chapter “9. Information for Advanced Users” from the “Bioloid User’s Guide.pdf” (version 1.0, because it’s not included in later versions).
You can download helloworld project for “Programmers Notepad [WinAVR]” (zip). It’s the Robotis example but splitted in 3 files for clearity and modularity:
1.Declarations from Robotis in “robotis.h”
2. The body of the functions in “robotis.c”
3. The most simple example that moves the AX12+ servo with id 15 to position 512, in “helloworld.c”
[Spanish/Español]
Manejar el entorno WinAVR, que a su vez utiliza make, conocer el protocolo de los AX12+ y programación del ATMega128.
Para mover un motor desde el CM-5 en C el meollo sería este trozo (extraído del ejemplo de Robotis):
gbpParameter[0] = P_GOAL_POSITION_L; //Address of goal
gbpParameter[1] = 0×00; //Writing Data P_GOAL_POSITION_L
gbpParameter[2] = 0×02; //Writing Data P_GOAL_POSITION_H
gbpParameter[3] = 0×00; //Writing Data P_GOAL_SPEED_L
gbpParameter[4] = 0×01; //Writing Data P_GOAL_SPEED_H
bTxPacketLength = TxPacket(bID,INST_WRITE,5);
bRxPacketLength = RxPacket(DEFAULT_RETURN_PACKET_SIZE);
Pero antes requiere unas cuantas funciones de inicialización de interrupciones y comunicaciones. TxPacket utiliza el array global gbpParameter para recibir los parámetros y bID es el ID del AX12+ a mover.
Un requisito previo es tener claro el protocolo de los AX12+, manual “ AX-12(english).pdf “, y haberse estudiado el tutorial de Robotis del capítulo “ 9. Information for Advanced Users ” del manual “ Bioloid User's Guide.pd f” (versión 1.0, ya que en las posteriores no se ha incluido).
Adjunto proyecto helloworld hecho con el “Programmers Notepad [WinAVR]” en un zip. Es el ejemplo de Robotis pero en tres ficheros:
1.Las declaraciones de robotis en “robotis.h”
2.El cuerpo de las funciones de robotis en “robotis.c”
3.El ejemplo más sencillo posible, mueve el motor con id 15 a la posición 512, en “helloworld.c”
April 27th, 2008
[Español]
En este blog iré incluyendo todo lo que he aprendido sobre cómo programar Bioloid.
- Conectado a un PC mediante cable serie o USB2Dynamixel. En C, C++, C# y Java
- En C en el propio CM-5.
Además de información no documentada pero incluida en el firmware como Toss mode y Monitor.
[English]
In this blog I will be including everything what I have learned on how programming Bioloid.
- Connected to a PC by means of serial cable or USB2Dynamixel In C, C++, C# and Java
- In C on the CM-5 Besides information not documented but included in the firmware like Toss mode and Monitor.