-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schema): add support of vehicle state (#31)
* feat: add new schema name for vehicle state Signed-off-by: ktro2828 <[email protected]> * feat: add schema table for vehicle state Signed-off-by: ktro2828 <[email protected]> * feat: update to load vehicle state in Tier4 class Signed-off-by: ktro2828 <[email protected]> * test: add unit testing for vehicle state Signed-off-by: ktro2828 <[email protected]> --------- Signed-off-by: ktro2828 <[email protected]>
- Loading branch information
Showing
8 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
|
||
from attrs import define, field | ||
|
||
from ..name import SchemaName | ||
from .base import SchemaBase | ||
from .registry import SCHEMAS | ||
|
||
__all__ = ["ShiftState", "IndicatorState", "Indicators", "AdditionalInfo", "VehicleState"] | ||
|
||
|
||
class ShiftState(str, Enum): | ||
"""An enum to represent gear shift state.""" | ||
|
||
PARK = "PARK" | ||
REVERSE = "REVERSE" | ||
NEUTRAL = "NEUTRAL" | ||
HIGH = "HIGH" | ||
FORWARD = "FORWARD" | ||
LOW = "LOW" | ||
NONE = "NONE" | ||
|
||
|
||
class IndicatorState(str, Enum): | ||
"""An enum to represent indicator state.""" | ||
|
||
ON = "on" | ||
OFF = "off" | ||
|
||
|
||
@define | ||
class Indicators: | ||
"""A dataclass to represent state of each indicator. | ||
Attributes: | ||
left (IndicatorState): State of the left indicator. | ||
right (IndicatorState): State of the right indicator. | ||
hazard (IndicatorState): State of the hazard lights. | ||
""" | ||
|
||
left: IndicatorState = field(converter=IndicatorState) | ||
right: IndicatorState = field(converter=IndicatorState) | ||
hazard: IndicatorState = field(converter=IndicatorState) | ||
|
||
|
||
@define | ||
class AdditionalInfo: | ||
"""A dataclass to represent additional state information of the ego vehicle. | ||
Attributes: | ||
speed (float | None): Speed of the ego vehicle. | ||
""" | ||
|
||
speed: float | None = field(default=None) | ||
|
||
|
||
@define(slots=False) | ||
@SCHEMAS.register(SchemaName.VEHICLE_STATE) | ||
class VehicleState(SchemaBase): | ||
"""A dataclass to represent schema table of `vehicle_state.json`. | ||
Attributes: | ||
token (str): Unique record identifier. | ||
timestamp (int): Unix time stamp. | ||
accel_pedal (float | None): Accel pedal position [%]. | ||
brake_pedal (float | None): Brake pedal position [%]. | ||
steer_pedal (float | None): Steering wheel position [%]. | ||
steering_tire_angle (float | None): Steering tire angle [rad]. | ||
steering_wheel_angle (float | None): Steering wheel angle [rad]. | ||
shift_state (ShiftState | None): Gear shift state. | ||
indicators (Indicators | None): State of each indicator. | ||
additional_info (AdditionalInfo | None): Additional state information. | ||
""" | ||
|
||
token: str | ||
timestamp: int | ||
accel_pedal: float | None = field(default=None) | ||
brake_pedal: float | None = field(default=None) | ||
steer_pedal: float | None = field(default=None) | ||
steering_tire_angle: float | None = field(default=None) | ||
steering_wheel_angle: float | None = field(default=None) | ||
shift_state: ShiftState | None = field( | ||
default=None, converter=lambda x: None if x is None else ShiftState(x) | ||
) | ||
indicators: Indicators | None = field( | ||
default=None, converter=lambda x: Indicators(**x) if isinstance(x, dict) else x | ||
) | ||
additional_info: AdditionalInfo | None = field( | ||
default=None, converter=lambda x: AdditionalInfo(**x) if isinstance(x, dict) else x | ||
) |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from t4_devkit.schema import VehicleState | ||
|
||
|
||
def test_vehicle_state_json(vehicle_state_json) -> None: | ||
"""Test loading vehicle state from a json file.""" | ||
_ = VehicleState.from_json(vehicle_state_json) | ||
|
||
|
||
def test_vehicle_state(vehicle_state_dict) -> None: | ||
"""Test loading vehicle state from a dictionary.""" | ||
s = VehicleState.from_dict(vehicle_state_dict) | ||
print(s) |
This file contains 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
This file contains 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