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

10 次查看(过去 30 天)
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

采纳的回答

Ryan Salvo
Ryan Salvo 2025-3-31
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

更多回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2025-3-30
编辑:KALYAN ACHARJYA 2025-3-30
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 个评论
inhyeok
inhyeok 2025-3-30
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

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by