Skip to content

Commit 781e783

Browse files
committed
Merge branches 'develop' and 'release-1.4.0.beta.1' of github.com:DroidPlanner/DroneKit-Android into release-1.4.0.beta.1
2 parents ba8bdb2 + e7f8da0 commit 781e783

File tree

8 files changed

+119
-60
lines changed

8 files changed

+119
-60
lines changed

ClientLib/src/main/java/com/o3dr/android/client/apis/VehicleApi.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.o3dr.android.client.Drone;
66
import com.o3dr.services.android.lib.coordinate.LatLong;
7+
import com.o3dr.services.android.lib.coordinate.LatLongAlt;
78
import com.o3dr.services.android.lib.drone.attribute.AttributeType;
89
import com.o3dr.services.android.lib.drone.connection.ConnectionParameter;
910
import com.o3dr.services.android.lib.drone.property.Gps;
@@ -21,9 +22,11 @@
2122
import static com.o3dr.services.android.lib.drone.action.ParameterActions.ACTION_WRITE_PARAMETERS;
2223
import static com.o3dr.services.android.lib.drone.action.ParameterActions.EXTRA_PARAMETERS;
2324
import static com.o3dr.services.android.lib.drone.action.StateActions.ACTION_ARM;
25+
import static com.o3dr.services.android.lib.drone.action.StateActions.ACTION_SET_VEHICLE_HOME;
2426
import static com.o3dr.services.android.lib.drone.action.StateActions.ACTION_SET_VEHICLE_MODE;
2527
import static com.o3dr.services.android.lib.drone.action.StateActions.EXTRA_ARM;
2628
import static com.o3dr.services.android.lib.drone.action.StateActions.EXTRA_EMERGENCY_DISARM;
29+
import static com.o3dr.services.android.lib.drone.action.StateActions.EXTRA_VEHICLE_HOME_LOCATION;
2730
import static com.o3dr.services.android.lib.drone.action.StateActions.EXTRA_VEHICLE_MODE;
2831

2932
/**
@@ -225,4 +228,15 @@ public void pauseAtCurrentLocation() {
225228
public void pauseAtCurrentLocation(final AbstractCommandListener listener) {
226229
controlApi.pauseAtCurrentLocation(listener);
227230
}
231+
232+
/**
233+
* Changes the vehicle home location.
234+
* @param homeLocation New home coordinate
235+
* @param listener Register a callback to receive update of the command execution state.
236+
*/
237+
public void setVehicleHome(final LatLongAlt homeLocation, final AbstractCommandListener listener){
238+
Bundle params = new Bundle();
239+
params.putParcelable(EXTRA_VEHICLE_HOME_LOCATION, homeLocation);
240+
drone.performAsyncActionOnDroneThread(new Action(ACTION_SET_VEHICLE_HOME, params), listener);
241+
}
228242
}

ClientLib/src/main/java/com/o3dr/services/android/lib/drone/action/StateActions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public class StateActions {
1414
public static final String ACTION_SET_VEHICLE_MODE = Utils.PACKAGE_NAME + ".action.SET_VEHICLE_MODE";
1515
public static final String EXTRA_VEHICLE_MODE = "extra_vehicle_mode";
1616

17+
public static final String ACTION_SET_VEHICLE_HOME = Utils.PACKAGE_NAME + ".action.SET_VEHICLE_HOME";
18+
public static final String EXTRA_VEHICLE_HOME_LOCATION = "extra_vehicle_home_location";
19+
1720
//Private to prevent instantiation
1821
private StateActions(){}
1922
}

ServiceApp/src/org/droidplanner/services/android/core/MAVLink/command/doCmd/MavLinkDoCmds.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,30 @@
66
import com.MAVLink.common.msg_mission_set_current;
77
import com.MAVLink.enums.GRIPPER_ACTIONS;
88
import com.MAVLink.enums.MAV_CMD;
9+
import com.o3dr.services.android.lib.coordinate.LatLongAlt;
910
import com.o3dr.services.android.lib.model.ICommandListener;
1011

1112
import org.droidplanner.services.android.core.drone.autopilot.MavLinkDrone;
1213
import org.droidplanner.services.android.core.helpers.coordinates.Coord3D;
1314

