Legacy Forum: Preserving Nearly 20 Years of Community History - A Time Capsule of Discussions, Memories, and Shared Experiences.

RQ-HUNO Serial communication : newbie questions

Korean company maker of Robot kits and servos designed for of articulated robots. Re-incarnation of Megarobotics.
7 postsPage 1 of 1
7 postsPage 1 of 1

RQ-HUNO Serial communication : newbie questions

Post by RNope » Sun Jan 20, 2013 9:04 pm

Post by RNope
Sun Jan 20, 2013 9:04 pm

Hi all , thanks for this great forum !

After playing a bit with the recomon i finally managed to interface the RQ with MSRS v4 (after few infructuous tries)

Now i'd like to go a step further sending direct serial command to the robot (essentially for motion playing)
From what'v read i assume i can send direct Serial command like that :
Serial.write("xxxx xxxx xxxx xxxx ");
from almost any language (i tested it on processing as i knew how to establish a serial connection for sure from some arduino plays)


I'v read the "RBC over Serial" pdf but i still have (silly) questions :
(1) what does the numbers inside parenthesist mean ?
Header(8 )/Command Type (1)/Platform (1) /Command size (4) Command contents (1)


(2)What is "don't care" supposed to mean : put nothing ? put white space ?
0xFF 0xFF 0xAA 0x55 0xAA 0x55 0x37 0xBA 20 don't care 1 Motion No. CheckSum


(3)Assuming i'v started a serial connection at 115200bps on the proper COM port is it correct to send this command to play motion number 1
Serial.print("0xFF 0xFF 0xAA 0x55 0xAA 0x55 0x37 0xBA 20 1 1 CheckSum");
(with Checksum = 5A in that case if i'm correct assuming "don't care" means put nothing special)



I'm pretty sure it's the" format" : maybe i should'nt put the "0x" before the number if i follow this example
/forum/viewtopic.php?t=3269

I tried to do this in Processing , failed (no error but nothing happend) tried directly with hyper terminal without more success.


I'v spend a few days tring to have a better overview of all , this but as i don't have much (almost any) programmation skill there is something i must miss.
Please assume any very stupid mistake is possible :)

Thanks for any helpl !
Hi all , thanks for this great forum !

After playing a bit with the recomon i finally managed to interface the RQ with MSRS v4 (after few infructuous tries)

Now i'd like to go a step further sending direct serial command to the robot (essentially for motion playing)
From what'v read i assume i can send direct Serial command like that :
Serial.write("xxxx xxxx xxxx xxxx ");
from almost any language (i tested it on processing as i knew how to establish a serial connection for sure from some arduino plays)


I'v read the "RBC over Serial" pdf but i still have (silly) questions :
(1) what does the numbers inside parenthesist mean ?
Header(8 )/Command Type (1)/Platform (1) /Command size (4) Command contents (1)


(2)What is "don't care" supposed to mean : put nothing ? put white space ?
0xFF 0xFF 0xAA 0x55 0xAA 0x55 0x37 0xBA 20 don't care 1 Motion No. CheckSum


(3)Assuming i'v started a serial connection at 115200bps on the proper COM port is it correct to send this command to play motion number 1
Serial.print("0xFF 0xFF 0xAA 0x55 0xAA 0x55 0x37 0xBA 20 1 1 CheckSum");
(with Checksum = 5A in that case if i'm correct assuming "don't care" means put nothing special)



I'm pretty sure it's the" format" : maybe i should'nt put the "0x" before the number if i follow this example
/forum/viewtopic.php?t=3269

I tried to do this in Processing , failed (no error but nothing happend) tried directly with hyper terminal without more success.


I'v spend a few days tring to have a better overview of all , this but as i don't have much (almost any) programmation skill there is something i must miss.
Please assume any very stupid mistake is possible :)

Thanks for any helpl !
RNope
Newbie
Newbie
Posts: 5
Joined: Sun Jan 20, 2013 7:16 pm

Post by l3v3rz » Sun Jan 20, 2013 9:24 pm

Post by l3v3rz
Sun Jan 20, 2013 9:24 pm

Hi there !

The serial protocol is very similar/same as that for the 5710 which I know quite well now.

