Source code for suboptimumg.models

from __future__ import annotations

from pydantic import BaseModel, ConfigDict, Field


[docs] class TireForce(BaseModel): """ Forces acting on a single tire at a single instant. """ model_config = ConfigDict(frozen=True, extra="forbid") normal: float = Field(description="Normal force on the tire (N)") lateral: float = Field(description="Lateral force on the tire (N)")
[docs] class TireForces(BaseModel): """ Forces acting on the four tires at a single instant. """ model_config = ConfigDict(frozen=True, extra="forbid") front_left: TireForce = Field(description="Forces on the front left tire") front_right: TireForce = Field(description="Forces on the front right tire") back_left: TireForce = Field(description="Forces on the back left tire") back_right: TireForce = Field(description="Forces on the back right tire") @property def total_normal(self) -> float: """Sum of the normal forces on all four tires (N).""" return sum( ( self.front_left.normal, self.front_right.normal, self.back_left.normal, self.back_right.normal, ) )
[docs] class SimulationState(BaseModel): """ Vehicle state used in our simulation. """ model_config = ConfigDict(frozen=True, extra="forbid") sliding: bool = Field(description="Whether the vehicle is sliding") acc: float = Field(description="Longitudinal acceleration (m/s^2)") v: float = Field(description="Current velocity (m/s)") dt: float = Field(description="Current time step (s)") p: float = Field(description="Current power (W)") motor_torque: float = Field( default=0.0, description=( "Per-motor shaft torque (N*m), signed: positive driving, negative " "regen. This is the mechanical output torque of a SINGLE motor " "(total drivetrain torque / motor count), the quantity the " "efficiency LUT and the real motor torqueFeedback are indexed by." ), ) roll: float = Field(default=0.0, description="Roll angle (rad)") pitch: float = Field(default=0.0, description="Pitch angle (rad)")
[docs] def model_copy(self, *args: object, **kwargs: object) -> SimulationState: """ Raise an error, since copying is disabled to ensure immutability. """ raise TypeError("Copying is disabled for SimulationState")
[docs] def copy(self, *args: object, **kwargs: object) -> SimulationState: """ Raise an error, since copying is disabled to ensure immutability. """ raise TypeError("Copying is disabled for SimulationState")