Skip to content

Commit

Permalink
updated mavlink library with the latest definitions files.
Browse files Browse the repository at this point in the history
added experimentation spline follow modes.
  • Loading branch information
m4gr3d committed Jan 6, 2015
1 parent dcbff9e commit d129a0d
Show file tree
Hide file tree
Showing 33 changed files with 527 additions and 207 deletions.
4 changes: 2 additions & 2 deletions AidlLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 20023
versionName '2.0.23'
versionCode 20024
versionName '2.0.24'
}

defaultPublishConfig "release"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public enum FollowType implements Parcelable {
RIGHT("Right"),
LEFT("Left"),
CIRCLE("Circle"),
ABOVE("Above");
ABOVE("Above"),
SPLINE_LEASH("Spline Leash"),
SPLINE_ABOVE("Spline Above");

private final String typeLabel;

Expand Down
4 changes: 2 additions & 2 deletions ClientLib/mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

ext {
PUBLISH_ARTIFACT_ID = '3dr-services-lib'
PUBLISH_VERSION = '2.1.33'
PUBLISH_VERSION = '2.1.34'
PROJECT_DESCRIPTION = "3DR Services Client Library"
PROJECT_LABELS = ['3DR', '3DR Services', 'DroneAPI', 'Android']
PROJECT_LICENSES = ['Apache-2.0']
Expand All @@ -15,7 +15,7 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 20133
versionCode 20134
versionName PUBLISH_VERSION
}

Expand Down
Binary file modified ClientLib/mobile/libs/AidlLib.jar
Binary file not shown.
79 changes: 49 additions & 30 deletions ServiceApp/src/org/droidplanner/services/android/api/DroneApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -657,36 +657,7 @@ public void setGuidedVelocity(double xVel, double yVel, double zVel) throws Remo

@Override
public void enableFollowMe(FollowType followType) throws RemoteException {
final FollowAlgorithm.FollowModes selectedMode;
switch (followType) {
case ABOVE:
selectedMode = FollowAlgorithm.FollowModes.ABOVE;
break;

case LEAD:
selectedMode = FollowAlgorithm.FollowModes.LEAD;
break;

case LEASH:
selectedMode = FollowAlgorithm.FollowModes.LEASH;
break;

case CIRCLE:
selectedMode = FollowAlgorithm.FollowModes.CIRCLE;
break;

case LEFT:
selectedMode = FollowAlgorithm.FollowModes.LEFT;
break;

case RIGHT:
selectedMode = FollowAlgorithm.FollowModes.RIGHT;
break;

default:
selectedMode = null;
break;
}
final FollowAlgorithm.FollowModes selectedMode = followTypeToMode(followType);

if (selectedMode != null) {
final Follow followMe = this.droneMgr.getFollowMe();
Expand Down Expand Up @@ -907,6 +878,46 @@ public void onReceivedMavLinkMessage(MAVLinkMessage msg) {
}
}

private static FollowAlgorithm.FollowModes followTypeToMode(FollowType followType){
final FollowAlgorithm.FollowModes followMode;

switch (followType) {
case ABOVE:
followMode = FollowAlgorithm.FollowModes.ABOVE;
break;

case LEAD:
followMode = FollowAlgorithm.FollowModes.LEAD;
break;

default:
case LEASH:
followMode = FollowAlgorithm.FollowModes.LEASH;
break;

case CIRCLE:
followMode = FollowAlgorithm.FollowModes.CIRCLE;
break;

case LEFT:
followMode = FollowAlgorithm.FollowModes.LEFT;
break;

case RIGHT:
followMode = FollowAlgorithm.FollowModes.RIGHT;
break;

case SPLINE_LEASH:
followMode = FollowAlgorithm.FollowModes.SPLINE_LEASH;
break;

case SPLINE_ABOVE:
followMode = FollowAlgorithm.FollowModes.SPLINE_ABOVE;
break;
}
return followMode;
}

private static FollowType followModeToType(FollowAlgorithm.FollowModes followMode) {
final FollowType followType;

Expand Down Expand Up @@ -935,6 +946,14 @@ private static FollowType followModeToType(FollowAlgorithm.FollowModes followMod
case ABOVE:
followType = FollowType.ABOVE;
break;

case SPLINE_LEASH:
followType = FollowType.SPLINE_LEASH;
break;

case SPLINE_ABOVE:
followType = FollowType.SPLINE_ABOVE;
break;
}

return followType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.droidplanner.services.android.location;

import org.droidplanner.core.helpers.coordinates.Coord3D;
import org.droidplanner.core.helpers.units.Altitude;
import org.droidplanner.services.android.utils.GoogleApiClientManager;
import org.droidplanner.services.android.utils.GoogleApiClientManager.GoogleApiClientTask;
import org.droidplanner.core.gcs.location.Location.LocationFinder;
Expand Down Expand Up @@ -103,8 +105,9 @@ public void onLocationChanged(Location androidLocation) {
currentSpeed);

org.droidplanner.core.gcs.location.Location location = new org.droidplanner.core.gcs.location.Location(
new Coord2D(androidLocation.getLatitude(), androidLocation.getLongitude()),
androidLocation.getBearing(), androidLocation.getSpeed(), isLocationAccurate);
new Coord3D(androidLocation.getLatitude(), androidLocation.getLongitude(),
new Altitude(androidLocation.getAltitude())), androidLocation.getBearing(),
androidLocation.getSpeed(), isLocationAccurate, androidLocation.getTime());

mLastLocation = androidLocation;
receiver.onLocationChanged(location);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,84 @@
package org.droidplanner.core.MAVLink;

import org.droidplanner.core.model.Drone;

import com.MAVLink.Messages.ApmModes;
import com.MAVLink.common.msg_mission_item;
import com.MAVLink.common.msg_set_position_target_global_int;
import com.MAVLink.common.msg_set_mode;
import com.MAVLink.enums.MAV_CMD;
import com.MAVLink.enums.MAV_FRAME;

import org.droidplanner.core.model.Drone;

public class MavLinkModes {
public static void setGuidedMode(Drone drone, double latitude, double longitude, double d) {
msg_mission_item msg = new msg_mission_item();
msg.seq = 0;
msg.current = 2; // TODO use guided mode enum
msg.frame = MAV_FRAME.MAV_FRAME_GLOBAL;
msg.command = MAV_CMD.MAV_CMD_NAV_WAYPOINT; //
msg.param1 = 0; // TODO use correct parameter
msg.param2 = 0; // TODO use correct parameter
msg.param3 = 0; // TODO use correct parameter
msg.param4 = 0; // TODO use correct parameter
msg.x = (float) latitude;
msg.y = (float) longitude;
msg.z = (float) d;
msg.autocontinue = 1; // TODO use correct parameter
msg.target_system = drone.getSysid();
msg.target_component = drone.getCompid();
drone.getMavClient().sendMavPacket(msg.pack());
}

public static void sendGuidedVelocity(Drone drone, double xVel, double yVel, double zVel) {
msg_mission_item msg = new msg_mission_item();
msg.seq = 0;
msg.current = 2; // TODO use guided mode enum
msg.frame = MAV_FRAME.MAV_FRAME_GLOBAL;
msg.command = 91; // MAV_CMD_NAV_VELOCITY
msg.param1 = 0; // TODO use correct parameter
msg.param2 = 0; // TODO use correct parameter
msg.param3 = 0; // TODO use correct parameter
msg.param4 = 0; // TODO use correct parameter
msg.x = (float) (xVel );
msg.y = (float) (yVel);
msg.z = (float) (zVel);
msg.autocontinue = 1; // TODO use correct parameter
msg.target_system = drone.getSysid();
msg.target_component = drone.getCompid();
drone.getMavClient().sendMavPacket(msg.pack());
}

public static void changeFlightMode(Drone drone, ApmModes mode) {
msg_set_mode msg = new msg_set_mode();
msg.target_system = drone.getSysid();
msg.base_mode = 1; // TODO use meaningful constant
msg.custom_mode = mode.getNumber();
drone.getMavClient().sendMavPacket(msg.pack());
}

private static final int MAVLINK_SET_POS_TYPE_MASK_POS_IGNORE = ((1 << 0) | (1 << 1) | (1 << 2));
private static final int MAVLINK_SET_POS_TYPE_MASK_VEL_IGNORE = ((1 << 3) | (1 << 4) | (1 << 5));
private static final int MAVLINK_SET_POS_TYPE_MASK_ACC_IGNORE = ((1 << 6) | (1 << 7) | (1 << 8));

public static void setGuidedMode(Drone drone, double latitude, double longitude, double d) {
msg_mission_item msg = new msg_mission_item();
msg.seq = 0;
msg.current = 2; // TODO use guided mode enum
msg.frame = MAV_FRAME.MAV_FRAME_GLOBAL;
msg.command = MAV_CMD.MAV_CMD_NAV_WAYPOINT; //
msg.param1 = 0; // TODO use correct parameter
msg.param2 = 0; // TODO use correct parameter
msg.param3 = 0; // TODO use correct parameter
msg.param4 = 0; // TODO use correct parameter
msg.x = (float) latitude;
msg.y = (float) longitude;
msg.z = (float) d;
msg.autocontinue = 1; // TODO use correct parameter
msg.target_system = drone.getSysid();
msg.target_component = drone.getCompid();
drone.getMavClient().sendMavPacket(msg.pack());
}

public static void sendGuidedPosition(Drone drone, double latitude, double longitude, double altitude){
msg_set_position_target_global_int msg = new msg_set_position_target_global_int();
msg.type_mask = MAVLINK_SET_POS_TYPE_MASK_ACC_IGNORE | MAVLINK_SET_POS_TYPE_MASK_VEL_IGNORE;
msg.coordinate_frame = MAV_FRAME.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT;
msg.lat_int = (int) (latitude * 1E7);
msg.lon_int = (int) (longitude * 1E7);
msg.alt = (float) altitude;
msg.target_system = drone.getSysid();
msg.target_component = drone.getCompid();
drone.getMavClient().sendMavPacket(msg.pack());
}

public static void sendGuidedVelocity(Drone drone, double xVel, double yVel, double zVel){
msg_set_position_target_global_int msg = new msg_set_position_target_global_int();
msg.type_mask = MAVLINK_SET_POS_TYPE_MASK_ACC_IGNORE | MAVLINK_SET_POS_TYPE_MASK_POS_IGNORE;
msg.coordinate_frame = MAV_FRAME.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT;
msg.vx = (float) xVel;
msg.vy = (float) yVel;
msg.vz = (float) zVel;
msg.target_system = drone.getSysid();
msg.target_component = drone.getCompid();
drone.getMavClient().sendMavPacket(msg.pack());
}

public static void sendGuidedPositionAndVelocity(Drone drone, double latitude, double longitude, double altitude,
double xVel, double yVel, double zVel){
msg_set_position_target_global_int msg = new msg_set_position_target_global_int();
msg.type_mask = MAVLINK_SET_POS_TYPE_MASK_ACC_IGNORE;
msg.coordinate_frame = MAV_FRAME.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT;
msg.lat_int = (int) (latitude * 1E7);
msg.lon_int = (int) (longitude * 1E7);
msg.alt = (float) altitude;
msg.vx = (float) xVel;
msg.vy = (float) yVel;
msg.vz = (float) zVel;
msg.target_system = drone.getSysid();
msg.target_component = drone.getCompid();
drone.getMavClient().sendMavPacket(msg.pack());
}

public static void changeFlightMode(Drone drone, ApmModes mode) {
msg_set_mode msg = new msg_set_mode();
msg.target_system = drone.getSysid();
msg.base_mode = 1; // TODO use meaningful constant
msg.custom_mode = mode.getNumber();
drone.getMavClient().sendMavPacket(msg.pack());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.droidplanner.core.drone.DroneInterfaces.OnDroneListener;
import org.droidplanner.core.drone.DroneVariable;
import org.droidplanner.core.helpers.coordinates.Coord2D;
import org.droidplanner.core.helpers.coordinates.Coord3D;
import org.droidplanner.core.helpers.units.Altitude;
import org.droidplanner.core.model.Drone;

Expand Down Expand Up @@ -263,4 +264,9 @@ public void newGuidedVelocity( double xVel, double yVel, double zVel){
MavLinkModes.sendGuidedVelocity(myDrone,xVel,yVel,zVel);
}

public void newGuidedPositionAndVelocity(Coord2D coord3d, double xVel, double yVel, double zVel){
MavLinkModes.sendGuidedPositionAndVelocity(myDrone, coord3d.getLat(), coord3d.getLng(),
altitude.valueInMeters(), xVel, yVel, zVel);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public void changeRadius(Double radius) {
}

public enum FollowModes {
LEASH("Leash"), LEAD("Lead"), RIGHT("Right"), LEFT("Left"), CIRCLE("Orbit"), ABOVE("Above");
LEASH("Leash"), LEAD("Lead"), RIGHT("Right"), LEFT("Left"), CIRCLE("Orbit"), ABOVE("Above"),
SPLINE_LEASH("Spline Leash"), SPLINE_ABOVE("Spline Above");

private String name;

Expand Down Expand Up @@ -54,6 +55,10 @@ public FollowAlgorithm getAlgorithmType(Drone drone) {
return new FollowCircle(drone, new Length(15.0), 10.0);
case ABOVE:
return new FollowAbove(drone, new Length(0.0));
case SPLINE_LEASH:
return new FollowSplineLeash(drone, new Length(8.0));
case SPLINE_ABOVE:
return new FollowSplineAbove(drone, new Length(0.0));
}
return null; // Should never reach this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ public void processNewLocation(Location location) {

final double radiusInMeters = radius.valueInMeters();
if (GeoTools.getDistance(locationCoord, dronePosition).valueInMeters() > radiusInMeters) {
double headingGCStoDrone = GeoTools.getHeadingFromCoordinates(locationCoord,
dronePosition);
Coord2D goCoord = GeoTools.newCoordFromBearingAndDistance(locationCoord,
headingGCStoDrone, radiusInMeters);
double headingGCStoDrone = GeoTools.getHeadingFromCoordinates(locationCoord, dronePosition);
Coord2D goCoord = GeoTools.newCoordFromBearingAndDistance(locationCoord, headingGCStoDrone, radiusInMeters);
drone.getGuidedPoint().newGuidedCoord(goCoord);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.droidplanner.core.gcs.follow;

import org.droidplanner.core.gcs.location.Location;
import org.droidplanner.core.helpers.coordinates.Coord2D;
import org.droidplanner.core.helpers.units.Length;
import org.droidplanner.core.model.Drone;

/**
* Created by fhuya on 1/5/15.
*/
public class FollowSplineAbove extends FollowAlgorithm {
@Override
public void processNewLocation(Location location) {
Coord2D gcsLoc = new Coord2D(location.getCoord().getLat(), location.getCoord().getLng());
double speed = location.getSpeed();
double bearing = location.getBearing();
double bearingInRad = Math.toRadians(bearing);
double xVel = speed * Math.cos(bearingInRad);
double yVel = speed * Math.sin(bearingInRad);
drone.getGuidedPoint().newGuidedPositionAndVelocity(gcsLoc, xVel, yVel, 0);
}

@Override
public FollowModes getType() {
return FollowModes.SPLINE_ABOVE;
}

public FollowSplineAbove(Drone drone, Length length) {
super(drone, length);
}
}
Loading

0 comments on commit d129a0d

Please sign in to comment.