1415
public class MavLinkDoCmds {
16+
17+
public static void setVehicleHome(MavLinkDrone drone, LatLongAlt location, ICommandListener listener){
18+
if(drone == null || location == null)
19+
return;
20+
21+
msg_command_long msg = new msg_command_long();
22+
msg.target_system = drone.getSysid();
23+
msg.target_component = drone.getCompid();
24+
msg.command = MAV_CMD.MAV_CMD_DO_SET_HOME;
25+
26+
msg.param5 = (float) location.getLatitude();
27+
msg.param6 = (float) location.getLongitude();
28+
msg.param7 = (float) location.getAltitude();
29+
30+
drone.getMavClient().sendMavMessage(msg, listener);
31+
}
32+
1533
public static void setROI(MavLinkDrone drone, Coord3D coord, ICommandListener listener) {
1634
if (drone == null)
1735
return;

ServiceApp/src/org/droidplanner/services/android/core/drone/DroneManager.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ public DroneAttribute getAttribute(String attributeType) {
568568
}
569569

570570
@Override
571-
public void executeAsyncAction(Action action, final ICommandListener listener) {
571+
public boolean executeAsyncAction(Action action, final ICommandListener listener) {
572572
final String type = action.getType();
573573
Bundle data = action.getData();
574574

@@ -581,14 +581,14 @@ public void executeAsyncAction(Action action, final ICommandListener listener) {
581581
bundle.putFloat(AttributeEventExtra.EXTRA_MISSION_DRONIE_BEARING, bearing);
582582
notifyDroneAttributeEvent(AttributeEvent.MISSION_DRONIE_CREATED, bundle);
583583
}
584-
break;
584+
return true;
585585

586586
//FOLLOW-ME ACTIONS
587587
case FollowMeActions.ACTION_ENABLE_FOLLOW_ME:
588588
data.setClassLoader(FollowType.class.getClassLoader());
589589
FollowType followType = data.getParcelable(FollowMeActions.EXTRA_FOLLOW_TYPE);
590590
CommonApiUtils.enableFollowMe(this, handler, followType, listener);
591-
break;
591+
return true;
592592

593593
case FollowMeActions.ACTION_UPDATE_FOLLOW_PARAMS:
594594
if (followMe != null) {
@@ -619,51 +619,51 @@ public void executeAsyncAction(Action action, final ICommandListener listener) {
619619
followAlgorithm.updateAlgorithmParams(paramsMap);
620620
}
621621
}
622-
break;
622+
return true;
623623

624624
case FollowMeActions.ACTION_DISABLE_FOLLOW_ME:
625625
CommonApiUtils.disableFollowMe(followMe);
626-
break;
626+
return true;
627627

628628
//************ SOLOLINK ACTIONS *************//
629629
case SoloActions.ACTION_SEND_MESSAGE:
630630
final TLVPacket messageData = data.getParcelable(SoloActions.EXTRA_MESSAGE_DATA);
631631
if (messageData != null) {
632632
SoloApiUtils.sendSoloLinkMessage(this, messageData, listener);
633633
}
634-
break;
634+
return true;
635635

636636
case SoloConfigActions.ACTION_UPDATE_WIFI_SETTINGS:
637637
final String wifiSsid = data.getString(SoloConfigActions.EXTRA_WIFI_SSID);
638638
final String wifiPassword = data.getString(SoloConfigActions.EXTRA_WIFI_PASSWORD);
639639
SoloApiUtils.updateSoloLinkWifiSettings(this, wifiSsid, wifiPassword, listener);
640-
break;
640+
return true;
641641

642642
case SoloConfigActions.ACTION_UPDATE_BUTTON_SETTINGS:
643643
final SoloButtonSettingSetter buttonSettings = data.getParcelable(SoloConfigActions.EXTRA_BUTTON_SETTINGS);
644644
if (buttonSettings != null) {
645645
SoloApiUtils.updateSoloLinkButtonSettings(this, buttonSettings, listener);
646646
}
647-
break;
647+
return true;
648648

649649
case SoloConfigActions.ACTION_UPDATE_CONTROLLER_MODE:
650650
final @SoloControllerMode.ControllerMode int mode = data.getInt(SoloConfigActions.EXTRA_CONTROLLER_MODE);
651651
SoloApiUtils.updateSoloLinkControllerMode(this, mode, listener);
652-
break;
652+
return true;
653653

654654
case SoloConfigActions.ACTION_UPDATE_EU_TX_POWER_COMPLIANCE:
655655
final boolean isCompliant = data.getBoolean(SoloConfigActions.EXTRA_EU_TX_POWER_COMPLIANT, false);
656656
SoloApiUtils.updateSoloLinkEUTxPowerCompliance(this, isCompliant, listener);
657-
break;
657+
return true;
658658

659659
case SoloConfigActions.ACTION_REFRESH_SOLO_VERSIONS:
660660
soloComp.refreshSoloVersions();
661-
break;
661+
return true;
662662

663663
case SoloConfigActions.ACTION_UPDATE_CONTROLLER_UNIT:
664664
final @SoloControllerUnits.ControllerUnit String unit = data.getString(SoloConfigActions.EXTRA_CONTROLLER_UNIT);
665665
SoloApiUtils.updateSoloControllerUnit(this, unit, listener);
666-
break;
666+
return true;
667667

668668
//**************** CAPABILITY ACTIONS **************//
669669
case CapabilityActions.ACTION_CHECK_FEATURE_SUPPORT:
@@ -696,15 +696,15 @@ public void executeAsyncAction(Action action, final ICommandListener listener) {
696696
}
697697
}
698698
}
699-
break;
699+
return true;
700700

701701
default:
702702
if (drone != null) {
703-
drone.executeAsyncAction(action, listener);
703+
return drone.executeAsyncAction(action, listener);
704704
} else {
705705
CommonApiUtils.postErrorEvent(CommandExecutionError.COMMAND_FAILED, listener);
706+
return true;
706707
}
707-
break;
708708
}
709709
}
710710

ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/CommonMavLinkDrone.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.droidplanner.services.android.core.drone.autopilot;
22

