How to work with Matlab object's within Simulink?
조회 수: 2 (최근 30일)
이전 댓글 표시
How to work with the object in the base workspace in MATLAB Function in Simulink?
I want the object 'NewDriver' to perform some actions based on: Objects in the Workspace and input from Simulink simulation.
function steer_angle = Driver(newposition)
global NewPath;
global NewVehicle;
global NewDriver;
NewVehicle.Set_Position(newposition); %Updates the Vehicle Position in Space
steer_input = NewDriver.Run(NewVehicle, NewPath); %Calculates the Steering Input to keep the Vehicle on the Path
NewVehicle.Set_Steering_Position(steer_input); %Updates actulal Steering Position
steer_angle = steer_input; %Sends the Steering Angle to the simulation
I found the information to make this implementation with 'global' variables work their type has to be set in Model Explorer to Data Store Memory, but it generates an error:
Variable 'NewDriver' is resolved in workspace ('base') for block 'three_F1toPass_Driver/MATLAB Function2' but it is not a 'Simulink.Signal' object
Adding Simulink Signal with the same name (NewDriver) to Model Workspace doesn't work either.
I doubt if this is the best option to implement this functionality, I am totally open to any other ideas.
Is there a better option to perform this action in Simulink? By using different Simulink Blocks? All the functionalities I need were written in classes as methods to keep the code clean and understandable. However, now I am struggling with merging this functionality with Simulink Simulation.
댓글 수: 0
답변 (1개)
jessupj
2022년 1월 13일
편집: jessupj
2022년 1월 13일
see documtation for assignin to pass info from matlab to simulink perhaps?
i don't know if this is helpful or something you've looked into or fits your intended workflow.
modelworkspace = get_param(systemname,'ModelWorkspace'); %system name is the simulink system
assignin(modelworkspace,'simulink_variable_name',simulink_variable_value);
to assign matlab workspace variable simulink_variable_value to the 2nd argument
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Naming Conventions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!