You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The vehicle directory contained eight nearly identical classes:
FrontLeftTire
FrontRightTire
RearLeftTire
RearRightTire
FrontAxle
RearAxle
Body
Chassis
Each class repeated the same drawing and transformation logic. They differed only in geometry, mounting offset, and whether steering was applied.
This change centralizes the shared behavior in VehiclePart while keeping the individual part names visible in FourWheelsVehicle, making the implementation easier to maintain and understand as learning material.
Changes
Replaced the eight duplicated vehicle-part classes with a shared VehiclePart class.
Created all vehicle parts explicitly in FourWheelsVehicle.
Preserved readable names such as body, front_left_tire, and rear_axle.
Preserved each part's outline, mounting offset, and steering behavior.
Keept compatibility modules for existing imports and smoke tests.
Thank you, @katerinakatsampoula, for taking on #121! The new FourWheelsVehicle reads well: each part keeps its name, _create_vehicle_parts shows in one place which outline goes where and which parts steer, and drawing becomes a single loop over self.parts.
I checked that the vehicle looks the same: I ran several simulations on main and on this branch and compared their last frames pixel by pixel. The vehicle frame of chapter 3 (visualize_vehicle_zoom.py), Pure Pursuit, Stanley and EKF localization are identical (0 pixels differ). The LiDAR obstacle sensing frames differ by about 1,700 pixels, but two runs on main differ by as much, from the sensor noise. The full test suite passes.
Requests before merging:
Remove the eight compatibility modules.Replace the 8 vehicle part classes with one configurable part class #121 asks for one class, and the modules now define each outline a second time: the tire outline is in front_left_tire.py, front_right_tire.py, rear_left_tire.py, rear_right_tire.py and in _create_vehicle_parts. A change to one copy wouldn't show in the simulations, which only use _create_vehicle_parts. The only remaining user is test/test_rear_axle.py: it can build a FourWheelsVehicle and check vehicle.rear_axle, vehicle.rear_left_tire and vehicle.rear_right_tire instead.
One signature for VehiclePart.draw. The if elems is None: branch shifts the arguments so that the old draw(axes, pose, elems) calls still work. A learner reading the class has to work out what this does, and once the compatibility modules are gone, nothing needs it: draw(axes, pose, steer_rad, elems) is enough.
File name. Please rename VehiclePart.py to vehicle_part.py, like the other modules (for example four_wheels_vehicle.py, vehicle_specification.py).
Type hints and units. Following CLAUDE.md, please add type hints to the new methods, and say the shape and units of outline_xy in the docstring (2 x n array of x and y in meters, in the part's own frame).
For your next PRs: the PR template (since #229) asks for a "How I checked it works" section and images. For this PR I did the comparison myself, so nothing more is needed here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Closes #121
The vehicle directory contained eight nearly identical classes:
FrontLeftTireFrontRightTireRearLeftTireRearRightTireFrontAxleRearAxleBodyChassisEach class repeated the same drawing and transformation logic. They differed only in geometry, mounting offset, and whether steering was applied.
This change centralizes the shared behavior in
VehiclePartwhile keeping the individual part names visible inFourWheelsVehicle, making the implementation easier to maintain and understand as learning material.Changes
VehiclePartclass.FourWheelsVehicle.body,front_left_tire, andrear_axle.Implementation
VehiclePartreceives: