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

Elevation data #343

Open
wants to merge 6 commits into
base: master
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
6 changes: 4 additions & 2 deletions src/ardupilot/ArduPilotProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ void ArduPilotProtocol::clientDisconnected() {

bool ArduPilotProtocol::validateGPSRequest(const json& j) {
return util::validateKey(j, "lat", val_t::number_float) &&
util::validateKey(j, "lon", val_t::number_float);
util::validateKey(j, "lon", val_t::number_float) &&
util::validateKey(j, "alt", val_t::number_float);
}

void ArduPilotProtocol::handleGPSRequest(const json& j) {
double lat = j["lat"];
double lon = j["lon"];
double alt = j["alt"];
{
std::lock_guard<std::mutex> lock(_lastGPSMutex);
_lastGPS = gpscoords_t{lat, lon};
_lastGPS = gpscoords_t{lat, lon, alt};
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/gps/usb_gps/read_usb_gps.cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is obsolete so changes here are not required.

Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ void gps_loop() {
} else {
double lat = newdata->fix.latitude;
double lon = newdata->fix.longitude;
LOG_F(2, "Received fresh GPS data: (lat %.6f, lon %.6f).", lat, lon);
double alt = newdata->fix.altitude;
LOG_F(2, "Received fresh GPS data: (lat %.6f, lon %.6f).", lat, lon, alt);
gps_mutex.lock();
if (!has_fix) {
// This is our first fix
has_fix = true;
}

most_recent_coords = {lat, lon};
most_recent_coords = {lat, lon, alt};
gps_time = dataclock::now();
gps_mutex.unlock();
}
Expand Down
2 changes: 2 additions & 0 deletions src/navtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct gpscoords_t {
double lat;
/** the longitude of the gps coordinate, in degrees */
double lon;
/** the altitude of the gps coordinate */
Copy link
Contributor

Choose a reason for hiding this comment

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

See https://github.com/huskyroboticsteam/ardupilot-driver/pull/2/files and update this comment to specify the unit of data

double alt;
};

/* @brief Euler angles to represent orientation. Rotation ordering is XYZ extrinsic
Expand Down
4 changes: 2 additions & 2 deletions src/network/MissionControlProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ static bool validateWaypointNavRequest(const json& j) {
void MissionControlProtocol::handleWaypointNavRequest(const json& j) {
float latitude = j["latitude"];
float longitude = j["longitude"];
float altitude = j["altitude"];
bool isApproximate = j["isApproximate"];
bool isGate = j["isGate"];

if (Globals::AUTONOMOUS && !isApproximate && !isGate) {
navtypes::gpscoords_t coords = {latitude, longitude};
navtypes::gpscoords_t coords = {latitude, longitude, altitude};
auto target = robot::gpsToMeters(coords);
if (target) {
_autonomous_task.start(target.value());
Expand Down
4 changes: 3 additions & 1 deletion src/network/MissionControlTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ void TelemReportTask::sendTelemetry() {
util::to_string(gps.isValid()).c_str());
if (imu.isValid()) {
Eigen::Quaterniond quat = imu.getData();
double lon = 0, lat = 0;
double lon = 0, lat = 0, alt = 0;
if (gps.isValid()) {
lon = gps.getData().lon;
lat = gps.getData().lat;
alt = gps.getData().alt;
}
double imuRecency = util::durationToSec(dataclock::now() - imu.getTime());
double recency = imuRecency;
Expand All @@ -219,6 +220,7 @@ void TelemReportTask::sendTelemetry() {
{"orientZ", quat.z()},
{"lon", lon},
{"lat", lat},
{"alt", alt},
{"recency", recency}};
_server.sendJSON(Constants::MC_PROTOCOL_NAME, msg);
}
Expand Down
2 changes: 1 addition & 1 deletion src/world_interface/simulator_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void initMotors() {
}

void handleGPS(json msg) {
gpscoords_t coords{msg["latitude"], msg["longitude"]};
gpscoords_t coords{msg["latitude"], msg["longitude"], msg["altitude"]};
std::lock_guard<std::mutex> guard(gpsMutex);
lastGPS = {coords};
}
Expand Down