1) The numbers in parathenses are no. of bytes - i.e. 8 in the header
header (8) = 0xFF 0xFF 0xAA 0x55 0xAA 0x55 0x37 0xBA

2) don't care means put any byte value see 0x00 for instance - will affect checksum.

3) NO you cannot send it like that - you must send the raw bytes not a string
The 0x means HEX so 0xFF = 255 in decimal

To send you need to create an array of Bytes[] output - new Bytes[] {0xFF, etc } and then write bytes array.

Ive created a dll with a couple of classes to make life easier - http://robobuildervc.googlecode.com/fil ... derLib.dll

http://code.google.com/p/robobuildervc/ ... Cremote.cs

Code: Select all
public class PCremote
    {
        public SerialPort serialPort;
        byte[] header = new byte[] { 0xFF, 0xFF, 0xAA, 0x55, 0xAA, 0x55, 0x37, 0xBA };
        byte[] respnse = new byte[32];

etc......


There's some examples on the site of using kinnect and other stuff.

Have fun.
Hi there !

The serial protocol is very similar/same as that for the 5710 which I know quite well now.

1) The numbers in parathenses are no. of bytes - i.e. 8 in the header
header (8) = 0xFF 0xFF 0xAA 0x55 0xAA 0x55 0x37 0xBA

2) don't care means put any byte value see 0x00 for instance - will affect checksum.

3) NO you cannot send it like that - you must send the raw bytes not a string
The 0x means HEX so 0xFF = 255 in decimal

To send you need to create an array of Bytes[] output - new Bytes[] {0xFF, etc } and then write bytes array.

Ive created a dll with a couple of classes to make life easier - http://robobuildervc.googlecode.com/fil ... derLib.dll

http://code.google.com/p/robobuildervc/ ... Cremote.cs

Code: Select all
public class PCremote
    {
        public SerialPort serialPort;
        byte[] header = new byte[] { 0xFF, 0xFF, 0xAA, 0x55, 0xAA, 0x55, 0x37, 0xBA };
        byte[] respnse = new byte[32];

etc......


There's some examples on the site of using kinnect and other stuff.

Have fun.
l3v3rz
Savvy Roboteer
Savvy Roboteer
Posts: 473
Joined: Fri Jul 18, 2008 2:34 pm

Post by RNope » Mon Jan 21, 2013 8:56 pm

Post by RNope
Mon Jan 21, 2013 8:56 pm

Yeah, it works ! :D

The dirtyest possible way but it works :)

I put my nose in your librairy isolating
byte[] header = new byte[] { 0xFF, 0xFF, 0xAA, 0x55, 0xAA, 0x55, 0x37, 0xBA };

wich was not working with Processing so i converted every different hex separately and created the array afterward.

Code: Select all
import processing.serial.*;
 

//array header
byte a;
byte b;
byte c;
byte d;
byte e;

a = byte (0xFF);
b = byte (0xAA);
c = byte (0x55);
d = byte (0x37);
e = byte (0xBA);


byte[] header = {a, a, b, c, b, c, d, e};

// array inner
byte z;
byte y;
byte x;
byte w;

z = byte (20);
y = byte (0x00);
x = byte (0x01);
w = byte (1);

byte[] inner = {z, y, y, y, y, x, w ,w};
 
// The serial port:
Serial myPort;
 
// List all the available serial ports:
println(Serial.list());
 
// You may need to change the number in [ ] to match
// the correct port for your system
myPort = new Serial(this, Serial.list()[3], 115200);


myPort.write(header);
myPort.write(inner); 


When i said it was dirty ... :)
There must be a better way i'll have a look when more time.

Still there a few things i 'm some sure of as :
-(1) Why does the command number doesn't need to be converted in hex before byte conversion (i assume the byte(); function recognise the type of value wich is in ?)

-(2) It looks like checksum is alway the same as the command (cmd in your lib) I don't really understand why (all the rest = to 0 ?)

-(2) can i send infinite serial commands without worrying with the controler buffer size ?


I'm now on my way to get a response when the movement is finished with the help of your lib !

Thanks a lot for your ultra-fast answer !
Yeah, it works ! :D

The dirtyest possible way but it works :)

I put my nose in your librairy isolating
byte[] header = new byte[] { 0xFF, 0xFF, 0xAA, 0x55, 0xAA, 0x55, 0x37, 0xBA };

