owned this note
owned this note
Published
Linked with GitHub
# Carla Simulator
### Installation
The following requirements should be fulfilled before installing CARLA:
• System requirements. CARLA is built for Windows and Linux systems.
• An adequate GPU. CARLA aims for realistic simulations, so the server needs
at least a 6 GB GPU although 8 GB is recommended, especially when dealing
with machine learning.
• Disk space. CARLA will use about 20 GB of space.
• Python. Python is the main scripting language in CARLA. On Linux, CARLA supports Python 2.7 and Python 3.7. On windows, Python 3.7 only is
supported.
• Pip. Some installation methods of the CARLA client library require pip or
pip3 (depending on your Python version) version 20.3 or higher.
2 Linux Installation
The Debian package is available for both Ubuntu 18.04 and Ubuntu 20.04.
2.1 Install the Carla Server on Linux
• Set up the Debian repository in the system (each of the two commands
bellow is to be run as a single line):
```
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recvkeys 1AF1527DE64CB8D9
$ sudo add-apt-repository "deb [arch=amd64] http://dist.carla.
org/carla(lsb_release -sc) main"
```
• Update the package lists and install the Carla server:
```
$ sudo apt-get update
$ sudo apt-get install carla-simulator
```
• Import additional assets:
Each Carla release has it’s own additional package of extra assets and maps.
These additional assets can be installed with the command bellow:
```
$ cd /opt/carla-simulator
$ ./ImportAssets.sh
```
• Test your server installation:
You can start the Carla server with the following command:
`$ ./CarlaUE4.sh`
A window containing a view over the city will pop up. This is the spectator
view. To fly around the city use the mouse and W A D S keys, holding
down the right mouse button to control the direction.
This is the server simulator which is now running and waiting for a client to
connect and interact with the world.
Troubleshooting
Some problem might arise when runing the server. These problem are reviewed
below:
• You get the error message: “error while loading shared libraries: libomp.so.5:
cannot open shared object file: No such file or directory”.
This error is solved by installing libomp5:
`$ sudo apt install libomp5`
• If you have 2 graphic cards (Intel and Nvidia) installed, Carla tend to select
the first active GPU device (which is often Intel GPU), even if you have
selected Nvidia in PRIME. This leads to a segmentation fault. To overcome
this, you have to tell Carla to prefer the Nvidia GPU:
`$ ./CarlaUE4.sh -preferNvidia`
• If you are installing Carla on a remote machine, forwarding the Carla server
GUI will fail. To solve this, you will need to start Carla in Off-screen mode.
In this mode, unreal Engine is working as usual, rendering is computed but
there is no display available. GPU based sensors return data as usual.
`$ ./CarlaUE4.sh -RenderOffScreen`
2.2 Install Carla Client on Linux
The Carla client API is implemented in Python.
2.2.1 Create a Conda Environment (optional)
It is highly recommended to install the CARLA client library in a conda virtual environment to avoid packages conflicts whit your other projects. Note for example that Carla requires python 3.7 (or python 2.7).
If your are not familiar with the Anaconda python distribution, see how to installit on Linux in Appendix 4.2.
Assuming you have Anaconda installed, create a virtual environment (named carla
for example) with python 3.7 and activate it:
```
$ conda create -n carla python=3.7
$ conda activate carla
```
2.2.2 Check your Pip Version
• Pip3 requires version 20.3 or higher. Check your pip3 version:
$ pip3 -V
If needed, upgrade pip3:
`$ pip3 install --upgrade pip`
• Install the python dependencies:
```
$ pip3 install pygame opencv-python
$ conda install numpy matplotlib
```
2.2.3 Install the Client
You are now ready to install the carla client in your created virtual environment.
CARLA provides .whl files for different Python versions. There can be found in
PythonAPI/carla/dist/. There is one file per supported Python version, indicated
by the file name. Install the one corresponding to your carla server- and python
version (0.9.13 & 3.7 at the time of writing):
```
$ cd /opt/carla-simulator/PythonAPI/carla/dist
$ pip3 install carla-0.9.13-cp37-cp37m-manylinux_2_27_x86_64.whl
```
2.3 Test your Complete Linux Installation
You can test your complete installation (client & server) by running the demo_run_carla.py script provided with this installation guide. An Opencv windows will pop up displaying a car driving around. Note that you must run this script within your carla conda environment and the server has to be runing (started via
./CarlaUE4.sh).
3. Windows Installation
3.1 Download the Carla Server for Windows
• Download the latest release (0.9.13 at the time of writing) of the carla package as well as the AdditionalMaps from here as shown in the figure below:
• Extract the Carla package (CARLA_0.9.13) in the folder of your choice.
• Extract the contents of AdditionalMaps_0.9.13 directly in th carla root folder, that is the folder where other carla module like CarlaUE4, Engine, etc,are located. The resulting structure will look like the figure bellow:
• Test your server installation:
You can start the Carla server by double clicking on the executable CarlaUE4.exe circled in red in the figure above.
A window containing a view over the city will pop up. This is the spectator view. To fly around the city use the mouse and W A D S keys, holding down the right mouse button to control the direction.
This is the server simulator which is now running and waiting for a client to
connect and interact with the world.
Troubleshooting
You get an error “The following component(s) are required to run this program
DirectX Runtime”. To solve this issue, download and install directX from here.
3.2 Install the Carla Client for Windows
• Create conda virtual environment (Optional but recommended):
It is highly recommended to install the CARLA client library in a conda virtual environment to avoid packages conflicts whit your other projects.
Note for example that Carla requires python 3.7 (or python 2.7).
If your are not familiar with the Anaconda python distribution, see how to
install it on Windows in Appendix 4.1.
Assuming you have Anaconda installed, create a conda virtual environment(named carla for example) with python 3.7 and activate it:
```
$ conda create -n carla python=3.7
$ conda activate carla
```
• Install the python dependencies:
```
$ pip3 install pygame opencv-python
$ conda install numpy matplotlib
```
• Install the client via the whl file:
CARLA provides .whl files for different Python versions. There can be found in PythonAPI/carla/dist/. There is one file per supported Python version,indicated by the file name.
In the conda command prompt, navigate to the directory where you extracted Carla, then navigate to PythonAPI/carla/dist/ and run the following
command to install the client corresponding to your carla server- and python
version (0.9.13 & 3.7 at the time of writing):
`$ pip3 install carla-0.9.13-cp37-cp37m-win_amd64.whl`
The process is shown in the figure bellow:
3.3 Test your Complete Windows Installation
You can test your complete installation (client & server) by running the demo_run_carla.py script provided with this installation guide. An Opencv windows will pop up displaying a car driving around.Note that you must run this script within your carla conda environment and the server has to be runing (started via
CarlaUE4.exe).
### Launhing Carla--
1. In terminal go to Carla_Simulator Folder
2. deactivate Conda encironment --conda deactivate
3. Run shell file -- ./CarlaUE4.sh
4. default carla window will popup on screen.
### Simulation --
1. PythonAPI's are used to perform simulations on carla.
2. Carla_Simulator/pythonAPI/examples have examle API scripts for better understanding of carla.
3. To run API script open this folder in terminsl then deactivate the conda environment.
4. run python name.py command to run the required API.
### PythonAPI --
These are the files used to manipulate carla and perform simulation on it.
Basic structure of API.
### client
* We need to connect Carla server to open port. Client controls simulator using client and world object.
1. client= carla.Client('localhost',2000)
2. world=client.get_world()
Client object serves to maintain client's connection. We can set any available port, port 2000 is set as default.
* we need map for simulation. worls object provides access to map element.
1. client.load_world('Town05')
* We can use spectator view to obsereve surrounding. we can use mouse to control pitch and yaw, QASD to control its movement.
1. spect=world.get_spectator()
2. transform=spect.get_transform()
3. location=tarnsform.location
4. spect.set_transform(transform1)-- this command will set spectator to given transfrom.
### Actors
* We required actors for simulation. Actors in carla are anything which performs actions within simulation. Actors in Carla involves Vehicles,Walkers,sensors,traffic Signs,traffic lights,spectator.
* Bluprints are the layouts allow the user to smoothly incorporate new actors in simulation,they are already made models with animations and series of attributes.
* All available bluprints are lsited in bluprints library.
#### Spawning
* first we have to take bluprint library to load actor.
1. bplib = world.get_bluprint_library()
* in this library we can find actor we want
1. vehicle_bp=bplib.find('vehicle.tesla_model3') -- it will find tesla_model3 in library.
* now we required spawn points to spawn the vehicles.
1. spawn_points= world.get_map().get_spawn_points() -- it will search available locations to spawn the vehicles in map and give list of spawn points.
* now we can spawn our vehicle in carla.
1. ego=world.spawn_actor(vehicle_bp,spawn_points[0])-- we can use world.try_spawn_actor() command to spawn the vehicle.
2. try_spawn_actor() don't give any error if any collision happen at spawn points and continue to run the script.
* to spawn other actors like sensors we follow same procedure, but only chane we have to do is we have to attach them to any vehicle.
1. camera_bp=bplib.find('sensor.camera.rgb')
2. camera=world.spawn_actor(camera_bp,spawn_points[0],attach_to=ego)
#### vehicle --
Vehicles are special type of actor in carla.It incorporates special type of components that simulates physcics of wheeled vehicles. This achived by applying types of different controls.
* carla.vehicle_control provides input for driving commands such as throttle,brake,steer etc.
1. ego.apply_control(carla.Vehicle_Control(throttle=1,steer=0))
* we can set vehicle to auto-pilot by using command
1. ego.set_autopilot(True)
* getter and setter function:-
1. ego.get_transform -- transform object of ego vehicle as output(location and it orientation)
2. ego.get_transform().get_location -- give location of ego vehicle from transform object.
3. ego.get_velocity() -- it give's velocity of vehicles in x,y,z direction.
4. ego.get_accleration()-- it will give acceleration of vehicle.
5. ego.set_target_velocity()-- set car to desired velocity.
6. ego.set_location() -- teleports actor to given location.
7. ego.set_transform() -- teleports the actor to given transform(location+rotation)