Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
carla advanced Artificial Intelligence module
1. CARLA
PYTHON AI MODULE
SALOM JERLIN
TRAINER HEAD
HITAKEY TECH SOLUTION PVT LTD
DATE: 5/10/23 10 AM
VENUE: PERIYAR UNIVERSITY,Salem
9790072449
2. INTRODUCTION
: CARLA simulator is a platform which is developed to support the development, training, and
validation of autonomous “self-driving” systems.
This simulation helps to detect and diagnose autonomous self-driving systems in the virtual
world. By using CARLA, we are able to see our model work in the virtual world and train them to
get ready for the real world.
In this simulated world, we can provide obstacles just like the real world which help to learn
more about real world scenarios for the system.
3. Simulator:
A simulator is a machine or a program which is designed to provide a realistic imitation of real
life situations.
Basically, it controls and operates the behavior of a vehicle, aircraft, or other complex systems
of the virtual environment.
In this case, CARLA simulates a dynamic world and provides a simple interface between the
world and an agent that interacts with the world.
4. Environment:
: It is a computer simulated virtual world which consists of actors and communication between
them.
For example, the city or the town environment that we see in car racing or bike racing video
games.
5. Sensors:
: We all have electronic devices which widely contain a different type of sensor.
A sensor is a device or subsystem whose purpose is to detect events or changes in its
environment and send the information.
A sensor is nothing but a device just like we have in phones which shows direction just like a
GPS/compass. Example: GyroscopE
6. CARLA SENSORS
Camera sensor - to detect the images of the environment
A Depth sensor - to detect the distance of spaces from top, bottom, front, or back of the object.
A Radar sensor - to detect or track the position of an object based on its distances etc
So, we can now say that self-driving cars rely on sensors to navigate
7. CARLA SET UP
1.OPEN CMD PROMPT AND TYPE
conda
Check conda is installed??
If yes I will open the folder which I had extracted after downloading CARLA, which is
WindowsNoEditor
2.CLICK ADDRESSBAR AND TYPE CMD
3.open the command prompt window
8. Create a new environment
Here you need to create an environment to run carla programs.
For that use the below command.
conda create -n name of environment python==3.7 -y
conda create -n self_driving_car python==3.7 -y
9. Activate the environment
Then we will activate our environment,
Syntax: activate (name of your environment)
Code: activate self_driving_car
Environment is running.
12. Spawn some cars
Type cd PythonAPI
Type cd examples
Type python spawn_npc.py –n 100
13. How to write simple program
Step 1
Set up your environment: seen earlier
Step 2
Install virtual environment
python –m venv name_of_env
Example python –m venv virtual_env
15. How to write a simple program
Import necessary libraries:
In your Python script, import the necessary CARLA modules and any additional libraries
you may need.
import carla
import time
17. Structure of the program
try:
finally:
print("destroying actors")
for actor in actor_list:
actor.destroy()
print("done")
18. Connect to the CARLA server
Connect to the CARLA server using the provided host and port. You can specify the host
and port as needed.
try:
client = carla.Client('localhost', 2000)
client.set_timeout(2.0) # Set a timeout for connection (2 seconds in
this example).
19. Load a map and create a world:
Load a CARLA map and create a world object to interact with the simulation
environment.
world = client.get_world()
20. Get blueprint of the vehicle
Craete actor list on top
actor_list = []
#get to blueprint
blueprint_library=world.get_blueprint_library()
bp=blueprint_library.filter("model3")[0]
Or
21. Set spawn point
vehicle_transform = (world.get_map().get_spawn_points())
spawn_point=random.choice(world.get_map().get_spawn_points())
Or
spawn_point=random.choice(vehicle_transform)
22. Spawn the vehicle
You can spawn a vehicle at a specific location in the simulation world. You'll need to
define the vehicle's blueprint (e.g., a specific car model) and transform (position and
orientation).
vehicle = world.spawn_actor(bp, spawn_point)
vehicle.set_autopilot(True)(if needs)
spawn_point = carla.Transform(carla.Location(x=10, y=10, z=2), carla.Rotation(pitch=0, yaw=0,
roll=0))
23. Control the vehicle:
You can control the vehicle's movements using various commands. For example, to
make the vehicle move forward:
vehicle.apply_control(carla.VehicleControl(throttle=1.0,steer=0.0))
26. Run the simulation:
Start the simulation loop and allow the program to run for a specified duration or until a
specific condition is met.
try:
# Add your simulation logic here.
time.sleep(10) # Run the simulation for 10 seconds in this example.
finally:
vehicle.destroy()
27. Cleanup:
Always remember to clean up resources by destroying the objects you've spawned in
the simulation, like the vehicle.
34. change vehicle
1.Run the Carla file simple_Carla1.py car will be moving
Python simple_Carla1.py –no—-autopilot stop the car
python simple_Carla1.py –filter vehicle.bmw.grandtourer -no--
autopilot
35. Spawn at different place
Find this line
vehicle_transform = (world.get_map().get_spawn_points()[1])
Give any spawn point from 1 to 200
Run the file again
Lets create a variable
location_for_vehicle=world.get_map().get_spawn_points()
vehicle_transform = random.choice(location_for_vehicle)
36. Title Lorem Ipsum
LOREM IPSUM DOLOR SIT AMET,
CONSECTETUER ADIPISCING ELIT.
NUNC VIVERRA IMPERDIET ENIM.
FUSCE EST. VIVAMUS A TELLUS.
PELLENTESQUE HABITANT MORBI
TRISTIQUE SENECTUS ET NETUS.