Skip to content

unify vehicle drawing parts - #233

Open
katerinakatsampoula wants to merge 1 commit into
ShisatoYano:mainfrom
katerinakatsampoula:replace-classes
Open

katerinakatsampoula wants to merge 1 commit into
ShisatoYano:mainfrom
katerinakatsampoula:replace-classes

Conversation

@katerinakatsampoula

Copy link
Copy Markdown
Contributor

Overview

Closes #121

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.

Implementation

VehiclePart receives:

VehiclePart(
    spec,
    outline_xy,
    offset_x_m,
    offset_y_m,
    steerable,
)

@ShisatoYano ShisatoYano added the enhancement New feature or request label Nov 15, 2026
@ShisatoYano
ShisatoYano self-requested a review November 15, 2026 21:51
@ShisatoYano

Copy link
Copy Markdown
Owner

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:

  1. 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.
  2. 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.
  3. File name. Please rename VehiclePart.py to vehicle_part.py, like the other modules (for example four_wheels_vehicle.py, vehicle_specification.py).
  4. 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.

🤖 Generated with Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Replace the 8 vehicle part classes with one configurable part class

2 participants