Skip to content

Commit 82fc116

Browse files
committed
Use GLOBAL_POSITION_INT to set altitude and speeds in ArduPilot
1 parent d985bcc commit 82fc116

File tree

2 files changed

+18
-33
lines changed

2 files changed

+18
-33
lines changed

ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduPilot.java

+18-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.MAVLink.ardupilotmega.msg_mount_configure;
1414
import com.MAVLink.ardupilotmega.msg_mount_status;
1515
import com.MAVLink.ardupilotmega.msg_radio;
16+
import com.MAVLink.common.msg_global_position_int;
1617
import com.MAVLink.common.msg_named_value_int;
1718
import com.MAVLink.common.msg_raw_imu;
1819
import com.MAVLink.common.msg_rc_channels_raw;
@@ -416,10 +417,6 @@ public void onMavLinkMessageReceived(MAVLinkMessage message) {
416417
processStatusText(msg_statustext);
417418
break;
418419

419-
case msg_vfr_hud.MAVLINK_MSG_ID_VFR_HUD:
420-
processVfrHud((msg_vfr_hud) message);
421-
break;
422-
423420
case msg_raw_imu.MAVLINK_MSG_ID_RAW_IMU:
424421
msg_raw_imu msg_imu = (msg_raw_imu) message;
425422
mag.newData(msg_imu);
@@ -511,11 +508,25 @@ private void checkControlSensorsHealth(msg_sys_status sysStatus) {
511508
}
512509
}
513510

514-
protected void processVfrHud(msg_vfr_hud vfrHud) {
515-
if (vfrHud == null)
511+
/**
512+
* Used to update the vehicle location, and altitude.
513+
* @param gpi
514+
*/
515+
@Override
516+
protected void processGlobalPositionInt(msg_global_position_int gpi) {
517+
if(gpi == null)
516518
return;
517519

518-
setAltitudeGroundAndAirSpeeds(vfrHud.alt, vfrHud.groundspeed, vfrHud.airspeed, vfrHud.climb);
520+
super.processGlobalPositionInt(gpi);
521+
522+
final double relativeAlt = gpi.relative_alt / 1000.0;
523+
524+
final double groundSpeedX = gpi.vx / 100.0;
525+
final double groundSpeedY = gpi.vy / 100.0;
526+
final double groundSpeed = Math.sqrt(Math.pow(groundSpeedX, 2) + Math.pow(groundSpeedY, 2));
527+
528+
final double climbRate = gpi.vz / 100.0;
529+
setAltitudeGroundAndAirSpeeds(relativeAlt, groundSpeed, groundSpeed, climbRate);
519530
}
520531

521532
protected void processMountStatus(msg_mount_status mountStatus) {

ClientLib/src/main/java/org/droidplanner/services/android/impl/core/drone/autopilot/apm/ArduPlane.java

-26
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,6 @@ public FirmwareType getFirmwareType() {
4141
return FirmwareType.ARDU_PLANE;
4242
}
4343

44-
@Override
45-
protected void processVfrHud(msg_vfr_hud vfrHud){
46-
//Nothing to do. Plane used GLOBAL_POSITION_INT to set altitude and speeds unlike copter
47-
}
48-
49-
/**
50-
* Used to update the vehicle location, and altitude.
51-
* @param gpi
52-
*/
53-
@Override
54-
protected void processGlobalPositionInt(msg_global_position_int gpi){
55-
if(gpi == null)
56-
return;
57-
58-
super.processGlobalPositionInt(gpi);
59-
60-
final double relativeAlt = gpi.relative_alt / 1000.0;
61-
62-
final double groundSpeedX = gpi.vx / 100.0;
63-
final double groundSpeedY = gpi.vy / 100.0;
64-
final double groundSpeed = Math.sqrt(Math.pow(groundSpeedX, 2) + Math.pow(groundSpeedY, 2));
65-
66-
final double climbRate = gpi.vz / 100.0;
67-
setAltitudeGroundAndAirSpeeds(relativeAlt, groundSpeed, groundSpeed, climbRate);
68-
}
69-
7044
@Override
7145
protected boolean isFeatureSupported(String featureId){
7246
switch(featureId){

0 commit comments

Comments
 (0)