How to ensure that all values are not equal when using the ecef2enu function

11 visualizaciones (últimos 30 días)
I'm doing coordinate system transformation using the ecef2enu function. But for some reason, all three E, N, and U values are the same. I wonder why. How can I modify it to get the exact value?
Isn't it normal for the 1, 2, 3 matrices to have different values? Is there something wrong with my code?
currTime = gnss.SensorModel.InitialTime;
setup(scene)
wgs84 = wgs84Ellipsoid('meter');
while scene.IsRunning
[~,~,p,satPos,status] = gnss.read ();
allSatPos = gnssconstellation(currTime); % ecef
currTime = currTime + seconds(1/scene.UpdateRate);
[~,trueRecPos] = plat.read; % lla
trueRecPos_ecef = lla2ecef(trueRecPos); % uav ecef
[az,el] = lookangles(trueRecPos,satPos,gnss.SensorModel.MaskAngle);
nsat = length(satPos(:,1));
enu_sat = zeros(nsat,3);
for k = 1:1:nsat
enu_sat(k,:) = ecef2enu(satPos(k,1),satPos(k,2),satPos(k,3),trueRecPos(1),trueRecPos(2),trueRecPos(3),wgs84);
end
temp=1;
unit_sat = normalize(enu_sat,'norm',1);
target_z = 500;
scale_factors = target_z ./ unit_sat(:,3);
unit_sat_scaled = unit_sat .* scale_factors;
end

Respuesta aceptada

Ryan Salvo
Ryan Salvo el 31 de Mzo. de 2025
The ecef2enu function returns three output arguments, but you are setting all three columns of the enu_sat variable with only the first output argument. Update the for-loop to:
for k = 1:1:nsat
[enu_sat(k,1),enu_sat(k,2),enu_sat(k,3)] = ecef2enu(satPos(k,1),satPos(k,2),satPos(k,3),trueRecPos_lla(1),trueRecPos_lla(2),trueRecPos_lla(3),wgs84);
end

Más respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 30 de Mzo. de 2025
Editada: KALYAN ACHARJYA el 30 de Mzo. de 2025
As there may be multiple reasons, I don't have the complete data file and am unable to reproduce the issue. Please give it a try converting Earth-Centered Earth-Fixed (ECEF) coordinates to geodetic coordinates first might help.
trueRecPos_lla = ecef2lla(trueRecPos_ecef);
enu_sat(k,:) = ecef2enu(satPos(k,1), satPos(k,2), satPos(k,3), trueRecPos_lla(1), trueRecPos_lla(2), trueRecPos_lla(3), wgs84);
  1 comentario
inhyeok
inhyeok el 30 de Mzo. de 2025
It's the same as before..
I'll show you the full code. I recommend replacing the .osm file in the middle with something else.
referenceLocation=[37.498759 127.027487 0];
stopTime = 1;
scene = uavScenario(ReferenceLocation=referenceLocation,UpdateRate=10,StopTime=stopTime);
xTerrainLimits = [-200 200];
yTerrainLimits = [-200 200];
xBuildingLimits = [-150 150];
yBuildingLimits = [-150 150];
color = [0.80302 0.80298 0.8029];
addMesh(scene,"buildings",{"gangnam_11exit.osm" xBuildingLimits yBuildingLimits,"auto"},color)
uavTrajectory = waypointTrajectory([0 0 1; 0 0 1],TimeOfArrival=[0 stopTime],ReferenceFrame="ENU");
plat = uavPlatform("UAV",scene,Trajectory=uavTrajectory,ReferenceFrame="ENU");
updateMesh(plat,"quadrotor",{1},[1 0 0],eye(4));
gnss = uavSensor("GNSS",plat,gnssMeasurementGenerator(ReferenceLocation=referenceLocation));
fig = figure;
ax = show3D(scene);
uavPosition = uavTrajectory.lookupPose(linspace(0,stopTime,35));
hold on
uavTrajectoryLine = plot3(uavPosition(:,1),uavPosition(:,2),uavPosition(:,3),".",LineWidth=1.5,Color="cyan",MarkerSize=15);
legend(uavTrajectoryLine,"Trajectory",Location="northeast")
clf(fig,"reset")
set(fig,Position=[400 458 1120 420])
hScenePlot = uipanel(fig,Position=[0 0 0.5 1]);
ax = axes(hScenePlot);
[~,pltFrames] = show3D(scene,Parent=ax);
hold(ax,"on")
uavMarker = plot(pltFrames.UAV.BodyFrame,0,0,Marker="o",MarkerFaceColor="cyan");
uavTrajectoryLine = plot3(uavPosition(:,1),uavPosition(:,2),uavPosition(:,3),"--",LineWidth=1.5,Color="cyan");
legend(ax,[uavMarker uavTrajectoryLine],["UAV","Trajectory"],Location="northeast")
view(ax,[0 90])
axis(ax,"equal")
hold(ax,"off")
currTime = gnss.SensorModel.InitialTime;
setup(scene)
wgs84 = wgs84Ellipsoid('meter');
while scene.IsRunning
[~,~,p,satPos,status] = gnss.read ();
allSatPos = gnssconstellation(currTime); % ecef
currTime = currTime + seconds(1/scene.UpdateRate);
[~,trueRecPos] = plat.read; % lla
trueRecPos_ecef = lla2ecef(trueRecPos); % uav ecef
trueRecPos_lla = ecef2lla(trueRecPos_ecef);
[az,el] = lookangles(trueRecPos,satPos,gnss.SensorModel.MaskAngle);
nsat = length(satPos(:,1));
enu_sat = zeros(nsat,3);
for k = 1:1:nsat
enu_sat(k,:) = ecef2enu(satPos(k,1),satPos(k,2),satPos(k,3),trueRecPos_lla(1),trueRecPos_lla(2),trueRecPos_lla(3),wgs84);
end
temp=1;
unit_sat = normalize(enu_sat,'norm',1);
target_z = 500;
scale_factors = target_z ./ unit_sat(:,3);
unit_sat_scaled = unit_sat .* scale_factors;
end

Iniciar sesión para comentar.

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by