You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SimuLTE与Veins中启用SUMO TraCI并获取实时交通数据?

Hey there! Let me break down exactly how to make this work for your SimuLTE + Veins setup—since you’re already familiar with pure Veins, this will feel familiar with just a few extra steps for LTE integration.

Core Overview

In the combined SimuLTE + Veins simulation, Veins handles traffic mobility and TraCI interactions, while SimuLTE manages LTE communication. The key is to fetch real-time traffic data via TraCI in your Veins node's application layer, then pass that data to SimuLTE's LTE stack to send as safety messages.

Step-by-Step Implementation

1. Pick the Right Code Location

Just like in pure Veins, you’ll work within the application layer module of your Veins node (usually attached to a node with the TraCIMobility module, like VeinsVehicle). This is where you’ll add TraCI logic and handle data handoff to SimuLTE.

2. Use TraCICommandInterface to Grab Real-Time Data

First, get a reference to the TraCIMobility module and its associated TraCI interface in your application's .cc file:

// Fetch the TraCIMobility module from the parent node
TraCIMobility* mobility = dynamic_cast<TraCIMobility*>(getModuleByPath("^.mobility"));
if (!mobility) {
    error("Failed to locate TraCIMobility module");
}
// Access the TraCI command interface
TraCICommandInterface* traci = mobility->getCommandInterface();

Example 1: Get Average Speed for the Current Road

If you need the average speed of vehicles on the road your car is currently on:

// Get the ID of the road your vehicle is traveling on
std::string currentRoad = traci->vehicle(getParentModule()->getFullName())->getRoadId();
// Fetch the average speed (in m/s) for that road
double roadAvgSpeed = traci->road(currentRoad)->getAverageSpeed();

Example 2: Calculate Overall Fleet Average Speed

If you need the average speed of all connected vehicles in the simulation:

double totalSpeed = 0.0;
int vehicleCount = 0;
// Iterate over all vehicles in the simulation
for (const auto& vehId : traci->getVehicleIds()) {
    TraCICommandInterface::Vehicle* vehicle = traci->vehicle(vehId);
    totalSpeed += vehicle->getSpeed();
    vehicleCount++;
}
double fleetAvgSpeed = vehicleCount > 0 ? totalSpeed / vehicleCount : 0.0;

3. Pass Data to SimuLTE for LTE Transmission

Once you have your traffic data, package it into a custom message (e.g., SafetyMessage) and send it through SimuLTE's LTE stack. Make sure your node's NED file connects the application layer to the LTE NIC's upper layer interface:

// Create your custom safety message
SafetyMessage* safetyMsg = new SafetyMessage();
safetyMsg->setAvgSpeed(roadAvgSpeed); // Populate with your data
safetyMsg->setSenderId(getParentModule()->getId());

// Fetch the SimuLTE LTE NIC module
LteNic* lteNic = dynamic_cast<LteNic*>(getParentModule()->getSubmodule("nic"));
if (lteNic) {
    // Send the message to the LTE stack for transmission
    send(safetyMsg, "upperLayerOut");
}

Note: Double-check your NED file to ensure the application's upperLayerOut gate links to the LTE NIC's upperLayerIn gate.

4. Test & Debug

  • Start by validating TraCI data fetching in a pure Veins setup first—use OMNeT++'s EV logging to confirm data is correct:
    EV_INFO << "Current road average speed: " << roadAvgSpeed << " m/s\n";
    
  • Then test the full SimuLTE + Veins setup to ensure messages are transmitted and received over LTE.
  • For real-time updates, set up a timer (e.g., every 100ms) to periodically fetch data and send messages—avoid blocking the simulation loop with continuous TraCI calls.
Key Notes
  • Make sure your Veins and SimuLTE versions are compatible, and your launch script (like run.sh) correctly configures paths for both frameworks.
  • Always call TraCI methods within the simulation event loop (e.g., in handleMessage or a scheduled timer event) to avoid disrupting simulation timing.

内容的提问来源于stack exchange,提问作者J.G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:54:13