| <!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/docs/develop_applications/"> |
| |
| |
| |
| |
| |
| |
| |
| <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/docs/develop_applications/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/docs/develop_applications/"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <meta property="twitter:card" content="summary"> |
| |
| <meta property="og:site_name" content="Eclipse MOSAIC"> |
| <meta property="og:url" content="https://www.eclipse.org/mosaic/docs/develop_applications/"> |
| <meta property="og:title" content="Basics in Application Development | 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-08-06T00:00:00+00:00"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <title>Basics in Application Development | Eclipse MOSAIC</title> |
| |
| </head> |
| |
| <body id="top" data-spy="scroll" data-offset="70" data-target="#TableOfContents" class=" page-mosaic page-docs page-develop_applications "> |
| |
| <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 style="visibility:visible;" 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-center" 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/news"><span>News</span></a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link active" href="/mosaic/docs"><span>Documentation</span></a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="nav-item"> |
| <a class="nav-link " 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="container docs"> |
| <div class="row flex-xl-nowrap"> |
| <div class="col-12 col-md-3 col-xl-3 docs-sidebar"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <form class="docs-search d-flex align-items-center"> |
| <button class="btn docs-toggle d-md-none p-0 mr-3" type="button" data-toggle="collapse" data-target="#docs-nav" aria-controls="docs-nav" aria-expanded="false" aria-label="Toggle section navigation"> |
| <span><i class="fas fa-bars"></i></span> |
| </button> |
| |
| |
| <input name="q" type="search" class="form-control" placeholder="Search..." autocomplete="off"> |
| |
| </form> |
| |
| <nav class="collapse docs-links" id="docs-nav"> |
| |
| |
| |
| |
| |
| |
| <div class="docs-toc-item"> |
| <a class="docs-toc-link" href="/mosaic/docs/getting_started">Getting Started</a> |
| <ul class="nav docs-sidenav"> |
| |
| <li > |
| <a href="/mosaic/docs/getting_started/">Download</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/getting_started/run_mosaic/">Run Eclipse MOSAIC</a> |
| </li> |
| |
| </ul> |
| |
| |
| </div> |
| |
| <div class="docs-toc-item"> |
| <a class="docs-toc-link" href="/mosaic/docs/run_simulations">Run Simulations</a> |
| <ul class="nav docs-sidenav"> |
| |
| <li > |
| <a href="/mosaic/docs/run_simulations/">Run a single simulation</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/run_simulations/results/">Simulation Results</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/run_simulations/simulation_set/">Run a Simulation Set</a> |
| </li> |
| |
| </ul> |
| |
| |
| </div> |
| |
| <div class="docs-toc-item"> |
| <a class="docs-toc-link" href="/mosaic/docs/visualization">Visualization</a> |
| <ul class="nav docs-sidenav"> |
| |
| <li > |
| <a href="/mosaic/docs/visualization/filevis/">FileOutput</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/visualization/">WebSocket Visualizer</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/visualization/statistics/">Statistics Visualizer</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/visualization/itef/">ITEF</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/visualization/phabmap/">PHABMap</a> |
| </li> |
| |
| </ul> |
| |
| |
| </div> |
| |
| <div class="docs-toc-item"> |
| <a class="docs-toc-link" href="/mosaic/docs/simulators">Simulators</a> |
| <ul class="nav docs-sidenav"> |
| |
| <li > |
| <a href="/mosaic/docs/simulators/">Overview</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/simulators/traffic_simulator_sumo/">Traffic - Eclipse SUMO</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/simulators/network_simulator_omnetpp/">Network - OMNeT++</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/simulators/network_simulator_ns3/">Network - ns-3</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/simulators/network_simulator_sns/">Network - SNS</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/simulators/network_simulator_cell/">Network - Cell</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/simulators/application_simulator/">Application Simulator</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/simulators/environment_simulator/">Environment Simulator</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/simulators/battery_simulator/">Battery Simulator</a> |
| </li> |
| |
| </ul> |
| |
| |
| </div> |
| |
| <div class="docs-toc-item"> |
| <a class="docs-toc-link" href="/mosaic/docs/building_scenarios">Building Scenarios</a> |
| <ul class="nav docs-sidenav"> |
| |
| <li > |
| <a href="/mosaic/docs/building_scenarios/">Simulation Scenarios</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/building_scenarios/scenario_convert/">Scenario Convert</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/building_scenarios/scenario_configuration/">Additional Scenario Configuration</a> |
| </li> |
| |
| </ul> |
| |
| |
| </div> |
| |
| <div class="docs-toc-item"> |
| <a class="docs-toc-link" href="/mosaic/docs/develop_applications">Create Applications</a> |
| <ul class="nav docs-sidenav"> |
| |
| <li class="active"> |
| <a href="/mosaic/docs/develop_applications/">Basics</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/develop_applications/communication/">V2X Communication</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/develop_applications/event_scheduler/">Event Scheduling</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/develop_applications/road_traffic/">Scenario Database</a> |
| </li> |
| |
| </ul> |
| |
| |
| </div> |
| |
| <div class="docs-toc-item"> |
| <a class="docs-toc-link" href="/mosaic/docs/extending_mosaic">Extending Eclipse MOSAIC</a> |
| <ul class="nav docs-sidenav"> |
| |
| <li > |
| <a href="/mosaic/docs/extending_mosaic/">Core Concepts</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/extending_mosaic/simulator_coupling/">Simulator Coupling</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/extending_mosaic/interactions/">Interactions</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/extending_mosaic/application_ambassador_details/">Application Ambassador</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/extending_mosaic/sumo_ambassador_details/">Sumo Ambassador</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/extending_mosaic/omnetpp_details/">OMNeT++ Federate</a> |
| </li> |
| |
| <li > |
| <a href="/mosaic/docs/extending_mosaic/delay_models/">Delay Models</a> |
| </li> |
| |
| </ul> |
| |
| |
| </div> |
| |
| |
| </nav> |
| |
| </div> |
| |
| |
| <div class="d-none d-xl-block col-xl-2 docs-toc"> |
| <ul class="nav toc-top"> |
| <li><a href="#" id="back_to_top" class="docs-toc-title">Contents</a></li> |
| </ul> |
| |
| <nav id="TableOfContents"> |
| <ul> |
| <li><a href="#developing-applications">Developing Applications</a></li> |
| <li><a href="#create-a-hello-world-application-based-on-maven">Create a ’Hello world’ application based on Maven</a></li> |
| <li><a href="#application-interfaces">Application Interfaces</a></li> |
| <li><a href="#basic-functions-and-concepts-for-applications">Basic Functions and Concepts for Applications</a> |
| <ul> |
| <li><a href="#event-hooks">Event hooks</a></li> |
| <li><a href="#trigger-own-events">Trigger own Events</a></li> |
| <li><a href="#using-the-operating-system">Using the Operating System</a></li> |
| <li><a href="#navigation">Navigation</a></li> |
| <li><a href="#access-sumo-traci-from-applications">Access SUMO TraCI from applications</a></li> |
| </ul> |
| </li> |
| <li><a href="#debugging-of-applications">Debugging of applications</a></li> |
| </ul> |
| </nav> |
| |
| |
| </div> |
| |
| |
| <main class="col-12 col-md-9 col-xl-7 py-md-3 pl-md-4 docs-content" role="main"> |
| |
| <article class="article"> |
| |
| <div class="docs-article-container"> |
| <h1>Basics in Application Development</h1> |
| |
| <div class="article-style"> |
| <p>Applications in Eclipse MOSAIC are simulated by the |
| <a href="/docs/simulators/application_simulator/">Eclipse MOSAIC Application Simulator</a>. Such |
| an application is programmed in Java and follows an event-based execution flow. Thereby, certain methods of the application are called by |
| the Application Simulator upon corresponding events (the application “reacts”). To actively gain execution at some later point in time, an |
| application can also schedule a generic event itself. When the application is executing, it has access to a set of methods, allowing to |
| trigger actions like sensing messages or controlling the vehicle, influencing the current simulation (the application “acts”).</p> |
| <h2 id="developing-applications">Developing Applications</h2> |
| <p>Developing custom applications in Eclipse MOSAIC is rather easy. The best way to learn it is by looking at the |
| source code of actual applications. For this purpose, we provide the source code of all tutorial applications |
| and further examples. You can find the source code on the |
| <a href="https://www.dcaiti.tu-berlin.de/research/simulation/download/" target="_blank" rel="noopener">DCAITI website</a>.</p> |
| <p>For an easy understanding of the application API, the following questions and their answers should |
| help:</p> |
| <ul> |
| <li> |
| <p>What is required to get my own application to run in Eclipse MOSAIC? |
| In Eclipse MOSAIC it is very easy to build your own application. First, it needs to inherit from the <code>AbstractApplication</code> |
| class (see following section). Secondly, the application must be mapped to |
| a vehicle (or RSU, or traffic light, …) via the mapping configuration (see section |
| <a href="/docs/building_scenarios/scenarios/#applications-and-mapping">mapping</a>). Finally, |
| the application must be compiled as a Jar-File and placed into the application directory of your |
| scenario.</p> |
| </li> |
| <li> |
| <p>How can I access vehicle functions from within the application, such as sending V2X messages? |
| Every applications has access to the <code>OperatingSystem</code> of the underlying unit which allows to |
| change its state or to initiate actions, such as sending messages to other vehicles.</p> |
| </li> |
| <li> |
| <p>How can I react to events during the simulation, such as receiving V2X messages? |
| For each application you decide, which events the application should listen to. For example, |
| if your application needs to react upon incoming V2X messages, it simply implements the <code>CommunicationApplication</code> |
| interface. In the following section you can find all available interfaces |
| applications can implement.</p> |
| </li> |
| </ul> |
| <h2 id="create-a-hello-world-application-based-on-maven">Create a ’Hello world’ application based on Maven</h2> |
| <p>For this example you need to install |
| <a href="https://maven.apache.org/download.cgi" target="_blank" rel="noopener">Maven</a> which is used |
| to resolve required MOSAIC dependencies and to compile your application Java code into a Jar file. |
| Follow the steps to build an example application:</p> |
| <ol> |
| <li>Create a new folder <code>HelloWorldApp</code>: |
| <pre><code class="language-FOLDER">└─ HelloWorldApp |
| ├─ src |
| | └─ main |
| | └─ java |
| | └─ HelloWorldApp.java |
| └─ pom.xml |
| </code></pre> |
| </li> |
| <li>Place a <code>pom.xml</code> with the following content: |
| <pre><code class="language-xml"><?xml version="1.0" encoding="UTF-8"?> |
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
| <modelVersion>4.0.0</modelVersion> |
| |
| <groupId>org.eclipse.mosaic.app</groupId> |
| <artifactId>HelloWorldApp</artifactId> |
| <version>0.0.1</version> |
| <packaging>jar</packaging> |
| |
| <dependencies> |
| <dependency> |
| <groupId>org.eclipse.mosaic</groupId> |
| <artifactId>mosaic-application</artifactId> |
| <version>20.0-SNAPSHOT</version> |
| </dependency> |
| </dependencies> |
| |
| </project> |
| </code></pre> |
| </li> |
| <li>Create a new application in <code>src/main/java/HelloWorldApp.java</code>: |
| <pre><code class="language-java">import org.eclipse.mosaic.fed.application.app.AbstractApplication; |
| import org.eclipse.mosaic.fed.application.app.api.VehicleApplication; |
| import org.eclipse.mosaic.fed.application.app.api.os.VehicleOperatingSystem; |
| import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; |
| import org.eclipse.mosaic.lib.util.scheduling.Event; |
| |
| public class HelloWorldApp extends AbstractApplication<VehicleOperatingSystem> implements VehicleApplication { |
| |
| @Override |
| public void onStartup() { |
| getLog().info("Hello World!"); |
| } |
| |
| @Override |
| public void onVehicleUpdated(VehicleData previousVehicleData, VehicleData updatedVehicleData) { |
| getLog().info("Driving {} m/s.", updatedVehicleData.getSpeed()); |
| } |
| |
| @Override |
| public void onShutdown() { |
| getLog().info("Good bye!"); |
| } |
| |
| @Override |
| public void processEvent(Event event) { |
| // ... |
| } |
| } |
| </code></pre> |
| </li> |
| <li>Build the application using maven: |
| <pre><code class="language-shell">mvn clean install |
| </code></pre> |
| </li> |
| <li>Copy the JAR file from <code>target/HelloWorldApp-0.0.1.jar</code> to the <code>application</code> directory of your simulation scenario.</li> |
| <li>Use the fully qualified name <code>HelloWorldApp</code> in the <code>mapping_config.json</code> to load the application onto vehicles.</li> |
| </ol> |
| <h2 id="application-interfaces">Application Interfaces</h2> |
| <p>You may have noticed that the <code>HellowWorldApp</code> extends from the class <code>[...].AbstractApplication<OS></code>. |
| In order to define the type of unit your application can run on, you need to speficy the operating system by choosing one of the following:</p> |
| <ul> |
| <li><code>VehicleOperatingSystem</code> - for applications mapped to normal vehicles.</li> |
| <li><code>ElectricVehicleOperatingSystem</code> - for applications for vehicles with electro mobility features.</li> |
| <li><code>RoadSideUnitOperatingSystem</code> - for applications mapped to RSUs.</li> |
| <li><code>TrafficLightOperatingSystem</code> - for applications mapped to traffic lights.</li> |
| <li><code>TrafficManagementCenterOperatingSystem</code> - for applications mapped to TMCs.</li> |
| <li><code>ChargingStationOperatingSystem</code> - for applications mapped to charging stations.</li> |
| </ul> |
| <p><em>See package:</em> <code>org.eclipse.mosaic.fed.application.app.api.os.*</code></p> |
| <p>Furthermore, your application can implement the following 7 interfaces in order to get informed on specific events:</p> |
| <ul> |
| <li><code>VehicleApplication</code> - get informed when information about the vehicles state is updated.</li> |
| <li><code>ElectricVehicleApplication</code> - get informed on electric vehicle specific events.</li> |
| <li><code>CommunicationApplication</code> - react on incoming V2X messages.</li> |
| <li><code>MosaicApplication</code> - get informed on Eclipse MOSAIC internal events.</li> |
| <li><code>TrafficLightApplication</code> - get noticed when the traffic light program is changed.</li> |
| <li><code>ChargingStationApplication</code> - react on state changes of the charging station.</li> |
| <li><code>TrafficManagementCenterApplicatio</code>n - get informed on state changes of road infrastructure.</li> |
| </ul> |
| <p><em>See package:</em> <code>org.eclipse.mosaic.fed.application.app.api.*</code></p> |
| <hr> |
| <h2 id="basic-functions-and-concepts-for-applications">Basic Functions and Concepts for Applications</h2> |
| <p>The following section describes how applications are implemented.</p> |
| <h3 id="event-hooks">Event hooks</h3> |
| <p>Applications are implemented by reacting to specific events. Those events are, amongst others:</p> |
| <ul> |
| <li>The simulation has started: All static units (e.g. road side units) are set up (<code>onStartup()</code> is called)</li> |
| <li>Once a vehicle has been added to the simulation, all its configured applications are initialized (<code>onStartup()</code> is called)</li> |
| <li>The data of the vehicle has changed, e.g. after the traffic simulator has finished one simulationstep (<code>onVehicleUpdated()</code> is called).</li> |
| <li>A unit has received a V2X message from another entity (<code>onMessageReceived</code> is called).</li> |
| <li>A unit which has send a V2X message via a ITS-G5 topocast receives an acknowledgement (<code>onAcknowledgementReceived()</code> is called).</li> |
| </ul> |
| <p>Another example:</p> |
| <pre><code class="language-mermaid">sequenceDiagram |
| activate RTI |
| activate ApplicationSimulator |
| |
| RTI ->> ApplicationSimulator: VehicleRegistration |
| ApplicationSimulator ->> Application1: onStartup() |
| activate Application1 |
| ApplicationSimulator ->> Application2: onStartup() |
| activate Application2 |
| |
| RTI ->> ApplicationSimulator: VehicleUpdates |
| ApplicationSimulator ->> Application1: onVehicleUpdated() |
| ApplicationSimulator ->> Application2: onVehicleUpdated() |
| |
| RTI ->> ApplicationSimulator: VehicleUpdates |
| ApplicationSimulator ->> Application1: onVehicleUpdated() |
| ApplicationSimulator ->> Application2: onVehicleUpdated() |
| Application2 ->> ApplicationSimulator: sendV2xMessage() |
| ApplicationSimulator ->> RTI: V2xMessageTransmission |
| |
| RTI ->> ApplicationSimulator: V2xMessageReceiption |
| ApplicationSimulator ->> Application1: onMessageReceived() |
| |
| RTI ->> ApplicationSimulator: VehicleUpdates (remove) |
| ApplicationSimulator ->> Application1: onShutdown() |
| deactivate Application1 |
| ApplicationSimulator ->> Application2: onShutdown() |
| deactivate Application2 |
| </code></pre> |
| <p><em>Example sequence of onStartup, update, and tear down of two applications.</em></p> |
| <p>A <code>onStartup()</code> method, which enables the ITS-G5 communication module of the unit, could be implemented the following:</p> |
| <pre><code class="language-java">@Override |
| public void onStartup() { |
| getOs().getAdHocModule().enable(new AdHocModuleConfiguration() |
| .addRadio().channel(AdHocChannel.CCH).power(50).create() |
| ); |
| } |
| </code></pre> |
| <p>A <code>onMessageReceived()</code> method, which reacts upon a <strong>DENM</strong> message, could be implemented as:</p> |
| <pre><code class="language-java">@Override |
| public void onMessageReceived(ReceivedV2xMessage receivedV2xMessage) { |
| final V2xMessage msg = receivedV2xMessage.getMessage(); |
| |
| if (msg instanceof Denm) { |
| Denm denm = (Denm)msg; |
| GeoPoint eventLocation = denm.getEventLocation(); |
| //TODO you can add further implementation here |
| } |
| } |
| </code></pre> |
| <h3 id="trigger-own-events">Trigger own Events</h3> |
| <p>It is possible to trigger own events at specific times within the application. For this purpose, the application has access to an own event manager. Each event requires a |
| simulation timestamp when it should be called, and an event processor.</p> |
| <p>The following code triggers an event in 10 seconds after the application has been initialied:</p> |
| <pre><code class="language-java">@Override |
| public void onStartup() { |
| Event event = new Event(getOs().getSimulationTime() + 10 * TIME.SECOND, this); |
| getOs().getEventManager().addEvent(event); |
| } |
| |
| @Override |
| public void processEvent(Event event) { |
| getLog().info("Event has been triggered"); |
| // TODO |
| } |
| </code></pre> |
| <p>To address a specific method to process the event, Java lambda expressions could be used:</p> |
| <pre><code class="language-java">@Override |
| public void onStartup() { |
| Event event = new Event(getOs().getSimulationTime() + 10 * TIME.SECOND, this::mySpecificMethod); |
| getOs().getEventManager().addEvent(event); |
| } |
| |
| public void mySpecificMethod(Event event) { |
| getLog().info("Event has been triggered"); |
| // TODO |
| } |
| </code></pre> |
| <h3 id="using-the-operating-system">Using the Operating System</h3> |
| <p>Each application has access to the operating system of its unit. Depending on the type of unit, the operating system provides different methods. For example, |
| an application which is mapped on vehicles, has access to the <code>VehicleOperatingSystem</code> by calling <code>this.getOperatingSystem()</code> (or <code>this.getOs()</code> to keep it short). The following examples show a bit |
| of the capabilities the <code>VehicleOperatingSystem</code> provides:</p> |
| <p>Get the current simulation time (in nanoseconds):</p> |
| <pre><code class="language-java">long time = this.getOs().getSimulationTime(); |
| </code></pre> |
| <p>Return the name of the unit (e.g. “veh_0”):</p> |
| <pre><code class="language-java">String nameOfUnit = this.getOs().getId(); |
| </code></pre> |
| <p>Get access to vehicle data, such as speed, position, heading, and the like:</p> |
| <pre><code class="language-java">double speed = this.getOs().getVehicleData().getSpeed(); |
| GeoPoint position = this.getOs().getVehicleData().getPosition(); |
| </code></pre> |
| <p>Change parameters of the vehicle during the simulation, such as its maximum speed:</p> |
| <pre><code class="language-java">this.getOs().requestVehicleParametersUpdate() |
| .changeMaxSpeed(10) // m/s |
| .changeMaxAcceleration(2.4) |
| .apply(); |
| </code></pre> |
| <p>Get the current lane index of the vehicle and change lane to left (within 5000 ms):</p> |
| <pre><code class="language-java">int laneIndex = this.getOs().getRoadPosition().getLaneIndex(); |
| int newLaneIndex = Math.max(0, laneIndex - 1); |
| this.getOs().changeLane(newLaneIndex, 5000); |
| </code></pre> |
| <p>Sending a V2X message via ITS-G5 singlehop broadcast:</p> |
| <pre><code class="language-java">MessageRouting routing = this.getOs().getAdHocModule().createMessageRouting().topoBroadCast(); |
| V2xMessage message = new MyV2xMessage(routing); |
| this.getOs().getAdHocModule().sendV2xMessage(message); |
| </code></pre> |
| <p>Park the vehicle in 200 meters at the right side of the road for 3 minutes:</p> |
| <pre><code class="language-java">double distance = 200; |
| double duration = 3 * 60 * 1000; |
| IRoadPosition stopPosition = RoadPositionFactory.createAlongRoute( |
| getOs().getNavigationModule().getRoadPosition(), |
| getOs().getNavigationModule().getCurrentRoute(), |
| 0, |
| distance |
| ); |
| this.getOs().stop(distance, duration, Stop.StopMode.PARK); |
| </code></pre> |
| <h3 id="navigation">Navigation</h3> |
| <p>The navigation of vehicles (i.e. calculation of routes) is handled completely by the |
| <a href="/docs/simulators/application_simulator/#eclipse-mosaic-application-simulator">Eclipse MOSAIC Application Simulator</a>. Each vehicle is equipped |
| with a navigation system which provides all required information and functions for navigational purposes:</p> |
| <ul> |
| <li>Retrieve the current position and heading of the vehicle.</li> |
| <li>Get the target of the vehicle.</li> |
| <li>Calculate various routes from the current position to an arbitrary target.</li> |
| <li>Choose a suitable route out of existing ones from the current position to an arbitrary target.</li> |
| <li>Switch onto a specific route.</li> |
| </ul> |
| <p>In order to provide routing functionality, a map model based on Open Street Map data is used, which |
| needs to be transformed before the simulation using scenario-convert. The map data including initial |
| routes for vehicles is provided with the database file which needs to be located in |
| <code>mosaic/scenarios/<scenario_name>/application/<scenario_name>.db</code></p> |
| <h4 id="configuration">Configuration</h4> |
| <p>If the database needs to be located somewhere else, the path can be specified in |
| <code>mosaic/scenarios/<scenario_name>/application/application_config.json</code>:</p> |
| <pre><code class="language-json">{ |
| ... |
| "navigationConfiguration": { |
| "databaseFile": "path/to/scenario.db" |
| } |
| } |
| </code></pre> |
| <p>The following snippet show, how the navigation system can be used within an application:</p> |
| <pre><code class="language-java">//get navigation module |
| INavigationModule navigationModule = getOs().getNavigationModule(); |
| |
| //choose current target as target position |
| RoutingPosition targetPosition = new RoutingPosition(navigationModule.getTargetPosition()); |
| |
| //set routing parameters to fastest route search |
| RoutingParameters params = new RoutingParameters().costFunction(IRoutingCostFunction.Fastest); |
| |
| //calculate routes |
| RoutingResponse response = navigationModule.calculateRoutes(targetPosition, params); |
| |
| //switch to best route |
| if (response.getBestRoute() != null) { |
| boolean routeSwitched = navigationModule.switchRoute(response.getBestRoute()); |
| ... |
| } |
| </code></pre> |
| <h3 id="access-sumo-traci-from-applications">Access SUMO TraCI from applications</h3> |
| <p>If SUMO is used as a traffic simulator and a special functionality is required, the <code>sendSumoTraciRequest</code> |
| function in the <code>OperatingSystem</code> can be used.</p> |
| <p>The function expects a string (a unique identifier which will be assigned to the response) and a byte array |
| (representing the complete Traffic Control Interface (TraCI) request including the header). The message |
| identifier can be an empty string.</p> |
| <p>In all cases the command will trigger a response. The application can receive the response from the |
| method <code>onSumoTraciResult</code>. This method will receive a <code>SumoTraciResult</code> |
| object. This response contains the specified identifier. The application must handle the |
| identification process of the response itself.</p> |
| <div class="alert alert-note"> |
| <div> |
| Be careful when using this interface and the TraCI commands. The |
| commands are delivered to TraCI without any prior checks. |
| </div> |
| </div> |
| <div class="alert alert-note"> |
| <div> |
| You can find the example application SumoTraciInteractionApp |
| in the additional examples bundle on the <a href="https://www.dcaiti.tu-berlin.de/research/simulation/download/" target="_blank">DCAITI website</a>. |
| </div> |
| </div> |
| <hr> |
| <h2 id="debugging-of-applications">Debugging of applications</h2> |
| <p>To debug an application, remote debugging needs to be used. The following steps need to be performed |
| in order to debug the application:</p> |
| <ol> |
| <li>Open the application in your IDE.</li> |
| <li>Modify your <code>mosaic.sh</code> or <code>mosaic.bat</code> by adding debug parameters to the java call:<br> |
| <code>java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=4100 ...</code></li> |
| <li>Add a new debug profile in your IDE for remote debugging. Make sure to correctly configure port <code>4100</code> (or whichever port you provided in step 2).</li> |
| <li>Launch Eclipse MOSAIC with the argument <code>-w 0</code> to disable the watchdog timer otherwise it will interfere with debugging.</li> |
| <li>Connect your debugger in your IDE with the running simulation.</li> |
| </ol> |
| |
| </div> |
| |
| |
| |
| |
| |
| |
| <div class="article-widget"> |
| |
| <div class="post-nav"> |
| |
| |
| </div> |
| |
| </div> |
| |
| </div> |
| |
| |
| |
| |
| |
| |
| </article> |
| </main> |
| </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 src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/4.1.1/anchor.min.js" integrity="sha512-aZotBPy6dqn8yVaLJwSrkJ+QxuxV695A4dgodAMvTU5JyNi5mhrr+LeaD3GSS+lx1SMFKNs0tu5ZMJEgNZQP2Q==" crossorigin="anonymous"></script> |
| <script> |
| anchors.add(); |
| </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 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">×</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> |