wich was not working with Processing so i converted every different hex separately and created the array afterward.

Code: Select all
import processing.serial.*;
 

//array header
byte a;
byte b;
byte c;
byte d;
byte e;

a = byte (0xFF);
b = byte (0xAA);
c = byte (0x55);
d = byte (0x37);
e = byte (0xBA);


byte[] header = {a, a, b, c, b, c, d, e};

// array inner
byte z;
byte y;
byte x;
byte w;

z = byte (20);
y = byte (0x00);
x = byte (0x01);
w = byte (1);

byte[] inner = {z, y, y, y, y, x, w ,w};
 
// The serial port:
Serial myPort;
 
// List all the available serial ports:
println(Serial.list());
 
// You may need to change the number in [ ] to match
// the correct port for your system
myPort = new Serial(this, Serial.list()[3], 115200);


myPort.write(header);
myPort.write(inner); 


When i said it was dirty ... :)
There must be a better way i'll have a look when more time.

Still there a few things i 'm some sure of as :
-(1) Why does the command number doesn't need to be converted in hex before byte conversion (i assume the byte(); function recognise the type of value wich is in ?)

-(2) It looks like checksum is alway the same as the command (cmd in your lib) I don't really understand why (all the rest = to 0 ?)

-(2) can i send infinite serial commands without worrying with the controler buffer size ?


I'm now on my way to get a response when the movement is finished with the help of your lib !

Thanks a lot for your ultra-fast answer !
RNope
Newbie
Newbie
Posts: 5
Joined: Sun Jan 20, 2013 7:16 pm

Post by l3v3rz » Mon Jan 21, 2013 11:12 pm

Post by l3v3rz
Mon Jan 21, 2013 11:12 pm

Great stuff - see below >>

-(1) Why does the command number doesn't need to be converted in hex before byte conversion (i assume the byte(); function recognise the type of value which is in ?)

>> The compiler will convert, so when it sees 0x it expects hex otherwise it expect decimal

-(2) It looks like checksum is always the same as the command (cmd in your lib) I don't really understand why (all the rest = to 0 ?)

>> Yes for simple 1 Bytes commands (the majority) that's all that's needed, its only for the longer commands you need to calculate it - i.e. setting zero values

-(3) can i send infinite serial commands without worrying with the controller buffer size ?

>> if you mean can use serial flow control XON/XOFF I'm not sure it may treat them as binary input, and I'm afraid I don't know how large serial buffer is in RQ-HUNO. Most cammands will respond, so as long as you wait until you have a 2 byte response, before sending next command you shouldn't have a problem
Great stuff - see below >>

-(1) Why does the command number doesn't need to be converted in hex before byte conversion (i assume the byte(); function recognise the type of value which is in ?)

>> The compiler will convert, so when it sees 0x it expects hex otherwise it expect decimal

-(2) It looks like checksum is always the same as the command (cmd in your lib) I don't really understand why (all the rest = to 0 ?)

>> Yes for simple 1 Bytes commands (the majority) that's all that's needed, its only for the longer commands you need to calculate it - i.e. setting zero values

-(3) can i send infinite serial commands without worrying with the controller buffer size ?

>> if you mean can use serial flow control XON/XOFF I'm not sure it may treat them as binary input, and I'm afraid I don't know how large serial buffer is in RQ-HUNO. Most cammands will respond, so as long as you wait until you have a 2 byte response, before sending next command you shouldn't have a problem
l3v3rz
Savvy Roboteer
Savvy Roboteer
Posts: 473
Joined: Fri Jul 18, 2008 2:34 pm

Post by RNope » Tue Jan 29, 2013 3:14 pm

Post by RNope
Tue Jan 29, 2013 3:14 pm

Thanks for your answers !

Pushing a step further i wanted to tried "over the web control" with this PHP -serial class:
(cannot put a direct link due to forum limitation sorry)
code.google(DOTcom)/p/php-serial/

I installed a local Wampserver and tried to send data on serial port but i seem to have a problem converting the 8 bit command into byte array :

I tried sending "raw" data from the result of single "byte conversion" i did in processing and a web-to-arduino-example using this class:


