Writing the motor controller

The motor controllers in src/motor.rs will be responsible for making decisions regarding how much force to generate from the motor. The physics driver will supply current state information regarding all known measurements of location, velocity, and so on. Currently, the motor controller uses only the most current information to make control decisions. However, this may change in the future, in which case the controller may store past measurements.

Extracting the same control algorithm from the previous chapter, the new MotorController definition becomes as follows:

pub struct SimpleMotorController{   pub esp: ElevatorSpecification}impl MotorController for SimpleMotorController{ fn init(&mut self, esp: ElevatorSpecification, ...

Get Hands-On Functional Programming in Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.