3+
import android.os.Bundle;
34
import android.text.TextUtils;
45

56
import com.MAVLink.Messages.MAVLinkMessage;
@@ -8,18 +9,26 @@
89
import com.MAVLink.common.msg_heartbeat;
910
import com.MAVLink.common.msg_radio_status;
1011
import com.MAVLink.common.msg_vibration;
12+
import com.o3dr.services.android.lib.coordinate.LatLongAlt;
13+
import com.o3dr.services.android.lib.drone.action.StateActions;
1114
import com.o3dr.services.android.lib.drone.attribute.AttributeEvent;
1215
import com.o3dr.services.android.lib.drone.attribute.AttributeType;
16+
import com.o3dr.services.android.lib.drone.attribute.error.CommandExecutionError;
17+
import com.o3dr.services.android.lib.drone.mission.action.MissionActions;
1318
import com.o3dr.services.android.lib.drone.property.Altitude;
1419
import com.o3dr.services.android.lib.drone.property.Attitude;
1520
import com.o3dr.services.android.lib.drone.property.Battery;
1621
import com.o3dr.services.android.lib.drone.property.DroneAttribute;
1722
import com.o3dr.services.android.lib.drone.property.Signal;
1823
import com.o3dr.services.android.lib.drone.property.Speed;
24+
import com.o3dr.services.android.lib.drone.property.VehicleMode;
1925
import com.o3dr.services.android.lib.drone.property.Vibration;
26+
import com.o3dr.services.android.lib.model.ICommandListener;
27+
import com.o3dr.services.android.lib.model.action.Action;
2028
import com.o3dr.services.android.lib.util.MathUtils;
2129

2230
import org.droidplanner.services.android.core.MAVLink.MAVLinkStreams;
31+
import org.droidplanner.services.android.core.MAVLink.command.doCmd.MavLinkDoCmds;
2332
import org.droidplanner.services.android.core.drone.DroneEvents;
2433
import org.droidplanner.services.android.core.drone.DroneInterfaces;
2534
import org.droidplanner.services.android.core.drone.variables.State;
@@ -96,6 +105,38 @@ public MAVLinkStreams.MAVLinkOutputStream getMavClient() {
96105
return MavClient;
97106
}
98107

108+
@Override
109+
public boolean executeAsyncAction(Action action, ICommandListener listener){
110+
final String type = action.getType();
111+
Bundle data = action.getData();
112+
113+
switch(type){
114+
//MISSION ACTIONS
115+
case MissionActions.ACTION_GOTO_WAYPOINT:
116+
int missionItemIndex = data.getInt(MissionActions.EXTRA_MISSION_ITEM_INDEX);
117+
CommonApiUtils.gotoWaypoint(this, missionItemIndex, listener);
118+
return true;
119+
120+
//STATE ACTIONS
121+
case StateActions.ACTION_SET_VEHICLE_MODE:
122+
data.setClassLoader(VehicleMode.class.getClassLoader());
123+
VehicleMode newMode = data.getParcelable(StateActions.EXTRA_VEHICLE_MODE);
124+
CommonApiUtils.changeVehicleMode(this, newMode, listener);
125+
return true;
126+
127+
case StateActions.ACTION_SET_VEHICLE_HOME:
128+
final LatLongAlt homeLoc = data.getParcelable(StateActions.EXTRA_VEHICLE_HOME_LOCATION);
129+
if(homeLoc != null){
130+
MavLinkDoCmds.setVehicleHome(this, homeLoc, listener);
131+
}
132+
return true;
133+
134+
default:
135+
CommonApiUtils.postErrorEvent(CommandExecutionError.COMMAND_UNSUPPORTED, listener);
136+
return true;
137+
}
138+
}
139+
99140
@Override
100141
public DroneAttribute getAttribute(String attributeType) {
101142
if (TextUtils.isEmpty(attributeType))

ServiceApp/src/org/droidplanner/services/android/core/drone/autopilot/Drone.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ public interface Drone {
1313

1414
DroneAttribute getAttribute(String attributeType);
1515

16-
void executeAsyncAction(Action action, ICommandListener listener);
16+
boolean executeAsyncAction(Action action, ICommandListener listener);
1717
}

0 commit comments

Comments
 (0)