Skip to content

Commit d23ea4b

Browse files
authored
Use attitude heading (#3663)
* Rename heading * Change gpsHeading message * Use IMU heading on GPS tab * Remove precision and rotation * Code style fixes
1 parent 07da339 commit d23ea4b

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

locales/en/messages.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,8 @@
818818
"message": "Reset Z axis, offset: $1 deg"
819819
},
820820
"initialSetupHeading": {
821-
"message": "Heading:",
822-
"description": "Heading shown on Setup tab"
821+
"message": "Yaw:",
822+
"description": "Heading [yaw] attitude value shown on Setup tab"
823823
},
824824
"initialSetupMixerHead": {
825825
"message": "Mixer Type"
@@ -2823,8 +2823,8 @@
28232823
"description": "Show GPS position - Latitude / Longitude"
28242824
},
28252825
"gpsHeading": {
2826-
"message": "Heading Mag / GPS:",
2827-
"description": "Show GPS heading - Magnetic / GPS course over ground"
2826+
"message": "Heading IMU / GPS:",
2827+
"description": "Show IMU / GPS heading - Attitude / GPS course over ground"
28282828
},
28292829
"gpsSpeed": {
28302830
"message": "Speed:"

src/js/tabs/gps.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ gps.initialize = async function (callback) {
5252
}
5353

5454
function get_gpsvinfo_data() {
55-
MSP.send_message(MSPCodes.MSP_GPS_SV_INFO, false, false, hasMag ? get_imu_data : update_ui);
55+
MSP.send_message(MSPCodes.MSP_GPS_SV_INFO, false, false, get_attitude_data);
56+
}
57+
58+
function get_attitude_data() {
59+
MSP.send_message(MSPCodes.MSP_ATTITUDE, false, false, hasMag ? get_imu_data : update_ui);
5660
}
5761

5862
function get_imu_data() {
@@ -185,6 +189,7 @@ gps.initialize = async function (callback) {
185189
const lat = FC.GPS_DATA.lat / 10000000;
186190
const lon = FC.GPS_DATA.lon / 10000000;
187191
const url = `https://maps.google.com/?q=${lat},${lon}`;
192+
const imuHeading = FC.SENSOR_DATA.kinematics[2];
188193
const magHeading = hasMag ? Math.atan2(FC.SENSOR_DATA.magnetometer[1], FC.SENSOR_DATA.magnetometer[0]) : undefined;
189194
const magHeadingDeg = magHeading === undefined ? 0 : magHeading * 180 / Math.PI;
190195
const gpsHeading = FC.GPS_DATA.ground_course / 100;
@@ -200,7 +205,7 @@ gps.initialize = async function (callback) {
200205
const gspUnitText = i18n.getMessage('gpsPositionUnit');
201206
$('.GPS_info td.alt').text(`${alt} m`);
202207
$('.GPS_info td.latLon a').prop('href', url).text(`${lat.toFixed(6)} / ${lon.toFixed(6)} ${gspUnitText}`);
203-
$('.GPS_info td.heading').text(`${magHeadingDeg.toFixed(4)} / ${gpsHeading.toFixed(4)} ${gspUnitText}`);
208+
$('.GPS_info td.heading').text(`${imuHeading.toFixed(0)} / ${gpsHeading.toFixed(0)} ${gspUnitText}`);
204209
$('.GPS_info td.speed').text(`${FC.GPS_DATA.speed} cm/s`);
205210
$('.GPS_info td.sats').text(FC.GPS_DATA.numSat);
206211
$('.GPS_info td.distToHome').text(`${FC.GPS_DATA.distanceToHome} m`);
@@ -298,7 +303,7 @@ gps.initialize = async function (callback) {
298303
action: 'center',
299304
lat: lat,
300305
lon: lon,
301-
heading: magHeading,
306+
heading: gpsHeading,
302307
};
303308

304309
frame = document.getElementById('map');

src/js/tabs/map.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,41 @@ function initializeMap() {
2121
const lonLat = ol.proj.fromLonLat([DEFAULT_LON, DEFAULT_LAT]);
2222

2323
mapView = new ol.View({
24-
center: lonLat,
25-
zoom: DEFAULT_ZOOM,
26-
});
24+
center: lonLat,
25+
zoom: DEFAULT_ZOOM,
26+
});
2727

2828
map = new ol.Map({
2929
target: 'map-canvas',
3030
layers: [
31-
new ol.layer.Tile({
32-
source: new ol.source.OSM(),
33-
}),
31+
new ol.layer.Tile({
32+
source: new ol.source.OSM(),
33+
}),
3434
],
3535
view: mapView,
3636
controls: [],
37-
});
37+
});
3838

39-
const iconGPS = new ol.style.Icon(({
39+
const iconGPS = new ol.style.Icon({
4040
anchor: [0.5, 1],
4141
opacity: 1,
4242
scale: 0.5,
4343
src: ICON_IMAGE_GPS,
44-
}));
44+
});
4545

46-
const iconMag = new ol.style.Icon(({
46+
const iconMag = new ol.style.Icon({
4747
anchor: [0.5, 1],
4848
opacity: 1,
4949
scale: 0.5,
5050
src: ICON_IMAGE_MAG,
51-
}));
51+
});
5252

53-
const iconNoFix = new ol.style.Icon(({
53+
const iconNoFix = new ol.style.Icon({
5454
anchor: [0.5, 1],
5555
opacity: 1,
5656
scale: 0.5,
5757
src: ICON_IMAGE_NOFIX,
58-
}));
58+
});
5959

6060
iconStyleGPS = new ol.style.Style({
6161
image: iconGPS,
@@ -70,6 +70,7 @@ function initializeMap() {
7070
});
7171

7272
iconGeometry = new ol.geom.Point(lonLat);
73+
7374
iconFeature = new ol.Feature({
7475
geometry: iconGeometry,
7576
});
@@ -106,8 +107,9 @@ function processMapEvents(e) {
106107
iconFeature.setStyle(iconStyle);
107108
const center = ol.proj.fromLonLat([e.data.lon, e.data.lat]);
108109
mapView.setCenter(center);
109-
const heading = e.data.heading === undefined ? 0 : e.data.heading;
110-
mapView.setRotation(heading);
110+
// TODO - add rotation for the icon
111+
// const heading = e.data.heading === undefined ? 0 : e.data.heading;
112+
// mapView.setRotation(heading);
111113
iconGeometry.setCoordinates(center);
112114
break;
113115

0 commit comments

Comments
 (0)