Sending individual bytes to the iCreate

5 replies [Last post]
AdamF
Title: MiniBot+
Joined: 03/17/2010
Posts:
BotPoints: 62
User offline. Last seen 9 years 13 weeks ago.

Does anyone have a solution for sending individual bytes to the iCreate?

Our team wants to run scripts instead of constantly polling the create for distance/angle values because it is insanely inaccurate and inconsistent.
I know how the iCreate open interface works, we actually ran the iCreate on its own (w/out CBC) last year for the game as a blocking device.

The libraries on the github repository (http://github.com/kipr/cbc/tree/master/userlib/libcbc/src/)seem to offer serial writing but our team tried to use

serial_write_byte(153);

and similar commands, the code wouldn't compile/download to the CBC.

Any help is greatly appreciated!!

Adam Farabaugh
Hampton High School

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 1168
User offline. Last seen 7 years 13 weeks ago.

I suspect the KISS-Sim libs don't include this function, which causes KISS-C to refuse to download it. Can you try loading the program via a flash drive and report back on whether it compiles? (If the flash drive works, then you might try using the Norman/Nease Mods for downloads, as they don't rely on the KISS-Sim libs.)

Another possibility is that you're using the wrong function. I recall seeing several variants in the CBC source code, including create_write_byte, serial_write_byte, and the misspelled serial_wryte_byte. If you find that this is the problem, please let us know... I'm curious which of those functions work.

Good luck!

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

PiPeep
PiPeep's picture
Title: RocketBot
Joined: 07/19/2009
Posts:
BotPoints: 170
User offline. Last seen 8 years 23 weeks ago.

I have never really used it, but CBCJVM (since version 10.3) has create scripting support. Braden might be able to supply you with some sample code. I am not sure if this is what you are looking for or not, but it might be of help anyways.

AdamF
Title: MiniBot+
Joined: 03/17/2010
Posts:
BotPoints: 62
User offline. Last seen 9 years 13 weeks ago.

Good call on the wrong function, I checked that library again and it is create_write_byte.

But it still doesn't compile/download from KISS-C, I'll try the flash drive thing at our next meeting.

Thanks for the suggestions

Adam Farabaugh
Hampton High School

PiPeep
PiPeep's picture
Title: RocketBot
Joined: 07/19/2009
Posts:
BotPoints: 170
User offline. Last seen 8 years 23 weeks ago.

I've posted it before, but this might help with installing via a flashdrive: http://github.com/catron/CBCJVM/blob/master/cbc/CBCJVM/tests/CodeInstall... although you'll want to change the directories. Just put it on a flashdrive and run, and it will replace the cbc's code folder with a code folder on the flashdrive.

matthewbot
Title: YAC
Joined: 04/12/2009
Posts:
BotPoints: 94
User offline. Last seen 12 years 5 weeks ago.

serial_read_byte and serial_write_byte are defined in that header file, but are not included in any C file for some reason. serial_read_byte in particular is broken by its very definition. Because it returns a char, you have no way to indicate when a byte could not be read (return 0 would be indistinguishable from reading a NUL character, for instance). Here's a quick, better implementation of create byte functions. I haven't tested for syntax but I think it should work:

  1. // returns unsigned byte 0-255, or -1 if no byte was available
  2. int serial_get_byte() {
  3. char byte;
  4. if (serial_read(&byte, 1))
  5. return (unsigned char)byte;
  6. else
  7. return -1;
  8. }
  9.  
  10. // writes an unsigned byte 0-255
  11. void serial_put_byte(unsigned char ubyte) {
  12. char byte = (char)ubyte;
  13. while (!serial_write(&byte, 1)) { }
  14. }

You'll want to call serial_init() before using these. I'd still point however, that if you're comfortable with arrays and pointers the serial_read() and serial_write() functions are more efficient and will probably produce more concise code.

Another approach could be to simply use ordinary C commands to manipulate the serial port's device file, /dev/uart1. For an example of this check the implementation of the above serial functions in cbcserial.c

--
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction.

Albert Einstein

Project Quadcopter: http://quadcopter.wordpress.com/