-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Armando Bañuelos
committed
Jul 10, 2024
1 parent
50cd9ef
commit fdee779
Showing
5 changed files
with
240 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
model scenic.simulators.metadrive.model | ||
param map = localPath('../../assets/maps/CARLA/Town01.xodr') | ||
model scenic.simulators.metadrive.model | ||
|
||
# car = new Car |
Empty file.
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 |
---|---|---|
@@ -1,2 +1,62 @@ | ||
from scenic.simulators.metadrive.simulator import MetaDriveSimulator | ||
simulator MetaDriveSimulator() | ||
from scenic.domains.driving.model import * | ||
import pathlib | ||
|
||
# TODO: research on open drive conversion for metadrive | ||
map_town = pathlib.Path(globalParameters.map).stem | ||
param map = map_town | ||
param timestep = 0.1 | ||
param render = 0 | ||
|
||
simulator MetaDriveSimulator( | ||
timestep=float(globalParameters.timestep), | ||
render=bool(globalParameters.render), | ||
metadrive_map=globalParameters.map, | ||
) | ||
|
||
class MetaDriveActor(DrivingObject): | ||
"""Abstract class for MetaDrive objects. | ||
Properties: | ||
metaDriveActor (dynamic): Set during simulations to the ``metaDrive.Actor`` representing this | ||
object. | ||
blueprint (str): Identifier of the MetaDrive blueprint specifying the type of object. | ||
rolename (str): Can be used to differentiate specific actors during runtime. Default | ||
value ``None``. | ||
""" | ||
metaDriveActor: None | ||
rolename: None | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
def setPosition(self, pos): | ||
self.metaDriveActor.set_location(pos) | ||
|
||
def setVelocity(self, vel): | ||
self.metaDriveActor.set_velocity(vel, 1, in_local_frame=True) | ||
|
||
|
||
class Vehicle(Vehicle, MetaDriveActor): | ||
"""Abstract class for steerable vehicles.""" | ||
|
||
def setThrottle(self, throttle): | ||
self.metaDriveActor._apply_throttle_brake(0) | ||
|
||
def setSteering(self, steering): | ||
self.control.steer = steering | ||
|
||
def setBraking(self, braking): | ||
self.control.brake = braking | ||
|
||
def setHandbrake(self, handbrake): | ||
self.control.hand_brake = handbrake | ||
|
||
def setReverse(self, reverse): | ||
self.control.reverse = reverse | ||
|
||
class Car: | ||
blueprint: None | ||
@property | ||
def isCar(self): | ||
return True |
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,59 @@ | ||
from metadrive.envs import MetaDriveEnv | ||
from metadrive.manager import BaseManager | ||
from metadrive.component.vehicle.vehicle_type import DefaultVehicle | ||
from metadrive.policy.idm_policy import IDMPolicy | ||
from metadrive.component.traffic_participants.pedestrian import Pedestrian | ||
|
||
class DriveManager(BaseManager): | ||
def __init__(self): | ||
super(DriveManager, self).__init__() | ||
self.generated_v = None | ||
self.ped = None | ||
self.generate_ts = 0 | ||
|
||
def cleanup_physics_bodies(self): | ||
for obj in self.get_objects(): | ||
print(obj) | ||
# import pdb; pdb.set_trace() | ||
# obj.cleanup_physics_body() # Implement this method as needed | ||
|
||
def reset(self): | ||
self.cleanup_physics_bodies() | ||
super().reset() # Call super method after cleanup | ||
|
||
def before_step(self): | ||
# if self.generated_v: | ||
# p = self.get_policy(self.generated_v.id) | ||
# self.generated_v.before_step(p.act()) | ||
self.cleanup_physics_bodies() | ||
pass | ||
|
||
|
||
def after_step(self): | ||
# if self.episode_step == self.generate_ts: | ||
# self.generated_v = self.spawn_object(DefaultVehicle, | ||
# vehicle_config=dict(), | ||
# position=(10, 0), | ||
# heading=0) | ||
# self.add_policy(self.generated_v.id, IDMPolicy, self.generated_v, self.generate_seed()) | ||
# self.ped = self.spawn_object( | ||
# Pedestrian, | ||
# name="ped", | ||
# position=(50,0), | ||
# heading_theta=1, | ||
# ) | ||
# self.ped.set_velocity([1, 0], 1, in_local_frame=True) | ||
pass | ||
|
||
|
||
|
||
# elif self.episode_step == self.recycle_ts: | ||
# self.clear_objects([self.generated_v.id]) | ||
# self.generated_v = None | ||
# elif self.generated_v: | ||
# self.generated_v.after_step() | ||
|
||
class DriveEnv(MetaDriveEnv): | ||
def setup_engine(self): | ||
super(DriveEnv, self).setup_engine() | ||
self.engine.register_manager("drive_mgr", DriveManager()) |