blob: 644f9d90aaa3fdf638247ec7544215ac12d9bf60 [file] [log] [blame]
<!DOCTYPE html><html lang="en-us" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="generator" content="Source Themes Academic 4.8.0">
<meta name="author" content="Fraunhofer FOKUS">
<meta name="description" content="">
<link rel="alternate" hreflang="en-us" href="https://www.eclipse.org/mosaic/tutorials/traffic_lights/">
<meta name="theme-color" content="#68145C">
<script src="/mosaic/js/mathjax-config.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/academicons/1.8.6/css/academicons.min.css" integrity="sha512-MCWBwPSput2UWNwyznVFLbD2iUc1e5VsdD1zahsWVzkDSUzyHhMZ4kCS3wgYSRm0mU+glwD/Q9lSJrDPwbUL2A==" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-1/css/all.min.css" integrity="sha512-ZYg+hQvLlM0W9C3P6vTpes5LmJ66G2EsroxDNzwD6qiulckldb29eD9I672HL2X+LH5nRhY1sQqZLJGB+aUUPg==" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css" integrity="sha512-H9jrZiiopUdsLpg94A333EfumgUBpO9MdbxStdeITo+KEIMaNfHNvwyjjDJb+ERPaRS6DpyRlKbvPUasNItRyw==" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/atom-one-light.min.css" crossorigin="anonymous" title="hl-light">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/atom-one-light.min.css" crossorigin="anonymous" title="hl-dark" disabled>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/lazysizes/5.2.2/lazysizes.min.js" integrity="sha512-TmDwFLhg3UA4ZG0Eb4MIyT1O1Mb+Oww5kFG0uHqXsdbyZz9DcvYQhKpGgNkamAI6h2lGGZq2X8ftOJvF/XjTUg==" crossorigin="anonymous" async></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" integrity="" crossorigin="anonymous" async></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,700i%7CRoboto+Mono&display=swap">
<link rel="stylesheet" href="/mosaic/css/academic.css">
<link rel="alternate" href="/mosaic/tutorials/traffic_lights/index.xml" type="application/rss+xml" title="Eclipse MOSAIC">
<link rel="manifest" href="/mosaic/index.webmanifest">
<link rel="icon" type="image/png" href="/mosaic/images/icon_hu6bdfb97c7e23190c70e41ca0e15a9fce_30436_32x32_fill_lanczos_center_2.png">
<link rel="apple-touch-icon" type="image/png" href="/mosaic/images/icon_hu6bdfb97c7e23190c70e41ca0e15a9fce_30436_192x192_fill_lanczos_center_2.png">
<link rel="canonical" href="https://www.eclipse.org/mosaic/tutorials/traffic_lights/">
<meta property="twitter:card" content="summary">
<meta property="og:site_name" content="Eclipse MOSAIC">
<meta property="og:url" content="https://www.eclipse.org/mosaic/tutorials/traffic_lights/">
<meta property="og:title" content=" | Eclipse MOSAIC">
<meta property="og:description" content=""><meta property="og:image" content="https://www.eclipse.org/mosaic/images/logo.svg">
<meta property="twitter:image" content="https://www.eclipse.org/mosaic/images/logo.svg"><meta property="og:locale" content="en-us">
<meta property="og:updated_time" content="2019-05-05T00:00:00&#43;01:00">
<title> | Eclipse MOSAIC</title>
</head>
<body id="top" data-spy="scroll" data-offset="70" data-target="#TableOfContents" class=" page-mosaic page-tutorials page-traffic_lights ">
<aside class="search-results" id="search">
<div class="container">
<section class="search-header">
<div class="row no-gutters justify-content-between mb-3">
<div class="col-6">
<h1>Search</h1>
</div>
<div class="col-6 col-search-close">
<a class="js-search" href="#"><i class="fas fa-times-circle text-muted" aria-hidden="true"></i></a>
</div>
</div>
<div id="search-box">
<input name="q" id="search-query" placeholder="Search..." autocapitalize="off"
autocomplete="off" autocorrect="off" spellcheck="false" type="search">
</div>
</section>
<section class="section-search-results">
<div id="search-hits">
</div>
</section>
</div>
</aside>
<nav class="navbar navbar-expand-lg navbar-light compensate-for-scrollbar" id="navbar-main">
<div class="container">
<div class="d-none d-lg-inline-flex">
<a class="navbar-brand" href="/mosaic/"><img src="/mosaic/images/logo.svg" alt="Eclipse MOSAIC"></a>
</div>
<button type="button" class="navbar-toggler" data-toggle="collapse"
data-target="#navbar-content" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span><i class="fas fa-bars"></i></span>
</button>
<div class="navbar-brand-mobile-wrapper d-inline-flex d-lg-none">
<a class="navbar-brand" href="/mosaic/"><img src="/mosaic/images/logo.svg" alt="Eclipse MOSAIC"></a>
</div>
<div class="navbar-collapse main-menu-item collapse justify-content-start" id="navbar-content">
<ul class="navbar-nav d-md-inline-flex">
<li class="nav-item">
<a class="nav-link " href="/mosaic/about"><span>About</span></a>
</li>
<li class="nav-item">
<a class="nav-link " href="/mosaic/about_deprecated"><span>About (Deprecated)</span></a>
</li>
<li class="nav-item">
<a class="nav-link " href="/mosaic/news"><span>News</span></a>
</li>
<li class="nav-item">
<a class="nav-link " href="/mosaic/docs"><span>Documentation</span></a>
</li>
<li class="nav-item">
<a class="nav-link active" href="/mosaic/tutorials"><span>Tutorials</span></a>
</li>
<li class="nav-item">
<a class="nav-link " href="/mosaic/download"><span>Download</span></a>
</li>
<li class="nav-item">
<a class="nav-link " href="/mosaic/community"><span>Community</span></a>
</li>
</ul>
</div>
<ul class="nav-icons navbar-nav flex-row ml-auto d-flex pl-md-2">
<li class="nav-item">
<a class="nav-link js-search" href="#" aria-label="Search"><i class="fas fa-search" aria-hidden="true"></i></a>
</li>
<li class="nav-item ">
<a href="https://github.com/eclipse/mosaic" target="blank">
<i class="fab fa-github" aria-hidden="true"></i>
</a>
</li>
</ul>
</div>
</nav>
<div class="universal-wrapper pt-3">
<h1></h1>
</div>
<div class="universal-wrapper">
<div class="article-style"><h1 id="traffic-lights">Traffic Lights</h1>
<a class="mosaic-btn mosaic-btn-primary" href="https://www.dcaiti.tu-berlin.de/research/simulation/download/" title="Download Traffic Lights Tutorial">Download Traffic Lights Tutorial</a>
<p>In this brief tutorial we will discuss how to interact with traffic lights via Eclipse MOSAIC. Usually the position and the lanes they control are coming from the OpenStreetmap-data, which we will also assume during this tutorial. Note that this tutorial is intended to be used with the Tiergarten scenario described in the first tutorial in Chapter 4, so creating a new scenario for is not necessary here and the Traffic Light data is already exported.</p>
<p>At first we cover the general steps necessary to enable traffic lights and eventually “map” applications onto them. Each step is described in more detail later on. After completing this tutorial you will be able to:</p>
<ol>
<li>Tell <code>scenario-convert</code> to export the traffic light information into the database</li>
<li>Determine the node ids of the traffic lights which should have applications on them</li>
<li>Adjust the mapping configuration of Eclipse MOSAIC accordingly and assign the desired application(s) onto one or more traffic lights.</li>
</ol>
<p>Additional information on how to use traffic lights, how they are modeled within sumo and how their phases work can be found in the sumo wiki unter
<a href="https://sumo.dlr.de/docs/Simulation/Traffic_Lights.html" target="_blank" rel="noopener">Sumo/Traffic Lights</a>.</p>
<h2 id="use-scenario-convert-to-export-traffic-lights">Use scenario-convert to export traffic lights</h2>
<p>Although the Tiergarten scenario which we are focusing on in this tutorial already has the traffic lights exported from the .osm file, this step is important if you desire to set up an own scenario. For the Tiergarten example, the scenario-convert command line looks like this:</p>
<pre><code class="language-windows">scenario - convert -19.0. jar -- osm2sumo -d tiergarten .db -i tiergarten .osm -l -n
</code></pre>
<p><sub><em>Export of traffic lights using scenario-convert</em></sub></p>
<p>Note the -l switch here that actually exports the traffic light information from the .osm file to the tiergarten.db database. If this command line switch is omitted the traffic lights will not be available in the scenario. More information on how traffic lights are handled by Open Streetmap can be found in their wiki
<a href="https://wiki.openstreetmap.org/wiki/Tag:highway%3Dtraffic_signals" target="_blank" rel="noopener">OpenStreetMap/Traffic Signals</a>.</p>
<h2 id="determine-the-traffic-lights-that-should-be-equipped-with-applications">Determine the traffic lights that should be equipped with applications</h2>
<p>The next step is to decide which traffic lights should have applications on them. Since their ID(s) have to be referenced in the mapping, we will have to determine them first. There are several ways to do this, e.g. taking them directly from the database using a tool like <code>sqlitebrowser</code> or extract them directly with a text editor fromthe .net.xml file that gets generated by scenario-convert for usage with sumo. However, here we will focus on a graphical approach using <code>sumo-gui</code> since it is the easiest way to determine the exact traffic lights we want to map applications too.</p>
<figure id="figure-locating-traffic-lights-in-sumo-gui">
<a data-fancybox="" href="images/tlSumoGui.png" data-caption="Locating traffic lights in sumo gui">
<img src="images/tlSumoGui.png" alt="" >
</a>
<figcaption data-pre="Figure " data-post=":" class="numbered">
Locating traffic lights in sumo gui
</figcaption>
</figure>
<p>The figure above shows how to locate a specific traffic light, or more precise, a traffic light group. The process is as simple as scrolling to the desired traffic light, right click on it and write down the number behind tlLogic in the drop down menu or use the <code>copy to clipboard</code> feature of the sumo gui. This id is then used in the next section which explains how to actually map applications to a traffic light.</p>
<h2 id="configure-the-mapping-for-traffic-lights">Configure the mapping for traffic lights</h2>
<p>Now that we have the ids of the traffic lights we can modify the mapping to assign application(s) to them. Note that the tutorial scenario already has applications assigned to two arbitrary traffic lights, so the mapping file bundled with it can also be used as a starting point here. In general, the mapping looks the same as for vehicles or RSUs. First, we define a prototype that is used for all subsequent traffic lights:</p>
<pre><code class="language-json">{
&quot;prototypes&quot;:[
{
&quot; applications &quot;:[&quot;com.vsimrti.applications.additionalsamples.misc.TrafficLightExample &quot;],
&quot; name &quot;:&quot; TrafficLight &quot;
}
]
}
</code></pre>
<p>The
<a href="files/additional.add.xml" title="ignore">listing</a> shows an additional prototype called <code>TrafficLight</code> that gets associated with the <code>TrafficLightExample</code> application. Note that the application that should run on the traffic light has to extend <code>AbstractApplication&lt;TrafficLightOperatingSystem&gt;</code> in order to work. The next step is to use this prototype and assign it to a traffic light we found in the section before using the sumo gui:</p>
<pre><code class="language-json">&quot; tls &quot;:[
{
&quot;tlName&quot;: &quot;27011311&quot;,
&quot;name&quot;:&quot; TrafficLight &quot;
},
{
&quot;tlName&quot;: &quot;252864801&quot;,
&quot;name&quot;:&quot; TrafficLight &quot;
}
]
</code></pre>
<p>The listing above shows as an example how this prototype is assigned via the <code>name</code> attribute to specific traffic lights. The important aspect here is that <code>tlName</code> refers to the id of the traffic light we found via the sumo gui in
<a href="#determine-the-traffic-lights-that-should-be-equipped-with-applications">section</a> which must exactly match each other.</p>
<h2 id="the-traffic-light-api">The Traffic Light API</h2>
<p>In order to access the traffic light functionality from within an application it must extend the <code>AbstractApplication&lt;TrafficLightOperatingSystem&gt;</code> abstract class. There are two main functionalities provided by it, reachable from the application operating system that can be acquired by using the <code>getOperatingSystem()</code> method:</p>
<ul>
<li>Change the currently active traffic light program via <code>setProgramById()</code></li>
<li>Adjust the remaining time of the currently active phase via <code>setPhaseRemainingDuration()</code></li>
</ul>
<p>However, adding a new traffic light program from within the application at runtime using the Eclipse MOSAIC application interface is currently not possible and has to be done beforehand via sumo as described
<a href="http://sumo.dlr.de/wiki/Simulation/Traffic_Lights" target="_blank" rel="noopener">here</a>. The two main ways of doing this is
to use an <code>additional-file</code> or the <code>tls_csv2SUMO.py</code> tool bundled with sumo. However, it is possible to add a new program by using the TraCI interface as described
<a href="http://sumo.dlr.de/wiki/TraCI/Change_Traffic_Lights_State" target="_blank" rel="noopener">here</a>.</p>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.1.4/imagesloaded.pkgd.min.js" integrity="sha512-S5PZ9GxJZO16tT9r3WJp/Safn31eu8uWrzglMahDT4dsmgqWonRY9grk3j+3tfuPr9WJNsfooOR7Gi7HL5W2jw==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.6/isotope.pkgd.min.js" integrity="sha512-Zq2BOxyhvnRFXu0+WE6ojpZLOU2jdnqbrM1hmVdGzyeCa1DgM3X5Q4A/Is9xA1IkbUeDd7755dNNI/PzSf2Pew==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js" integrity="sha512-uURl+ZXMBrF4AwGaWmEetzrd+J5/8NRkWAvJx5sbPSSuOb0bZLqf+tOzniObO00BjHa/dD7gub9oCGMLPQHtQA==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.4.8/mermaid.min.js" integrity="sha512-1tS1YUns336Mtxl+vkaLcADPwE1CPNVy3WEf7nrI7DGMMb6/FAVBgL2IzAWVBkB6vVuK94s2zVoiXcw1QZ9S1g==" crossorigin="anonymous" title="mermaid"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/highlight.min.js" integrity="sha512-1LdB3V708w6G4QRl7NsVdTr7MDibyRXr9stQZ+EGjEE0ZPMZkA//ir7kCWmFyxdAJNIRXdR/ZeJmCV0boyiCXw==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/languages/java.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/languages/json.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/languages/xml.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/languages/shell.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/languages/dos.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.js" integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og==" crossorigin="anonymous"></script>
<script>const code_highlighting = true;</script>
<script>const isSiteThemeDark = false;</script>
<script>
const search_config = {"indexURI":"/mosaic/index.json","minLength":1,"threshold":0.3};
const i18n = {"no_results":"No results found","placeholder":"Search...","results":"results found"};
const content_type = {
'post': "Posts",
'project': "Projects",
'publication' : "Publications",
'talk' : "Talks"
};
</script>
<script id="search-hit-fuse-template" type="text/x-template">
<div class="search-hit" id="summary-{{key}}">
<div class="search-hit-content">
<div class="search-hit-name">
<a href="{{relpermalink}}">{{title}}</a>
<div class="article-metadata search-hit-type">{{type}}</div>
<p class="search-hit-description">{{snippet}}</p>
</div>
</div>
</div>
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.2.1/fuse.min.js" integrity="sha512-o38bmzBGX+hD3JHWUFCDA09btWaqrNmoJ3RXLlrysA7PP01Kgs4UlE4MhelE1v5dJR3+cxlR4qQlotsW7jKsnw==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/jquery.mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script>
<script src="/mosaic/js/academic.min.12ac32fae0b6a379104641bfce6313cb.js"></script>
<script src="https://www.eclipse.org/js/mosaic-wg-features-widget.js"></script>
<div class="footer-wrap">
<div class="container">
<footer class="site-footer">
<div class="row">
<div class="col-sm-4">
<b>Eclipse MOSAIC</b>
<ul>
<li>
<a href="/mosaic/mosaic/download/" title="Download Eclipse MOSAIC" >
Download Eclipse MOSAIC
</a>
</li>
<li>
<a href="/mosaic/mosaic/documentation" title="Documentation" >
Documentation
</a>
</li>
<li>
<a href="/mosaic/mosaic/tutorials" title="Tutorials" >
Tutorials
</a>
</li>
<li>
<a href="/mosaic/mosaic/license" title="License" >
License
</a>
</li>
<li>
<a href="/mosaic/mosaic/community/#projects" title="Projects" >
Projects
</a>
</li>
<li>
<a href="/mosaic/mosaic/publications" title="Publications" >
Publications
</a>
</li>
</ul>
</div>
<div class="col-sm-4">
<b>Community</b>
<ul>
<li>
<a href="/mosaic/mosaic/community" title="Eclipse MOSAIC Community" >
Eclipse MOSAIC Community
</a>
</li>
<li>
<a href="/mosaic/mosaic/contribution" title="How to contribute" >
How to contribute
</a>
</li>
<li>
<a href="https://github.com/eclipse/mosaic" title="Github" target="_blank" rel="noopener">
Github
</a>
</li>
<li>
<a href="https://accounts.eclipse.org/mailing-list/mosaic-dev" title="Mailing list" target="_blank" rel="noopener">
Mailing list
</a>
</li>
</ul>
</div>
<div class="col-sm-4">
<b>Eclipse Foundation</b>
<ul>
<li>
<a href="https://www.eclipse.org/" title="About Eclipse Foundation" target="_blank" rel="noopener">
About Eclipse Foundation
</a>
</li>
<li>
<a href="https://www.eclipse.org/legal/privacy.php" title="Privacy Policy" target="_blank" rel="noopener">
Privacy Policy
</a>
</li>
<li>
<a href="https://www.eclipse.org/legal/termsofuse.php" title="Website terms of use" target="_blank" rel="noopener">
Website terms of use
</a>
</li>
<li>
<a href="https://www.eclipse.org/legal/copyright.php" title="Copyright" target="_blank" rel="noopener">
Copyright
</a>
</li>
<li>
<a href="https://www.eclipse.org/legal" title="Legal" target="_blank" rel="noopener">
Legal
</a>
</li>
</ul>
</div>
</div>
<div class="row justify-content-center mt-3 position-relative">
<p class="powered-by text-center font-italic mb-0 pb-0">
Powered by the
<a href="https://sourcethemes.com/academic/" target="_blank" rel="noopener">Academic theme</a> for
<a href="https://gohugo.io" target="_blank" rel="noopener">Hugo</a>.
</p>
<span class="position-absolute" aria-hidden="true" style="right: 0;">
<a href="#" class="back-to-top">
<span class="button_icon">
<i class="fas fa-chevron-up fa-2x"></i>
</span>
</a>
</span>
</div>
</footer>
</div>
</div>
<div id="modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Cite</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<pre><code class="tex hljs"></code></pre>
</div>
<div class="modal-footer">
<a class="btn btn-outline-primary my-1 js-copy-cite" href="#" target="_blank">
<i class="fas fa-copy"></i> Copy
</a>
<a class="btn btn-outline-primary my-1 js-download-cite" href="#" target="_blank">
<i class="fas fa-download"></i> Download
</a>
<div id="modal-error"></div>
</div>
</div>
</div>
</div>
</body>
</html>