Mapping code changes and additions
Now that we have organized our concepts, data structures, and logic into files, we can now proceed with the normal process to transform requirements into code. For each module, we will look at the required elements and produce code to satisfy those requirements.
Here, we break down all code development steps by module. Different modules have different organizations, so pay attention for patterns regarding organization and code development.
Developing code by type
These files will be organized using the by type method.
Writing the motor_controllers.rs module
The new motor_controller
module serves as an adapter to all of the linked motor drivers and their interfaces, and provides a single uniform interface. Let's see how:
- First, let's link all the drivers from the software provided into our program:
use libc::c_int; #[link(name = "motor1")] extern { pub fn motor1_adjust_motor(target_force: c_int) -> c_int; } #[link(name = "motor2")] extern { pub fn motor2_adjust_motor...