Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Working around looping problem

조회 수: 6 (최근 30일)
Mark Kelly
Mark Kelly 2014년 1월 20일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi,
So I am modelling the acceleration and coasting speed of an electric car over time. I have managed to model the max acceleration of the car. What I am trying to do is, once it reaches this max speed (8 m/s) the motor should switch off until it reaches 4 m/s where it will accelerate again before this process repeats. Here's what I currently have:
for n=1:500
%Motor Current I(n)=(Ebat-(((vel(n)*G)/WheelRadius)*Ke))/R;
%Motor Torque
T(n)=Kt*I(n);
%Motor RPM
RPM(n)=(vel(n)*G)/(WheelRadius)*60/(2*3.14);
%Car velocity during acceleration, taking into account rolling resistance
%and aerodynamic drag. Once these are equal to the max motor speed, car
%will travel at fixed velocity
vel(n+1)=(vel(n)+dT*((G/WheelRadius)*T(n)-CoeffRoll*mass*g-DensityAir*FrontalArea*CoeffDrag*(vel(n))^2)/(mass));
PowerIn(n)=(NoLoadCurrent+I(n))*Ebat;
PowerOut(n)=T(n)*(G*vel(n)/WheelRadius);
Efficiency(n)=PowerOut(n)/PowerIn(n);
d(n+1)=d(n) + (50/501)*vel(n); % Compute distance travelled.
end;
Now, if I put an if statement in here telling the motor to switch off once it reaches max speed, it will just decelerate for one iteration before accelerating back to maximum speed again over and over.
Does any one have any idea where to go with this?
Thanks!!

답변 (1개)

Doug Hull
Doug Hull 2014년 1월 20일
Use Simulink for time based simulation. This is simple enough though that you can do this in MATLAB.
Put a flag that gets toggled at the top speed but does not toggle back until the bottom speed.
Doug
  댓글 수: 3
AJ von Alt
AJ von Alt 2014년 1월 20일
I think Doug had something like this in mind:
flagMotorOn = true;
minVelocity = 11;
maxVelocity = 22;
...
if( vel(n) >= maxVelocity )
flagMotorOn = false;
elseif( vel(n) <= minVelocity )
flagMotorOn = true;
end
if( flagMotorOn )
% update calculations with motor turned on
else
% update calculations with motor turn off
end
Mark Kelly
Mark Kelly 2014년 1월 20일
That makes sense. I understand now! Thanks very much to you both.

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by