Writing a lap time sim tool
10 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to write a lap time sim tool for race tracks. I have it in excel, so, most of the maths is done, except for the parts where excel cant work stuff out (as far as I know) like braking and acceleration zones but that can be worked on at a later date.
The main problem is that I need to allow the user to input section lengths: corners and straights, and preferably in order.
Part of the problem I have asked about before here: https://uk.mathworks.com/matlabcentral/answers/424503-how-to-make-a-scale-able-structure-array-with-variable-values
But, as people who have very kindly helped so far have pointed out, I need to explain the whole problem :)
So, as my Matlab and programming knowledge is limited, I'd like to know what approaches I can do for this, what functions would I need, and how would I need to use them. While it would be great for code to be provided, I dont want to ask other people to do the work for me, and I wont learn anything, but, I do learn best from examples so any similar examples I can expand on would be great.
There could be upto 100 or so sections of the track, for the straights it's a straight forward length and calculation. For corners, I need to determine the radius of that corner, so, need to be able to identify which section is which.
After that, I should have a resulting value (the top speed) for each section which I need to use in further calculations.
Any help would be appreciated.
4 件のコメント
Guillaume
2018 年 10 月 22 日
Well, what inputs does your simulation need? You said the track details, that's one. What else?
回答 (1 件)
Guillaume
2018 年 10 月 22 日
Probably, the first thing you need to settle on is what form your inputs will take. If I understand your requirements, I would have three inputs to the simulation function:
- track details. I would have that as a structure array with fields:
type: a scalar categorical with possible values: 'straight' or 'corner'
length: a scalar double
radius: a scalar double
inclination:? if that's needed, a scalar double
type may not even be needed since a corner with infinite radius is a straight.
- car details, a scalar structure (unless you simulate more than one car, in which case it's another structure array), with fields
friction
drag
frontalarea
mass
all scalar doubles
- environment, another scalar structure with fields
gravity
air density
humidity (?)
air temperature (?)
and the signature of your function would be:
function [someresult, maybesomeotherresult] = tracksimulation(track, car, environment)
%TRACKSIMULATION: Simulate the car racing along the specified track under given environment conditions
%with:
% track: and Nx1 structure with fields
% type: scalar categorical with possible values 'straight' or 'corner'
% ... you can write the rest
% first thing you should do when you start writing a function is document its inputs/outputs
You can even have a helper function to help you build that track structure:
function track = addsection(track, type, length, radius)
%ADDSECTION: add a section to the given track (or start the track)
%with:
% track: a previously constructed track structure or an empty array to start the track
% type: the type of section to add, char array with value: 'straight' (or 's') or 'corner' (or 'c')
% length: length of section to add, scalar double
% radius: radius of section to add, ignored and can be omitted if type is 'straight'.
if isempty(track)
track = structure('type', {}, 'length', {}, 'radius', {});
else
assert(isstruct(track) && all(ismember({'type', 'length', 'radius'}, fieldnames(track))), 'track input must be a structure with correct fields');
end
validateattributes(type, {'char', 'string'}, {'scalartext'}, 2)
if strcmp(type, 's'), type = 'straight'; elseif strcmp(type, 'c'), type = 'corner'; end
validateattributes(length, {'numeric'}, {'scalar', 'positive', 'finite'}, 3);
if nargin < 3
if strcmp(type, 'corner'), error('radius must be specified when type is ''corner''); end
radius = Inf;
else
validateattributes(radius, {'numeric'}, {'scalar', 'positive', 'finite'}, 4);
end
track = [track; struct('type', categorical({type}, {'straight', 'corner'}), 'length', length, 'radius', radius)];
end
11 件のコメント
Guillaume
2018 年 11 月 6 日
Again, I'm really not clear on which data model you're using So, please clarify. What are the fields of your structures (TRACK and sections)? What are the possible values of each field?
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!