Code: Select all
     <php>deviceSet("COM9"); //SET THIS TO WHATEVER YOUR SERIAL DEVICE HAPPENS TO BE
     
    //Set the serial port parameters.
    $serial->confBaudRate(115200); //Baud rate:
    //$serial->confParity("none");  //Parity
    //$serial->confCharacterLength(8); //Character length
    //$serial->confStopBits(1);  //Stop bits
    //$serial->confFlowControl("none");


    //Now we "open" the serial port so we can write to it
    $serial->deviceOpen();

    //Issue the appropriate command according to the Arduino source code 0=Green On, 1=Green Off, 2=Red On, 3=Red Off.
    if ($_GET['action'] == "greenon") {

//$serial->sendMessage("-1 -1 -86 85 -86 85 55 -70"); //header
                $serial->sendMessage("-1");
      $serial->sendMessage("-1");
      $serial->sendMessage("-86");
      $serial->sendMessage("85");
      $serial->sendMessage("-86");
      $serial->sendMessage("85");
      $serial->sendMessage("55");
      $serial->sendMessage("-70");
      //$serial->sendMessage("20 0 0 0 0 1 1 1"); //inner
      $serial->sendMessage("20");
      $serial->sendMessage("0");
      $serial->sendMessage("0");
      $serial->sendMessage("0");
      $serial->sendMessage("0");
      $serial->sendMessage("1");
                $serial->sendMessage("1");
      $serial->sendMessage("1");
  //We're done, so close the serial port again
    $serial->deviceClose();

}


?><DOCTYPE>
<html>
<head>
<meta>
<title>Arduino Project 1: Serial LED Control</title>
</head>
<body>

<h1>Arduino Project 1: Serial LED Control</h1>
<p><a href="<?=$_SERVER['PHP_SELF'] . ">
</body>
</html>


Wich doesn't work : (USB red light on for 10s but no motion played)

Searching around the web , assuming it was a "type" problem i found two posts indicating quite the same method to transform hexadecimal to "raw" (assuming byte ?) array :
1 using str_plit (or explode) >convert string to array
2 using hexdec function >convert hex to dec
3 using chr function > return string from ASII code

(cannot put a direct link sorry) phpclasses(DOTorg)/discuss/package/3679/thread/16/
(cannot put a direct link sorry) stackoverflow(DOTcom)/questions/11352193/php-convert-c-sharp-hex-blob-hexadecimal-string-back-to-byte-array-prior-to-decr

Adaptating it to my problem :

Code: Select all

$headerHex = 'FFFFAA55AA5537BA';
      $innerHex = '1400000000010101';
        //$header = join(',', array_map('hexdec', str_split($headerHex, 2)));
      $header = join(',', array_map('chr', array_map('hexdec', str_split($headerHex, 2))));
      //$inner = join(',',  array_map('hexdec', str_split($innerHex, 2)));
      $inner = join(',', array_map('chr', array_map('hexdec', str_split($innerHex, 2))));
      $serial->sendMessage($header);
      $serial->sendMessage($inner);



Code: Select all
<php>deviceClose("COM9"); //Make sure port is closed
$serial->deviceSet("COM9"); //Set the comport (/dev/ttyS0)
$serial->confBaudRate(115200); //Set the baurd rate
$serial->confParity(none); //Set the Parity
$serial->confCharacterLength(8); //Set the word length
$serial->confStopBits(1); //Set Stop Bit
$serial->confFlowControl(none); //Set FLow Control



$packet = $_POST["newPacket"];
$explodedPacket = explode(",",$packet);

$concat = "";

for($i=0; $i<sizeof>deviceOpen(); //Open the port ready for transmitt
$serial->sendMessage($concat);
}
?>


Despite some communication being made (red LED lights on for 10s when i send the command) no motion is played.

Any suggestion would be greatly appreciated !
Thanks for your answers !

Pushing a step further i wanted to tried "over the web control" with this PHP -serial class:
(cannot put a direct link due to forum limitation sorry)
code.google(DOTcom)/p/php-serial/

I installed a local Wampserver and tried to send data on serial port but i seem to have a problem converting the 8 bit command into byte array :

I tried sending "raw" data from the result of single "byte conversion" i did in processing and a web-to-arduino-example using this class:


