
I am facing issues integrating Radar1 Object Detections from the Driving Scenario Designer into an ACC in Simulink, with errors related to bus signal handling and data extract
4 views (last 30 days)
Show older comments
I am working on a Simulink model exported from the Driving Scenario Designer, where I have created a 2D road with an ego vehicle moving along a specific path and added a radar sensor to detect a lead vehicle. My goal is to extract the relative distance from the `Radar1 Object Detections` output to use in an Adaptive Cruise Control (ACC) system, maintaining a 5-meter distance. However, I am encountering the following issues:
1. Error with `To Workspace` Block:
- Error: `'Input Port 1' of 'testing_vehicle_simulink/To Workspace' expects a nonbus signal but receives a bus from 'Output Port 1' of 'testing_vehicle_simulink/Radar'. To convert a virtual bus to a vector, use a Bus to Vector block. To select an element of the bus, use a Bus Selector block.'`
- I tried configuring the `To Workspace` block with `Structure With Time` and later `Timeseries` save format, but I still get issues accessing `radarDetections.Data`.
2. Error with `Bus Selector` and `Selector` Blocks:
Error: `Selected signal 'Detections.Measurement' in the Bus Selector block 'testing_vehicle_simulink/Bus Selector' is invalid since it refers to a bus element within an array of sub-buses. The path to the array of sub-buses is 'Detections'. Please select the appropriate array element using a Selector block before using the Bus Selector block to access an element within the bus.`
I added a `Selector` block with parameters (Number of input dimensions: 1, Index mode: One-based, Index: [1 3], Input port size: 3), but this seems incorrect for the bus structure.
3. Unable to Access Logged Data:
- After running the simulation, `whos radarDetections` shows the variable, but `radarDetections.Data` or `radarDetections.Data{1}` results in `Unable to resolve the name 'radarDetections.Data'`.
Steps Tried:
Connected a `Scope` directly to `Radar1 Object Detections`, but got an error about non-virtual buses.
Added a `Bus Selector` to extract `Detections.Measurement`, followed by a `Selector` block, but the configuration is wrong.
Updated the `To Workspace` block to `Timeseries` format and used a MATLAB Function block to extract `relativeDistance` with code:
```matlab
function relativeDistance = getRelativeDistance(detections)
if ~isempty(detections) && ~isempty(detections{1})
if isfield(detections{1}, 'Detections') && ~isempty(detections{1}.Detections)
firstDetection = detections{1}.Detections(1);
if isfield(firstDetection, 'Measurement')
relativeDistance = firstDetection.Measurement(1);
else
relativeDistance = 5;
end
else
relativeDistance = 5;
end
else
relativeDistance = 5;
end
end
```
Model Details:
- The model includes a `Scenario Reader` and a `Driving Radar DataGenerator` with `Sensor Index: 1`.
- The ACC uses a "Sum" block to compute `Distance error = 5 - relativeDistance`, where 5 is the desired distance.
Question:

- How can I correctly configure the `Selector` and `Bus Selector` blocks to extract the longitudinal distance (`Measurement(1)`) from `Radar1 Object Detections`?
- Why can’t I access `radarDetections.Data`, and how should I log the bus data properly?
- What adjustments are needed in my MATLAB Function block or model to integrate the radar output with the ACC successfully?
0 Comments
Answers (1)
Simon
on 6 Aug 2025
Hi, as I understand your question, you’re encountering multiple errors one after the other while trying to run the model. There are two approaches that I have tried where the model runs error free but the data depends on the test_ego_vehicle.mat file which was not available in your question but I simulated it with one ego vehicle with radar sensors and a normal vehicle in some distance on a 2D road. There are two approaches – bus selector/selector manual configurations and MATLAB function
The steps for bus selector / selector are as follows:
1. In your testing_vehicle_simulink.slx file, add a Bus Selector after Radar Block, connect the output (detections) of the radar generator block to the input of this bus selector block. In this bus selector, don’t forget removing signal1, signal2 and adding detection as an output signal
2. Add a Selector Block to pick first detection, drag a selector block (Simulink > Signal Routing > Selector). Connect the detections output from the Bus Selector to the Selector. Double-click the Selector block: Set Index Option to Index vector (dialog). Set Index to 1 (to select the first detection) and you can set the port size to 50 or 5 or any number according to the number of signals. (Errors will occur if you don’t modify these in selector block)
3. Add Another Bus Selector to Extract Measurement
Repeat the exact steps as you had done for detection, just replace ‘detection’ signals with ‘measurement’ this time.
Bus Selector (select Measurement) → Selector (index 1) in your case for ‘Measurement(1)’
4. Log the output by connecting the output measurement signal to the ‘To Workspace block’. The save format should be ‘Structure’ or ‘Structure With Time’.
This will run error free, you can check the out/simout in workspace for the data accordingly. You have [1 3] as the index, which means you are selecting two buses (the 1st and 3rd), so the output is still an array of buses, and the Bus Selector will still fail.
You must select only one element (e.g., [1]) and add 3 in input port size
The steps for MATLAB function are as follows,:
1. In the MATLAB function block connected to the output of RADAR generator
function relativeDistance = getRelativeDistance(detections)
%#codegen
% detections is a bus containing an array of structs
if ~isempty(detections) && ~isempty(detections.Detections)
firstDetection = detections.Detections(1);
if ~isempty(firstDetection.Measurement)
relativeDistance = firstDetection.Measurement(1);
else
relativeDistance = 5;
end
else
relativeDistance = 5;
end
end
Also, make sure the ACC logic receives the correct measured distance as input.
As I had simulated this using my example file, the specific information you are looking for might be little different in the data in workspace. Please find the attached link for any kind of additional information.

https://www.mathworks.com/help/mpc/ug/adaptive-cruise-control-using-model-predictive-controller.html
Hope it helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!