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

Zig-bee a note to Java Programmers

Bioloid robot kit from Korean company Robotis; CM5 controller block, AX12 servos..
1 postPage 1 of 1
1 postPage 1 of 1

Zig-bee a note to Java Programmers

Post by JavaRN » Wed Feb 20, 2008 7:28 pm

Post by JavaRN
Wed Feb 20, 2008 7:28 pm

I've just finished my first communication program through Zig-bee with the CM-5. I would like to mention a few important points for those of you who will eventually use Java to communicate with CM-5 using zig-bee.

Java's byte type is an 8-bit signed two's complement number so if you need to send a packet using an array of bytes you have to follow the same format using "different numbers", so if you are going to send the number 10 to the CM-5 use the array:

{-1, 85, 10, -11, 0, -1}

note that while writing your Java program you cannot use the hexadecimal 0xFF in the array since it will be treated as an integer and you'll get a compile time error, that's why you need to use -1. So as a general rule you can follow the following method for sending a packet using the byte type in Java:

1. Start with -1 and 85 which are the header.
2. Get the LSB to send. say 64, that would be the third number
3. Add one to it and make it negative (-65) that would be the fourth number.
4. Do the same with the MSB, if you don't have anything to send then add 0 and -1. So sending the number 64 to the CM-5 through zig-bee would involve the following array:

{-1, 85, 64, -65, 0, -1}


Of course this method works with positive numbers up to 127. If you have bigger positive numbers then you have to modify steps 2, 3, and 4 above

So if you want to send 200 for LSB, you have to:
1. Subtract 200 (or the number you have) from 256 and add negative to it. In this case you will end up with -56.
2. the fourth number would be a positive number which is one less than the previous number, so in this case it would be 55.
3. Apply the same principle to the MSB.

So if you want to send the number 200 in the LSB, you have to send:

{-1, 85, -56, 55, 0, -1}

Or else if you want to avoid all this math you can work with an array of int and then typecast each item to a byte. However you might encounter some problems when receiving data especially data which is bigger than 127.

Hope this helps Java Bioloid programmers out there.


Note: I got the Zig-bee packet information from http://www.bipedrobots.co.uk/blindex.aspx?id=328

Charles
I've just finished my first communication program through Zig-bee with the CM-5. I would like to mention a few important points for those of you who will eventually use Java to communicate with CM-5 using zig-bee.

Java's byte type is an 8-bit signed two's complement number so if you need to send a packet using an array of bytes you have to follow the same format using "different numbers", so if you are going to send the number 10 to the CM-5 use the array:

{-1, 85, 10, -11, 0, -1}

note that while writing your Java program you cannot use the hexadecimal 0xFF in the array since it will be treated as an integer and you'll get a compile time error, that's why you need to use -1. So as a general rule you can follow the following method for sending a packet using the byte type in Java:

1. Start with -1 and 85 which are the header.
2. Get the LSB to send. say 64, that would be the third number
3. Add one to it and make it negative (-65) that would be the fourth number.
4. Do the same with the MSB, if you don't have anything to send then add 0 and -1. So sending the number 64 to the CM-5 through zig-bee would involve the following array:

{-1, 85, 64, -65, 0, -1}


Of course this method works with positive numbers up to 127. If you have bigger positive numbers then you have to modify steps 2, 3, and 4 above

So if you want to send 200 for LSB, you have to:
1. Subtract 200 (or the number you have) from 256 and add negative to it. In this case you will end up with -56.
2. the fourth number would be a positive number which is one less than the previous number, so in this case it would be 55.
3. Apply the same principle to the MSB.

So if you want to send the number 200 in the LSB, you have to send:

{-1, 85, -56, 55, 0, -1}

Or else if you want to avoid all this math you can work with an array of int and then typecast each item to a byte. However you might encounter some problems when receiving data especially data which is bigger than 127.

Hope this helps Java Bioloid programmers out there.


Note: I got the Zig-bee packet information from http://www.bipedrobots.co.uk/blindex.aspx?id=328

Charles
F'dan il-passatemp ghandek bzonn zewg affarijiet - FLUS u HIN. Zewg affarijiet li huma skarsi hafna u li jien minnhom ghandi vera ftit!
JavaRN
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 282
Joined: Fri Mar 02, 2007 11:01 pm

1 postPage 1 of 1
1 postPage 1 of 1