Code: Select all
     <php>deviceSet("COM9"); //SET THIS TO WHATEVER YOUR SERIAL DEVICE HAPPENS TO BE
     
    //Set the serial port parameters.
    $serial->confBaudRate(115200); //Baud rate:
    //$serial->confParity("none");  //Parity
    //$serial->confCharacterLength(8); //Character length
    //$serial->confStopBits(1);  //Stop bits
    //$serial->confFlowControl("none");


    //Now we "open" the serial port so we can write to it
    $serial->deviceOpen();

    //Issue the appropriate command according to the Arduino source code 0=Green On, 1=Green Off, 2=Red On, 3=Red Off.
    if ($_GET['action'] == "greenon") {

//$serial->sendMessage("-1 -1 -86 85 -86 85 55 -70"); //header
                $serial->sendMessage("-1");
      $serial->sendMessage("-1");
      $serial->sendMessage("-86");
      $serial->sendMessage("85");
      $serial->sendMessage("-86");
      $serial->sendMessage("85");
      $serial->sendMessage("55");
      $serial->sendMessage("-70");
      //$serial->sendMessage("20 0 0 0 0 1 1 1"); //inner
      $serial->sendMessage("20");
      $serial->sendMessage("0");
      $serial->sendMessage("0");
      $serial->sendMessage("0");
      $serial->sendMessage("0");
      $serial->sendMessage("1");
                $serial->sendMessage("1");
      $serial->sendMessage("1");
  //We're done, so close the serial port again
    $serial->deviceClose();

}


?><DOCTYPE>
<html>
<head>
<meta>
<title>Arduino Project 1: Serial LED Control</title>
</head>
<body>

<h1>Arduino Project 1: Serial LED Control</h1>
<p><a href="<?=$_SERVER['PHP_SELF'] . ">
</body>
</html>


Wich doesn't work : (USB red light on for 10s but no motion played)

Searching around the web , assuming it was a "type" problem i found two posts indicating quite the same method to transform hexadecimal to "raw" (assuming byte ?) array :
1 using str_plit (or explode) >convert string to array
2 using hexdec function >convert hex to dec
3 using chr function > return string from ASII code

(cannot put a direct link sorry) phpclasses(DOTorg)/discuss/package/3679/thread/16/
(cannot put a direct link sorry) stackoverflow(DOTcom)/questions/11352193/php-convert-c-sharp-hex-blob-hexadecimal-string-back-to-byte-array-prior-to-decr

Adaptating it to my problem :

Code: Select all

$headerHex = 'FFFFAA55AA5537BA';
      $innerHex = '1400000000010101';
        //$header = join(',', array_map('hexdec', str_split($headerHex, 2)));
      $header = join(',', array_map('chr', array_map('hexdec', str_split($headerHex, 2))));
      //$inner = join(',',  array_map('hexdec', str_split($innerHex, 2)));
      $inner = join(',', array_map('chr', array_map('hexdec', str_split($innerHex, 2))));
      $serial->sendMessage($header);
      $serial->sendMessage($inner);



Code: Select all
<php>deviceClose("COM9"); //Make sure port is closed
$serial->deviceSet("COM9"); //Set the comport (/dev/ttyS0)
$serial->confBaudRate(115200); //Set the baurd rate
$serial->confParity(none); //Set the Parity
$serial->confCharacterLength(8); //Set the word length
$serial->confStopBits(1); //Set Stop Bit
$serial->confFlowControl(none); //Set FLow Control



$packet = $_POST["newPacket"];
$explodedPacket = explode(",",$packet);

$concat = "";

for($i=0; $i<sizeof>deviceOpen(); //Open the port ready for transmitt
$serial->sendMessage($concat);
}
?>


Despite some communication being made (red LED lights on for 10s when i send the command) no motion is played.

Any suggestion would be greatly appreciated !
RNope
Newbie
Newbie
Posts: 5
Joined: Sun Jan 20, 2013 7:16 pm

Post by l3v3rz » Tue Jan 29, 2013 7:58 pm

Post by l3v3rz
Tue Jan 29, 2013 7:58 pm

Sorry no idea, I don't use php or are familiar with library. Sounds like you're on right track with the conversion from hex string to bytes though.

