-
Notifications
You must be signed in to change notification settings - Fork 0
/
spawn_and_sensor_attach.py
68 lines (57 loc) · 2.11 KB
/
spawn_and_sensor_attach.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
#Script by Rishabh Verma
#This script is a part of the project I'm doing for Autonomous Navigation On Carla
from ast import Lambda
import glob
import os
import sys
from tkinter import Frame
import cv2
from cv2 import transform
import numpy as np
import random
import matplotlib.pyplot as plt
import time
import argparse
try:
sys.path.append(glob.glob('../carla/dist/carla-*%d.%d-%s.egg' % (
sys.version_info.major,
sys.version_info.minor,
'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
pass
import carla
def main():
actorList = []
try:
client = carla.Client('localhost',2000)
client.set_timeout(10.0)
world = client.load_world('Town01')
print(client.get_available_maps())
blueprintLibrary = world.get_blueprint_library()
vehicle_bp = blueprintLibrary.filter('cybertruck')[0]
transform = carla.Transform(carla.Location(x=130, y=195, z=40), carla.Rotation(yaw = 180))
vehicle = world.spawn_actor(vehicle_bp, transform)
actorList.append(vehicle)
camera_bp = blueprintLibrary.find('sensor.camera.rgb')
camera_bp.set_attribute('image_size_x','800')
camera_bp.set_attribute('image_size_y','600')
camera_bp.set_attribute('fov','90')
camera_transform = carla.Transform(carla.Location(x=1.5,z=2.4))
camera = world.spawn_actor(camera_bp,camera_transform,attach_to=vehicle)
camera.listen(lambda image: image.save_to_disk('output/%d064.png'%image.frame))
transform.rotation.yaw = -180
for _ in range(0,5):
transform.location.x+=10.0
bp = blueprintLibrary.filter('cybertruck')[0]
npc = world.try_spawn_actor(bp, transform)
if npc is not None:
actorList.append(npc)
npc.set_autopilot = True
print('created %s'%npc.type_id)
time.sleep(15)
finally:
print('delete actorList')
client.apply_batch([carla.command.DestroyActor(x) for x in actorList])
if __name__ == '__main__':
main()