generated from angelomorgado/CARLA-Ultimate-Template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.py
41 lines (33 loc) · 1.79 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'''
This script is used to show how to use the environment by running a few episodes or steps.
'''
from src.env.environment import CarlaEnv # It is mandatory to import the environment even if it is not used in this script
import gymnasium as gym
def steps_main():
# env = CarlaEnv('carla-rl-gym-v0', time_limit=300, initialize_server=False, random_weather=True, synchronous_mode=True, continuous=False, show_sensor_data=True, random_traffic=True) # <-- Alternative way to create the environment
env = gym.make('carla-rl-gym-v0', time_limit=15, initialize_server=True, random_weather=True, synchronous_mode=True, continuous=False, show_sensor_data=True, random_traffic=True)
obs, info = env.reset()
# Number of steps
for i in range(300):
action = env.action_space.sample()
obs, reward, terminated, truncated, info = env.step(action)
print("Reward: ", reward)
if terminated or truncated:
observation, info = env.reset()
env.close()
def episodes_main():
env = gym.make('carla-rl-gym-v0', time_limit=15, initialize_server=False, random_weather=False, synchronous_mode=True, continuous=True, show_sensor_data=True, random_traffic=False, autopilot=False)
# Number of episodes
for i in range(5):
print("================================ Episode", i, " ================================")
obs, info = env.reset()
while True:
action = [0.0, 0.0]
obs, reward, terminated, truncated, info = env.step(action)
# print("Reward:", reward, "Terminated:", terminated, "Truncated:", truncated)
if terminated or truncated:
print('Episode terminated cleaning environment')
break
env.close()
if __name__ == '__main__':
episodes_main()