I am struggling to modify the "Highway lane change" example.
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to implement the "Highway lane change" example with my own controller. Initially I designed my controller such that if I can provide the controller a reference path ( in the form of a N*2 matrix) the controller will be able to follow that path. Now I want to extend my project such that the reference path will be generated autonomously with the help of sensor fusion. I can see the similar thing has been done in the "Highway lane change" project. But for my controller I need to extract the reference X and Y values. But I am struggling to find those 2 values. I have tries with a matlab function block with the following code -
function [X_ref, Y_ref] = extractWaypoints(TrajectoryInfo)
% Extract X and Y waypoints from the planned trajectory
optimalTrajIndex = TrajectoryInfo.OptimalTrajectoryIndex;
trajectory = TrajectoryInfo.GlobalTrajectory(optimalTrajIndex).Trajectory;
% Extract X and Y positions
X_ref = trajectory(:, 1);
Y_ref = trajectory(:, 2);
end
But with this I am getting the error, "Error:'Input Port 1' of 'MotionPlanner/Ref_waypoints' expects a bus but receives a nonbus signal from 'Output Port 1' of 'MotionPlanner/MATLAB Function2'."
I am not sure how to work on this example.
0 Kommentare
Antworten (1)
Satwik
am 20 Jan. 2025
Hi Atulan,
I understand that the error message indicates that the MATLAB Function block is expected to output a bus signal, but it is currently outputting a non-bus signal. The following steps should be helpful in resolving the issue:
1. Understand the Input and Output Requirements: Verify the structure of ‘TrajectoryInfo’ to ensure you are accessing the correct fields. It should be a bus object if your model expects a bus signal.
2. Define a Bus Object: If ‘TrajectoryInfo’ is a bus, define a corresponding bus object in MATLAB that matches the structure of the signal. Here is an example of how to define bus object for the output:
% Define Bus Elements
elems(1) = Simulink.BusElement;
elems(1).Name = 'X_ref';
elems(1).Dimensions = [N, 1]; % Set N to the appropriate size
elems(2) = Simulink.BusElement;
elems(2).Name = 'Y_ref';
elems(2).Dimensions = [N, 1]; % Set N to the appropriate size
% Create Bus Object
refWaypointsBus = Simulink.Bus;
refWaypointsBus.Elements = elems;
% Assign the Bus Object to the MATLAB Function Block
set_param('YourModelName/MotionPlanner/Ref_waypoints', 'OutDataTypeStr', 'Bus: refWaypointsBus');
Please refer to the following documentation for more information on ‘Simulink.Bus’:
3. Adjust the MATLAB Function:
Make sure the MATLAB function outputs a structure that conforms to the defined bus:
function refWaypoints = extractWaypoints(TrajectoryInfo)
% Extract X and Y waypoints from the planned trajectory
optimalTrajIndex = TrajectoryInfo.OptimalTrajectoryIndex;
trajectory = TrajectoryInfo.GlobalTrajectory(optimalTrajIndex).Trajectory;
% Create a structure to match the bus
refWaypoints.X_ref = trajectory(:, 1);
refWaypoints.Y_ref = trajectory(:, 2);
end
I hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Customize System Objects for Simulink finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!