Lite / Intelligent Robotic Systems / Week 2
Week 2: Object-oriented programming
This week you will
- Define a class with attributes and methods to model an engineering component such as a sensor or motor.
- Protect an object's invariants with methods and properties.
- Decide when an object is clearer than a set of functions.
Lessons
- One blueprint, many sensors · about 40 min
A robot has six identical range sensors, each with its own offset and its own readings. Do you write six sets of variables, or one blueprint? - Objects that guard their own limits · about 35 min
A motor is rated to 3,000 rpm. Fifteen different parts of the code set its speed. How do you make sure none of them ever asks for 3,500? - Object or function? Choosing the clearer design · about 30 min
Converting degrees to radians, modelling a robot arm with three motors, parsing one line of a CSV file: which of these deserves a class?