Contents
Demonstrate different RWA models.
All demos use RWASmart.
------------------------------------------------------------------------
See also Plot2D, TimeGUI, RK4, RWASmart, RWACountToRate
------------------------------------------------------------------------
Global for the TimeGUI
global simulationAction
simulationAction = ' ';
clear x1Plot x2Plot x3Plot tPlot
Simulation parameters
dT = 0.0125;
nSim = 100;
Torque demand in counts
tDemand = 200;
Input the friction model
d = RWASmart('get default datastructure');
d.friction(1).fStatic = 0.0;
d.friction(1).fCoulomb = 0.0/2;
d.friction(1).vStribeck = 0.1;
d.friction(1).sigma0 = 0;
d.friction(1).sigma1 = 0;
d.friction(1).sigma2 = 0;
d.friction(1).maxC = 0.1/dT;
d.nWheels = 1;
Reinitialize
RWASmart( 'initialize', d );
Initialize the time display
[ ratioRealTime, tToGoMem ] = TimeGUI( nSim, 0, [], 0, dT, 'RWA Smart Simulation' );
Initial conditions
x = [0;0;0];
x1Plot = zeros(2,nSim);
t1Plot = zeros(1,nSim);
t = 0;
Commanded voltage
RWASmart( 'put data word', tDemand );
for k = 1:nSim
RWASmart( 'set tachometer states', struct( 'omega', x(1), 'angle', x(3) ) );
tachWord = RWASmart( 'get tachometer word' );
[ ratioRealTime, tToGoMem ] = TimeGUI( nSim, k, tToGoMem, ratioRealTime, dT );
x = RK4( 'RWASmart', x, dT, 0 );
tPlot(k) = t;
x1Plot(:,k) = [x(1,:);RWACountToRate( tachWord, d )];
t1Plot(1,k) = RWASmart('get torque');
t = t + dT;
switch simulationAction
case 'pause'
pause
simulationAction = ' ';
case 'stop'
return;
case 'plot'
break;
end
end
TimeGUI('close')
d.friction(1).fStatic = 0.005;
d.friction(1).fCoulomb = 0.005/2;
d.friction(1).vStribeck = 0.1;
d.friction(1).sigma0 = 1;
d.friction(1).sigma1 = 1e-4;
d.friction(1).sigma2 = 4.0585e-05;
d.friction(1).maxC = 0.1/dT;
d.nWheels = 1;
Reinitialize
RWASmart( 'set data', d );
Initialize the time display
[ ratioRealTime, tToGoMem ] = TimeGUI( nSim, 0, [], 0, dT, 'RWA Smart Simulation' );
Initial conditions
x = [0;0;0];
x2Plot = zeros(2,nSim);
t2Plot = zeros(1,nSim);
t = 0;
Commanded voltage
RWASmart( 'put data word', tDemand );
for k = 1:nSim
RWASmart( 'set tachometer states', struct( 'omega', x(1), 'angle', x(3) ) );
tachWord = RWASmart( 'get tachometer word' );
[ ratioRealTime, tToGoMem ] = TimeGUI( nSim, k, tToGoMem, ratioRealTime, dT );
x = RK4( 'RWASmart', x, dT, 0 );
tPlot(k) = t;
x2Plot(:,k) = [x(1,:);RWACountToRate( tachWord, d )];
t2Plot(1,k) = RWASmart('get torque');
t = t + dT;
switch simulationAction
case 'pause'
pause
simulationAction = ' ';
case 'stop'
return;
case 'plot'
break;
end
end
TimeGUI('close')
d.friction(1).fStatic = 0.005;
d.friction(1).fCoulomb = 0.005/2;
d.friction(1).vStribeck = 0.1;
d.friction(1).sigma0 = 1;
d.friction(1).sigma1 = 1e-4;
d.friction(1).sigma2 = 4.0585e-05;
d.friction(1).maxC = 0.1/dT;
d.nWheels = 1;
d = rmfield( d, 'kA ' );
Reinitialize
RWASmart( 'set data', d );
Initialize the time display
[ ratioRealTime, tToGoMem ] = TimeGUI( nSim, 0, [], 0, dT, 'RWA Smart Simulation' );
Initial conditions
x = [0;0;0];
x3Plot = zeros(2,nSim);
t3Plot = zeros(1,nSim);
tPlot = zeros(1,nSim);
t = 0;
Commanded voltage
RWASmart( 'put data word', tDemand );
for k = 1:nSim
RWASmart( 'set tachometer states', struct( 'omega', x(1), 'angle', x(3) ) );
tachWord = RWASmart( 'get tachometer word' );
[ ratioRealTime, tToGoMem ] = TimeGUI( nSim, k, tToGoMem, ratioRealTime, dT );
x = RK4( 'RWASmart', x, dT, 0 );
tPlot(k) = t;
x3Plot(:,k) = [x(1,:);RWACountToRate( tachWord, d )];
t3Plot(1,k) = RWASmart('get torque');
t = t + dT;
switch simulationAction
case 'pause'
pause
simulationAction = ' ';
case 'stop'
return;
case 'plot'
break;
end
end
TimeGUI('close')
RWASmart( 'quit' );
yL = ['Rate';'Rate';'Rate'];
Plot2D( tPlot, [x1Plot;x2Plot;x3Plot], 'Time (sec)', yL, 'Rate','lin',['1:2';'3:4';'5:6'] )
yL = ['Torque';'Torque';'Torque'];
Plot2D( tPlot, [t1Plot;t2Plot;t3Plot], 'Time (sec)', 'Torque' )
m = ['No Friction ';...
'Friction ';...
'No Current Feedback'];
legend(m)