Mostrando entradas con la etiqueta Modular kits. Mostrar todas las entradas
Mostrando entradas con la etiqueta Modular kits. Mostrar todas las entradas

domingo, 16 de junio de 2013

Robotis CM-900 in Toss Mode and querying connected sensors

CM-900 is a very cheap and tiny Robotis Dynamixel controller based in the STM32 ARM 32 bits microcontroller. Here you can find several links to documents.

CM-900_Size

I think it's ideal as a controller managed with, for example, a Raspberry Pi or a Pandaboard, so I have created a program which can be managed externally to control Dynamixel items (AX-12, AX-S1), Toss Mode, and sensors connected to the CM-900 with a simple protocol similar but simpler than the Dynamixel protocol:

[Headers] [ID] [Command code] [Nº Params] [Param1] [Param2] [ParamN]

Toss Mode works like USB2Dynamixel, but with this program in addition you can get sensor vales.

Toss Mode was a software feature, at least since CM-5, which allows you to use the elements connected to the controller from another device, usually a more powerful computer. What it receives from the USB or serial is sent to the Dynamixel bus, and whatever it receives from Dynamyxel bus is sent to the serial or USB connection.

Example for blinking twice: { 0xFF, 0xFF, 90, 1, 1, 2 }

Headers: 0xFF 0xFF

ID: 90

Command code: 1

Number of parameters: 1

Parameter 1: 2

Example for reading ultrasonic sensor (HC-SR04) : { 0xFF, 0xFF, 90, 2, 0 }

[sourcecode language="CPP"]

void MainWindow::testCM900_Sensor_US()
{
const int size=5;
byte buffer2[size] = { 0xFF, 0xFF, 90, 2, 0 };
pDynComm->rawWrite(buffer2, size);
}
[/sourcecode]

[caption id="attachment_1753" align="alignleft" width="320"]Ultrasonic sensor hc-sr04 Ultrasonic sensor hc-sr04[/caption]

And here the file with the code for Robotis CM-9 IDE version 0.9.9. You also need to copy Prof. Mason library for ultrasonic sensor to CM 900 IDE libraries folder. Althought it i still a beta version, I think it works ok. Asigning true to these variables, the messages for debugging are sent either to USB connection o Serial2 (connecting Zigbee is the easy option):

[sourcecode language="CPP"]
bool debugOutputSerial2On=true;
bool debugOutputOn=false;
[/sourcecode]

miércoles, 12 de junio de 2013

Robotis CM-900 as a tosser for Dynamixel commands

CM-900 is really tiny and cheap, so is perfect to use as communication bridge between any computer (Raspberry Pi, Pandaboard, etc. included, of course) and the Dynamixel bus. Whatever it receives from the Serial USB (usually commands and queries) is sent to the Dynamixel bus, and what it receives from the Dynamixel bus is sent to the SerialUSB (usually answers)

Here is the source code of the little program for CM-900 IDE:

[sourcecode language="C"]
int counter;
bool onlyOnceHappened;

void blinkOnce()
{
digitalWrite(BOARD_LED_PIN, LOW);
delay_us(100);
digitalWrite(BOARD_LED_PIN, HIGH);
}

void setup()
{
pinMode(BOARD_LED_PIN, OUTPUT);

onlyOnceHappened=false;
counter=0;

//USB Serial initialize
SerialUSB.begin();
// SerialUSB.attachInterrupt(USBDataReceived);
//DXL initialize
Dxl.begin(1);
}

byte aByte=0;
uint8 aUint8;

void loop()
{
// SerialUSB.println (counter++);

if (onlyOnceHappened==false)
{
blinkOnce();
onlyOnceHappened=true;
delay (3000); //Some time to the user to activate the monitor/console
SerialUSB.println ("v1.1.1 Orders receiver started");
}

if (SerialUSB.available())
{
aUint8=SerialUSB.read();
blinkOnce();
Dxl.writeRaw(aUint8);
// delay(20);
}

if (Dxl.available())
{
aByte=Dxl.readRaw();
blinkOnce();
SerialUSB.write(aByte);
// delay(20);
}
}

[/sourcecode]

Here the file.

In the next post I will include an improved version that could read sensors connected to the CM-900, "expanding" the Dynamixel protocol.