-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue that car can't full stop if brake (#786)
Fix issue that car can't full stop if brake=-1
- Loading branch information
1 parent
b908149
commit 2b6f5d3
Showing
2 changed files
with
56 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from metadrive.envs import MetaDriveEnv | ||
|
||
|
||
def test_full_stop(): | ||
config = { | ||
"use_render": False, | ||
"map": "y", | ||
"vehicle_config": { | ||
"spawn_position_heading": [[10, 10], 0], | ||
}, | ||
} | ||
|
||
env = MetaDriveEnv(config) | ||
env.reset() | ||
|
||
try: | ||
# Driving forward phase | ||
for step in range(30): # Drive forward for 30 steps | ||
env.step([0, 1]) # Full throttle, no steering | ||
# print("Speed: ", env.agent.speed) | ||
# env.render(mode="topdown") | ||
|
||
success = False | ||
print("Starting Brake Phase") | ||
for i in range(20): # Continue braking until the car stops | ||
env.step([0.0, -1.0]) # No throttle, apply brake | ||
# print(i, "Speed: ", env.agent.speed) | ||
# env.render(mode="topdown") | ||
|
||
if env.agent.speed <= 0.01: # Stop if speed is effectively zero | ||
print("Car has stopped.") | ||
success = True | ||
break | ||
|
||
if not success: | ||
raise ValueError("Car did not stop after 20 steps") | ||
|
||
finally: | ||
env.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
test_full_stop() |