I don't understand code attached, it looks like you should be sending header then inner after connecting serial but you seem to be sending concat which is blank.

Hope that helps - good luck
Sorry no idea, I don't use php or are familiar with library. Sounds like you're on right track with the conversion from hex string to bytes though.

I don't understand code attached, it looks like you should be sending header then inner after connecting serial but you seem to be sending concat which is blank.

Hope that helps - good luck
l3v3rz
Savvy Roboteer
Savvy Roboteer
Posts: 473
Joined: Fri Jul 18, 2008 2:34 pm

Post by RNope » Wed Jan 30, 2013 3:40 pm

Post by RNope
Wed Jan 30, 2013 3:40 pm

I don't understand code attached, it looks like you should be sending header then inner after connecting serial but you seem to be sending concat which is blank.

Yep , my fault , a cut/paste error sorry ! should have been

Code: Select all
$packet = 'FF,FF,AA,55,AA,55,37,BA';
$explodedPacket = explode(",",$packet);
 $concat = "";
 for($i=0; $i<sizeof>sendMessage($concat);
{
         $temp = hexdec($explodedPacket[$i]);
         $concat .= chr($temp);
         }
$serial->sendMessage($concat);


But it does'nt work for me.

My (seemingly) 2 most promishing tries with the PHP serial class so far :
(if anyone more inspired than me come to this one day)

(doesn't work: usb red light on for 10s but no motion)

Code: Select all
$headerHex = 'FFFFAA55AA5537BA';
$innerHex = '1400000000010101';
$header = join('', array_map('chr', array_map('hexdec',str_split($headerHex, 2))));
$inner = join('', array_map('chr', array_map('hexdec',str_split($innerHex, 2))));
      
$serial->sendMessage($header);
$serial->sendMessage($inner);


(doesn't work: usb red light on for 10s but no motion)

Code: Select all
$headerHex = 'FFFFAA55AA5537BA';
$innerHex = '1400000000010101';
      
$headerBin = pack("H*", $headerHex);
$innerBin= pack("H*", $innerHex);
      
$serial->sendMessage($headerBin);
$serial->sendMessage($innerBin);


Had a look at Endianness (transforming the "H*" into "h" but it doesn't seem to help, not sure of what i was doing anyway.


After 5 days of infructuous tries i'm gonna have a look at Javascrit or maybe Python to continue my investigations on a web interface....

Thanks for your answers !
I don't understand code attached, it looks like you should be sending header then inner after connecting serial but you seem to be sending concat which is blank.

Yep , my fault , a cut/paste error sorry ! should have been

Code: Select all
$packet = 'FF,FF,AA,55,AA,55,37,BA';
$explodedPacket = explode(",",$packet);
 $concat = "";
 for($i=0; $i<sizeof>sendMessage($concat);
{
         $temp = hexdec($explodedPacket[$i]);
         $concat .= chr($temp);
         }
$serial->sendMessage($concat);


But it does'nt work for me.

My (seemingly) 2 most promishing tries with the PHP serial class so far :
(if anyone more inspired than me come to this one day)

(doesn't work: usb red light on for 10s but no motion)

Code: Select all
$headerHex = 'FFFFAA55AA5537BA';
$innerHex = '1400000000010101';
$header = join('', array_map('chr', array_map('hexdec',str_split($headerHex, 2))));
$inner = join('', array_map('chr', array_map('hexdec',str_split($innerHex, 2))));
      
$serial->sendMessage($header);
$serial->sendMessage($inner);


(doesn't work: usb red light on for 10s but no motion)

Code: Select all
$headerHex = 'FFFFAA55AA5537BA';
$innerHex = '1400000000010101';
      
$headerBin = pack("H*", $headerHex);
$innerBin= pack("H*", $innerHex);
      
$serial->sendMessage($headerBin);
$serial->sendMessage($innerBin);


Had a look at Endianness (transforming the "H*" into "h" but it doesn't seem to help, not sure of what i was doing anyway.


After 5 days of infructuous tries i'm gonna have a look at Javascrit or maybe Python to continue my investigations on a web interface....

Thanks for your answers !
RNope
Newbie
Newbie
Posts: 5
Joined: Sun Jan 20, 2013 7:16 pm


7 postsPage 1 of 1
7 postsPage 1 of 1