gpsSensor problem with Random Stream

12 次查看(过去 30 天)
Hi to everybody!
I have a big problem with my gpsSensor. In my model I need to use 2 gps: one for my boat and one for my buoy (target).
The two GPS shares the same characteristics but I expected to have two different random stream. I saw on the decumentation that the deafult RandomStream is Global Stream and it's ok for my sensors, but i would like to have two different random stream for my GPS.
Hope that I weel explained my problem.
Thank you in advance!!!

采纳的回答

Ryan Salvo
Ryan Salvo 2021-4-28
Hi Leonardo,
To set two gpsSensor objects to two independent random streams, you can set the RandomStream and Seed properties on the gpsSensor.
Thanks,
Ryan
% Set each of the seeds to different values.
seed1 = 20;
seed2 = 40;
gps1 = gpsSensor("RandomStream", "mt19937ar with seed", "Seed", seed1);
gps2 = gpsSensor("RandomStream", "mt19937ar with seed", "Seed", seed2);
  5 个评论
Ryan Salvo
Ryan Salvo 2021-4-28
编辑:Ryan Salvo 2021-4-28
Hi Leonardo,
No problem. The issue is that gpsSensor is getting re-initialized every step in the MATLAB Function Block. Since gpsSensor is a System object, you'll want to make it a persistent variable so that its internal state is maintained between calls to the MATLAB Function Block. Something like this:
function output_GPS = fcn(x,RMS)
% Only create the GPS at the beginning of simulation.
persistent GPS;
if isempty(GPS)
GPS = gpsSensor('SampleRate',10,...
'HorizontalPositionAccuracy',RMS,...
'VelocityAccuracy',0.01,...
'RandomStream', "mt19937ar with seed",...
"Seed", 20);
end
%% Stato
X = x(1); % FIX
Y = x(2); % FIX
psi = x(3);
u = x(4);
v = x(5);
%% Matrici di rotazione
R_fix_Ned = eul2rotm([pi/2,0,pi]); % Fix To NED Z Y' X''
R_mob_fix = [cos(psi) -sin(psi) 0;... % Mob To Fix
sin(psi) cos(psi) 0;...
0 0 1];
%% Coordinate in NED
Pos_Ned = R_fix_Ned*[X;Y;0];
V_Ned = R_fix_Ned*R_mob_fix*[u;v;0];
%% Calcolo posizione in GPS
[coord_geo,speed_Ned,~,~] = GPS(Pos_Ned',V_Ned'); % [m],[m/s]
%% Posizione GPS in sistema mobile e fisso
lat = coord_geo(1);
lon = coord_geo(2);
alt = coord_geo(3);
lat0 = 0;
lon0 = 0;
alt0 = 0;
coder.extrinsic('referenceEllipsoid','geodetic2ned')
% % Inizializzazione variabili
fixCoord_GPS = zeros(3,1);
fixSpeed_GPS = zeros(3,1);
mobSpeed_GPS = zeros(3,1);
output_GPS = zeros(4,1);
% %
spheroid = referenceEllipsoid('GRS 80');
[xNorth,yEast,zDown] = geodetic2ned(lat,lon,alt,lat0,lon0,alt0,spheroid);
fixCoord_GPS = R_fix_Ned'*[xNorth;yEast;zDown];
fixSpeed_GPS = R_fix_Ned'*speed_Ned';
mobSpeed_GPS = R_mob_fix'*fixSpeed_GPS;
%% Stato GPS
X_GPS = fixCoord_GPS(1);
Y_GPS = fixCoord_GPS(2);
u_GPS = mobSpeed_GPS(1);
v_GPS = mobSpeed_GPS(2);
output_GPS = [X_GPS;Y_GPS;u_GPS;v_GPS];
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Automated Driving Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by