Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added elevation data on simulator side #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Assets/Scripts/GpsSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class GpsSensor : MonoBehaviour
private double initLat = 0.0;
[SerializeField]
private double initLon = 0.0;
[SerializeField]
private double initAlt= 0.0;

private RoverSocket _socket;

Expand Down Expand Up @@ -59,14 +61,16 @@ private void ReportPosition()
// z+ is north, x+ is east
double[] GPS = Utilities.metersToGPS(new double[] {
transform.position.z + _noise * Utilities.GaussianRandom(),
transform.position.x + _noise * Utilities.GaussianRandom()},
new double[] {initLat, initLon});
transform.position.x + _noise * Utilities.GaussianRandom(),
transform.position.y + _noise * Utilities.GaussianRandom()},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are reporting the altitude in meters anyway, I don't think we need to pass it into this metersToGPS function

new double[] {initLat, initLon, initAlt});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably just insert something like double altitude = transform.position.y + _noise * Utilities.GaussianRandom(); here and use it in the report below

JObject positionReport = new JObject()
{
["type"] = "simGpsPositionReport",
["latitude"] = GPS[0],
["longitude"] = GPS[1]
["longitude"] = GPS[1],
["altitude"] = GPS[2]
};
_socket.Send(positionReport);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to update the READMEs with the updated report packets please 🙏

}
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static Quaternion ConvertUnityToRover(Quaternion rotation)
/// <returns></returns>
public static double[] metersToGPS(double[] offset, double[] init = null)
{
init = init is null ? new double[] {0.0, 0.0} : init;
init = init is null ? new double[] {0.0, 0.0, 0.0} : init;
// North is +lat and East is +lon

// The Earth is not a perfect sphere, so we approximate the Earth's surface with an ellipsoid
Expand All @@ -70,7 +70,7 @@ public static double[] metersToGPS(double[] offset, double[] init = null)
double metersPerDegLat = (Math.PI * semiMajorAxis * (1 - eSq)) / (180.0 * Math.Pow(var, 1.5));
double degDiffLat = offset[0] / metersPerDegLat;
double degDiffLon = offset[1] / metersPerDegLon;
return new double[] {init[0] + degDiffLat, init[1] + degDiffLon};
return new double[] {init[0] + degDiffLat, init[1] + degDiffLon, init[2] + offset[2]};
}

/// <summary>
Expand Down