Auto Model Car Simulator
Auto Model Car Simulator
S OFTWARE P ROJECT
Authors: Supervisors:
Benjamin K AHL Prof. Dr. Daniel G ÖHRING
Abbas M OHAMMED M URREY Stephan S UNDERMANN
October 7, 2019
1
Preface
The modern-day surge in autonomous driving research and development has given
new-found importance to the virtual simulation of such systems.
Self-driving cars typically use combined data received from a wide range of sen-
sors to construct a model of their surrounding environment. Commonly employed
sensors include LiDAR, GPS, stereoscopic cameras and inertial measurement units.
The sensory data from these is interpreted by a series of control systems which iden-
tify obstacles, navigation paths and signage to extrapolate the respectively expected
driving-motion and set the vehicles actuators accordingly.
Being both cost-intensive and dangerous to test on real-world vehicles, the de-
velopment of such systems is often carried out with a simulator or a miniaturized
model.
Introduction
A fundamental facet of the proposed simulation is for a virtual vehicle to mimic the
real-world movement of an AMC when delivered the same actuator parameters.
In order to circumvent the complex physical formulae required to reproduce
car-movement on a tire-friction basis, we employ a highly simplified, determinis-
tic model based on Ackermann steering geometry.
This chapter covers the mathematical basis of said model as well as a list gener-
ally defined goals the software aims to achieve.
• Support for most common sensor types. Notably LiDAR, camera, GPS and
motor-ticks.
• Allow controller programs to run like regular ROS nodes, making a real AMC
and a simulated one interchangeable at will.
• Allow for easy adaptability in case of changes to the car. (Such as different
ROS topic names or datatypes)
Furthermore, the API and all code needs to be documented and unit-tested so
that it can be maintained in the long term.
Chapter 2. Introduction 3
Each simulated vehicle will be subject to the values of a steering and a speed topic,
which are externally adjusted by the end-users control-program. These topics are
not published to by the simulator.
Sensors can be mounted on vehicles or placed into the environment. Each sensor
publishes its measured data to a singular topic. The following four sensor types are
commonly mounted on each AMC:
• Lidar: Performs circular scans with a given frequency and publishes measured
data after each scan. The data is provided in the form of a list of distances
sorted by angle.
• Ticks: Continuously publishes the ’ticks’ the vehicles primary motor under-
went in the last time-interval. A faster turning-speed will equate to a greater
amount of ticks and vice versa.
F IGURE 2.2: A Situation when turning both front tires by the same
angle
Instead, to avoid the friction produced from keeping the tires off of their natural
path, each tire is ascribed its individual angle of rotation derived from the angle of
a virtual front wheel that lies at the center of the vehicle (Henceforth called the ideal
tire). This predicament is depicted in figure 2.3.
Chapter 2. Introduction 5
Given φ as the angular disposition of a front tire and L as the distance to the
respective back-tire, rudimentary trigonometry yields the distance r between the
back-tire and the turning center:
L L
tan(φ) = ⇒ r= (2.1)
r tan(φ)
The same equation applies to each tire-pair, yielding following three equations:
L
φ0 = arctan (2.2)
r+W
L
φ = arctan (2.3)
r
L
φ1 = arctan (2.4)
r−W
−
→
Normalizing V and scaling it by the radius r yields the vector pointing from the
tire to the center of rotation:
−
→ −
→
C = B +r∗ V (2.6)
Dependencies
3.1 Unity3D
While initially contemplating the possibility of building an OpenGL-based simulator
from scratch, we ultimately decided to utilize the powerful tools provided by the
Unity Engine as a fundament for the necessary rendering and collision calculations.
The Unity Engine[5] is developed by Unity Technologies and provides a highly
flexible framework for all kinds of real-time 3D rendering software, including games,
simulations as well as architecture and engineering tools.
The engine was chosen over its peers due to the convenience of providing a
plethora of assets and tools to accelerate the development process, helping us create
a finished and usable application within the given, limited time-span.
Furthermore, the manifold of supported platforms would allow us to deploy the
finished software to various systems as well as expand upon it through the inte-
grated support of controllers, VR-hardware, mobile support etc.
3.2 RosSharp
RosSharp (or simply ROS#) is a set of C#-based open source libraries that enable
easy communication between ROS and .NET applications.
Provided by Siemens[4], the library includes ready-to-go classes for a variety of
uses such as publishing of laserscan- and camera-topics as well as Urdf parsing.
Given its seamless integration with the Unity Engine, ROS# was chosen as our
primary interface with the ROS environment.
3.3 ROSBridge
In order to establish a reliable communication between ROS# and ROS itself, a Ros-
Bridge server is employed.
Rosbridge provides a programming language agnostic, JSON-based API to ROS
functionalities for non-ROS programs. Topics and their values become accessible
through websockets and are sent in accordance to the rosbridge protocol.
The rosbridge-suite package is a collection of packages that implement the ros-
bridge protocol, which comes by default with any regular installation of the ROS
melodic distribution.
Implementation Details
4.2 API
To communicate with the rosbridge-server we employ a ROS# object of the RosCon-
nector class. All components publish and subscribe to topics exclusively through this
interface. This section describes the implemented APIs accessible by external ROS
control programs.
Chapter 4. Implementation Details 9
The base ROS# version provides most datatypes used in ROS applications, but
the specialized types such as UInt8 and Int16 were not recognized. In order to pro-
vide a seamless plug between simulation and reality, the simulated vehicle had to
recognize and use these types.
For this purpose the ROS# project was accordingly modified and a newly com-
piled .dll file substituted.
The three macro symbols {ID}, {NAME} and {TYPE} can be utilized here to include
the id-number, name or type of a component in its topic-string. In multi-car setups,
these may prevent several cars from publishing to the same topics by, for example,
appending a "/vehicle_{ID}" as a prefix to each topic.
For use-cases where camera images are less crucial, two further scenes were cre-
ated each with substantially less detail and, as a result, far better performance.
The UI includes an inspector panel which allows the user to perform simple
modifications to the environment such as placing obstacles, attaching sensors and
moving objects. UI elements will be presented in greater detail in section 4.5.
4.4.1 Chassis
The chassis is responsible for a cars movement and is divided into two axles:
• The steering axle subscribes to the steering topics listed in table 4.2 and calcu-
lates the respective turning circle of the car by means described in chapter 2.
The various interpolation-parameters of the different topics are listed in their
respective settings files (such as steeringaxle_interp_nrm.txt for the nor-
malized topic) and can be adjusted by the user.
• The propulsion axle derives the cars speed from the three speed topics listed in
table 4.2, rotates the vehicle by the respective amount around the circle-center
obtained from the steering axle and finally produces the appropriate amount
of ticks in proportion to the distance travelled.
Similarly to above, speedaxle_interp_nrm.txt and similar files define the in-
terpolation values for speed parameters. How these values were obtained is
described below.
0 0 0 0 0 0 0 0 0
0.1 19 0.10982659 0.15 30 0.17647059 0.1 20 0.06153846
0.2 66 0.38150289 0.2 52 0.30588235 0.2 125 0.38461538
0.3 114 0.65895954 0.3 100 0.58823529 0.3 209 0.64307692
0.4 163 0.94219653 0.4 146 0.85882353 0.4 315 0.96923077
0.5 211 1.21965318 0.5 195 1.14705882 0.5 410 1.26153846
0.6 259 1.49710983 0.6 244 1.43529412 0.6 # #
0.7 304 1.75722543 0.7 290 1.70588235 0.7 # #
0.8 353 2.04046243 0.8 340 2 0.8 # #
0.9 398 2.30057803 0.9 385 2.26470588 0.9 # #
1 448 2.58959538 1 440 2.58823529 1 # #
Tick's
173 t/m 170 t/m 325 t/m
Counter
For any values greater than 0.1, the relation is evidently a linear one. The interpolation-
curve points for the normalized topic were thus adopted to mirror this graph. The
regular speed topic would follow a simple 1:1 linear relation without any offsets.
Chapter 4. Implementation Details 13
1
≈ 0.00578 meters (4.1)
173
In order to emit the adequate amount of ticks, a propulsion axle requires the re-
spective distance travelled since the last emission. Given that the simulation moves
vehicles exclusively on a rotation-basis, we need to calculate the arc-length of any
given rotation in order to extrapolate the respective distance travelled.
L = r ∗ φ[rad] (4.2)
This distance is proportional to the cars speed v by the time difference between
P0 and P1 , which we denote as ∆t:
v ∗ ∆t = r ∗ φ (4.3)
This yields the relation between the cars velocity (given by its speed topics) and
the angle of rotation:
v ∗ ∆t
=φ (4.4)
r
Chapter 4. Implementation Details 14
We accumulate the total distance travelled until it reaches the threshold given by
(4.1), at which point we emit ticks equal to the following fraction:
j distance travelled k
ticks emitted = (4.5)
0.00578
4.4.4 Camera
Camera images are rendered through a regular unity camera-object and compressed
to a jpeg format before being published.
We chose a focal length of 43.6 (equivalent to 30.8 FOV) as a rough estimate from
sample images produced by AMCs. This value as well as any other parameters are
modifiable by the end user through UI elements (see 4.5).
4.4.5 Lidar
The Unity engine provides a native Raycast(...) method which returns a point of
contact on a collision-model when given a ray origin and propagation vector.
Carrying out a circular series of raycasts in compliance with the corresponding
lidar parameters would provide a reasonable approximation for a real lidar reading.
Conveniently, ROS# provides a LaserScanReader class specifically for this purpose as
well as three different tools (lines, spheres and mesh) to visualize lidar-scans.
In accordance with the lidar mounted on AMCs, the virtual sensor takes 360
samples in counterclockwise order with a minimum range of 0.15m and maximum
range of 16m. As with any other sensor, these default values can be adjusted for each
virtual car as the user sees fit.
Chapter 4. Implementation Details 15
F IGURE 4.8: Virtual lidar data visualized with a set of lines and
spheres at the impact point.
4.4.6 GPS
To avoid needless unit-conversion, we chose 1 Unity3d-unit to be equivalent to 1
meter in the real world. The GPS sensor would thus only have to broadcast the cars
position in world coordinates.
However, the axes-arrangement of coordinates provided by an AMC differ from
the axes-standard in the Unity engine, thus requiring a rudimentary coordinate-
conversion process of swapping, as well as reversing, the y- and z-axis.
The quaternion describing the vehicles world-space rotation follows the same
pattern.
F IGURE 4.9: Point of contact marked with a yellow sphere post colli-
sion.
Chapter 4. Implementation Details 16
4.5 UI
A significantly large portion of development time was dedicated towards fleshing
out a usable UI that would provide any necessary functionalities to the user without
requiring a full recompilation of the program. These are organized into a total of 14
windows, each with its own distinct purpose.
Describing each in detail would go beyond the scope of this report, instead we
discuss the most important ones here, leaving a more detailed description (as well
as instructions of use) on the simulators github documentation (See [6]).
4.5.2 Utilities
In addition, the simulator provides a wide range of utility tools meant to facilitate
generic tasks such as moving/placing cars, keeping track of topic values etc.
Result Evaluation
F IGURE 5.1: Camera image from simulation (left) and from reality
(right)
Figure 5.1 shows camera images produced by a real AMC and a simulated AMC
side-by-side. It becomes clear that the simulated image suffers from some jagged
edges and aliasing issues as opposed to the real one. Upon further inspection some
compression artifacts can be found as well.
These problems could be remedied by applying anti-aliasing filtering to the ren-
dered image as well as reducing the used compression factor of 50%.
In addition, the real image is subject to a slight red hue, presumably produced
by the mounted camera. Introducing this hue into the simulation would require
changing the lighting settings and recalculating lighting textures or, alternatively,
applying a color-correction filter to the rendered image.
F IGURE 5.2: Camera image from simulation (left) and from reality
(right) with an applied binary filter
Chapter 5. Result Evaluation 19
5.1.2 Lidar
Figure 5.3 shows the path of a vehicle when running a simple obstacle avoidance
program as well as the respective collected lidar data.
The simulated data is far smoother but still fairly analogous to the real data. A
simple way of increasing realism would be to introduce a random noise factor to
measured lidar points.
5.2 Performance
The publishing frequency of sensors is, of course, bound by the applications overall
frame-rate. Its heavy emphasis on image rendering makes the simulation heavily
bottle-necked by the employed GPU, in particular when using multiple camera sen-
sors.
Rough measurements for the most complex scene are listed below. When using
the minimalist scene the frame-rate is significantly improved.
5.3 Verdict
In total, we feel that most of the goals listed in chapter 2 have been met in a satis-
factory way while still leaving some clear room for improvement. Here we list the
most common points of contention:
• The emphasis on using simple maths instead of complex physics relieves some
CPU stress found in other simulator frameworks such as gazeebo. However,
the detailed environment puts a significant amount of strain on the GPU and
produces camera images of limited quality.
• Simple changes to the car (like using slightly different lidar sensors) are simple
to adjust in the simulator, but alterations on the underlying framework (like
switching from regular datatypes to autominy datatypes) require a complete
recompilation of the ROS# library as well as the simulator.
• Due to the rosbridge-based API the simulator is simple to set up even if run-
ning on a different machine than the controller program.
• We found that using a developers setup within the Unity Editor generally
made using the simulator more flexible than using the built executable. This
means that developers that are familiar with the Unity Engine can enjoy a
highly flexible workflow and incorporate simple changes efficiently.
• The simulator can be easily expanded onto different platforms and hardware
(mobile, VR, etc.) due to the flexibility of the Unity Engine.
• The simulator does not have a save/load function, making it highly session
dependent. Example: Making lots of changes to car will have to be redone if
the simulator is restarted.
21
References
[6] B ENJAMIN K AHL , A BBAS M URREY, Project github repository, 2019. URL: https:
//[Link]/Helliaca/AutoModelCar_Simulator.
[7] J.-S. Z HAO , Z.-J. L IU , AND J. D AI, Design of an ackermann type steering mechanism,
Journal of Mechanical Engineering Science, 227 (2013).