Most EV3 examples in this site are presented as isolated programs that show how to interact with specific parts aspects of the Lego EV3 hardware (i.e motors, sensors). In final applications that require to have several hardware components working together, it is better to encapsulate the code (make it functional). The following explanation is meant to be a general guideline of how to do this process. It does not cover creating general purpose libraries.
All the programs are divided in three well defined sections:
- Initialization: This may include mapping kernel data to user space program, and setting up parameters.
- Using the device: That is reading and parsing data from sensors, or doing some action on hardware such as motors and LCDs.
- Closing device files.
A different way of encapsulating the code is by using Object Oriented Programing, which we use extensively in the Robot Navigation Software.