BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 9:16 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How do I connect to PC via data packet mode?
PostPosted: Sat Jun 18, 2011 12:50 pm 
Offline
New User

Joined: Sat Jun 18, 2011 12:33 pm
Posts: 2
I was successful in connecting the roboclaw directly to LabVIEW and controlling it via simple serial mode. This only worked if I sent it ASCII code. So basically "@"(ascii) = "64" (decimal). What is the communication protocol for the data packet mode?! It seems like there is not enough in the data sheets about protocol when communicating directly with the PC. There is only some mention of communicating through the BASIC MCU's out of pin P14 and P15. Does anybody know the data type this controller accepts for proper handshaking? ...please more details on the communication side of things


Top
 Profile  
 
 Post subject: Re: How do I connect to PC via data packet mode?
PostPosted: Sun Jun 19, 2011 6:41 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
The Roboclaw uses a serial protocol, however it does not restrict itself to the standard printable characters.

That is for example in the datasheet you see:
Code:
Serout P15, i19200, [128, 0, 127, (255 & 0X7F)] ;M1 full speed forward


This is just simple basic cde that is outputting 4 bytes to the roboclaw
128 - Address of the roboclaw (selected by switches)
0 - Command. Command 0 says drive forward
127 - Speed full
127 - Checksum = (address+command+speed)&0x7f = (128+0+127) & 0x7f

It does not matter to the roboclaw if you generate these bytes on a Basic Atom Pro or on a PC. I have never used labview before so I can not tell you how there, but I have done similar stuff in Visual Basic or C on a PC...

In C you have several ways to do it. If you have variables that contain the data you can output it something like:

Code:
printf("%c%c%c%c", bAddr, bCmd, bSpeed, (bAddr+bCmd+bSpeed)&0x7f);


Note: you may need to compute the checksum outside of the printf. Also you may need to do so in a word (16 bit) variable to avoid overflows...

For fixed commands, like the one from the manual, you may be able to output those directly with strings. In C you have the string escape character \ that allows you to enter binary data in octal or hex. Something like:

Code:
printf("\0200\0\0177\0177");


or maybe:
Code:
printf("\x80\x0\x7f\x7f");


Note: you may have to look up the syntax as it has been awhile since I have...

Kurt


Top
 Profile  
 
 Post subject: Re: How do I connect to PC via data packet mode?
PostPosted: Mon Jun 20, 2011 2:35 pm 
Offline
New User

Joined: Sat Jun 18, 2011 12:33 pm
Posts: 2
So I discovered that I need to send the data packet in parts. What I did was send the command 128 then 2ms delay, then 0, 2ms delay, then 127, 2ms delay then the CRC value to get motor1 to run at 100% voltage. This worked fine up until I tried doing a read of the encoder position. I cant seem to get any sort of value back.

Thanks for the quick reply.. i think i have a lot more to figure out


Top
 Profile  
 
 Post subject: Re: How do I connect to PC via data packet mode?
PostPosted: Sat Jun 25, 2011 8:49 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
2ms is way longer than you should need for delays. We don't do anythign like that when talking to them with micros. The delay with our micros is 0 for all our samples(eg 8N1 with no delay between it and the next 8N1 byte).

Make sure you are using 8N1. 8N2 should also be fine.

Also try using the version command to test reading back data. Read back data only requires the address and then the command byte so you should always get something back. Are you using a standard rs-232 port or a usb adapter?

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO