How to change the drive cycle in Simulink through script?
9 views (last 30 days)
Show older comments
Hello!
I'm currently using Virtual Vehicle Composer APP to build a simulink model to evaluate the energy comsumption of a electric car. However, I need to use my own drive cycle to run the estimation which is not standard as predefined in the MATLAB Drive Cycle Data APP. And I also need to use the log data to do further optimization so I have to write some scripts to perform the estimation and get the data at the same time.
The script generated by Virtual Vehicle Composer has been shown below, I want to know if I can use any functions or statements to change this original drive cycle to my own drive cycle which is from workspace or from .mat file.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1491952/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1491952/image.png)
0 Comments
Accepted Answer
Nishan Nekoo
on 26 Sep 2023
Hi,
Looking into the setParamforManeuverAndDriver.m function provides some clues on how this can be done. On line 24 of that file in \VirtualVehicle\Scripts, there is the following line that sets the Drive Cycle to 'Wide Open Throttle':
in=in.setBlockParameter(ManeuverMaskPath,'cycleVar',ManeuverOption);
ManeuverMaskPath is the path to the DriveCycleSource block in your model, mine for example was:
ManeuverMaskPath = 'ConfiguredVirtualVehicleModel/Scenarios/Reference Generator/Reference Generator/Reference Generator/Drive Cycle'
You can override the drive cycle in the 'TestScript' with a .mat file by doing something like the following:
in(1)=in(1).setBlockParameter(ManeuverMaskPath,'cycleVar','.mat, .xls, .xlsx or .txt file');
in(1)=in(1).setBlockParameter(ManeuverMaskPath,'fileVar','driveCycle.mat')
or with a variable by doing something like the following:
in(1)=in(1).setBlockParameter(ManeuverMaskPath,'cycleVar','Workspace variable');
in(1)=in(1).setBlockParameter(ManeuverMaskPath,'wsVar','driveCycle')
I identified variable names like 'fileVar' and 'wsVar' by right clicking on the DriveCycleSource block and selecting Mask > View Mask.
I did not try this myself so there might be other things you need to set to get this working, but this should help you get started.
More Answers (0)
See Also
Categories
Find more on Virtual Vehicles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!