Thursday, 7 August 2014


The Lego Mindstroms software is an awesome way for anyone to get into programming and robotics. Lego has made it very easy to build a robot out of Lego, write a program by connecting program blocks together, and then watch your robot come alive! Within (at most) a couple hours anyone can have a Lego robot driving around, doing whatever they tell it to do. This is really amazing, especially for kids who already play with Lego.  Robot competitions (Like the Ottawa Robotics Competition are now open to kids that are as old as Facebook is and can program better than some computer science undergrads. This is all thanks to Lego Mindstorms, but what if you want to dig deeper and really see what’s going on under the hood of a lego Mindstorms brick. Well, unfortunately, you can’t – at least not easily. The hardware itself can be explored and researched but you can’t do much with the software. A program that’s written using the Lego Mindstorms IDE, in all of its blocky glory, can’t be easily converted to an actual program in a real program language. This led me to begin a project called EV3ToC, a program that will convert a program written for a Lego Mindstorms EV3 to functioning C code.

Why in the world would you want to do that?

Well, for starters, one way great way to learn to program is to try to understand what real code is actually doing. If someone learning to program can write a program without having to write out the syntax, they overcome all of the problems faced by (relatively) weird programming syntax. Secondly, with the use of a helper library, the code that us generated by EV3ToC can then be used to program another microcontroller, say an Arduino that has a couple motors connected to it. Now someone can build a robot out of real parts, like an Arduino and motor controllers, and program it using the Lego Mindstorms easy-to-learn IDE.
The EV3ToC program parses an XML file that is created by the Lego Mindstorms IDE. The blocks and connections that are found in the XML file get used to generate the actual C code. Loop blocks become while loops, switch blocks become if/else statements and functional blocks become function calls. The function calls are to functions implemented in an external library that would be automatically included by the program.

Please note that the software is nowhere near complete, fully functional, or feature complete. Until I can perform more testing it will remain very limited. If you want to play with it and try it out, go to and grab the code from there. Instructions are in the readme.

No comments:

Post a Comment