Skip to content

Commit 9a3bdac

Browse files
Merge branch 'master' into beta
2 parents b3dc733 + 7b58a0a commit 9a3bdac

File tree

5 files changed

+73
-37
lines changed

5 files changed

+73
-37
lines changed

Android/src/org/droidplanner/android/fragments/FlightActionsFragment.java

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.droidplanner.core.model.Drone;
1414

1515
import android.app.Activity;
16+
import android.graphics.Color;
1617
import android.os.Bundle;
1718
import android.support.v4.app.Fragment;
1819
import android.view.LayoutInflater;
@@ -156,6 +157,9 @@ public void onClick(View v) {
156157
break;
157158

158159
case R.id.mc_pause:
160+
if (followMe.isEnabled()) {
161+
followMe.toggleFollowMeState();
162+
}
159163
drone.getGuidedPoint().pauseAtCurrentLocation();
160164
eventBuilder.setAction("Changed flight mode").setLabel("Pause");
161165
break;
@@ -172,26 +176,30 @@ public void onClick(View v) {
172176
break;
173177

174178
case R.id.mc_follow:
175-
final int result = followMe.toggleFollowMeState();
179+
followMe.toggleFollowMeState();
176180
String eventLabel = null;
177-
switch (result) {
178-
case Follow.FOLLOW_START:
181+
switch (followMe.getState()) {
182+
case FOLLOW_START:
179183
eventLabel = "FollowMe enabled";
180184
break;
185+
186+
case FOLLOW_RUNNING:
187+
eventLabel = "FollowMe running";
188+
break;
181189

182-
case Follow.FOLLOW_END:
190+
case FOLLOW_END:
183191
eventLabel = "FollowMe disabled";
184192
break;
185193

186-
case Follow.FOLLOW_INVALID_STATE:
194+
case FOLLOW_INVALID_STATE:
187195
eventLabel = "FollowMe error: invalid state";
188196
break;
189197

190-
case Follow.FOLLOW_DRONE_DISCONNECTED:
198+
case FOLLOW_DRONE_DISCONNECTED:
191199
eventLabel = "FollowMe error: drone not connected";
192200
break;
193201

194-
case Follow.FOLLOW_DRONE_NOT_ARMED:
202+
case FOLLOW_DRONE_NOT_ARMED:
195203
eventLabel = "FollowMe error: drone not armed";
196204
break;
197205
}
@@ -249,6 +257,8 @@ public void onDroneEvent(DroneEventsType event, Drone drone) {
249257

250258
case FOLLOW_START:
251259
case FOLLOW_STOP:
260+
case FOLLOW_UPDATE:
261+
updateFlightModeButtons();
252262
updateFollowButton();
253263
break;
254264

@@ -267,7 +277,7 @@ private void updateFlightModeButtons() {
267277
break;
268278

269279
case ROTOR_GUIDED:
270-
if (drone.getGuidedPoint().isIdle()) {
280+
if (drone.getGuidedPoint().isIdle() && !followMe.isEnabled()) {
271281
pauseBtn.setActivated(true);
272282
}
273283
break;
@@ -292,7 +302,19 @@ private void resetFlightModeButtons() {
292302
}
293303

294304
private void updateFollowButton() {
295-
followBtn.setActivated(followMe.isEnabled());
305+
switch (followMe.getState()) {
306+
case FOLLOW_START:
307+
followBtn.setBackgroundColor(Color.RED);
308+
break;
309+
case FOLLOW_RUNNING:
310+
followBtn.setActivated(true);
311+
followBtn.setBackgroundResource(R.drawable.flight_action_row_bg_selector);
312+
break;
313+
default:
314+
followBtn.setActivated(false);
315+
followBtn.setBackgroundResource(R.drawable.flight_action_row_bg_selector);
316+
break;
317+
}
296318
}
297319

298320
private void resetButtonsContainerVisibility() {

Android/src/org/droidplanner/android/fragments/mode/FlightModePanel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public void onDroneEvent(DroneInterfaces.DroneEventsType event, Drone drone) {
8282
case DISCONNECTED:
8383
case MODE:
8484
case TYPE:
85+
case FOLLOW_START:
86+
case FOLLOW_STOP:
8587
// Update the mode info panel
8688
onModeUpdate(drone.getState().getMode());
8789
break;

Android/src/org/droidplanner/android/notifications/PebbleNotificationProvider.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,27 @@ public void receiveData(Context context, int transactionId, PebbleDictionary dat
150150
switch (request) {
151151

152152
case KEY_REQUEST_MODE_FOLLOW:
153-
final int result = followMe.toggleFollowMeState();
153+
followMe.toggleFollowMeState();
154154
String eventLabel = null;
155-
switch (result) {
156-
case Follow.FOLLOW_START:
155+
switch (followMe.getState()) {
156+
case FOLLOW_START:
157+
case FOLLOW_RUNNING:
157158
eventLabel = "FollowMe enabled";
158159
break;
159160

160-
case Follow.FOLLOW_END:
161+
case FOLLOW_END:
161162
eventLabel = "FollowMe disabled";
162163
break;
163164

164-
case Follow.FOLLOW_INVALID_STATE:
165+
case FOLLOW_INVALID_STATE:
165166
eventLabel = "FollowMe error: invalid state";
166167
break;
167168

168-
case Follow.FOLLOW_DRONE_DISCONNECTED:
169+
case FOLLOW_DRONE_DISCONNECTED:
169170
eventLabel = "FollowMe error: drone not connected";
170171
break;
171172

172-
case Follow.FOLLOW_DRONE_NOT_ARMED:
173+
case FOLLOW_DRONE_NOT_ARMED:
173174
eventLabel = "FollowMe error: drone not armed";
174175
break;
175176
}
@@ -184,8 +185,7 @@ public void receiveData(Context context, int transactionId, PebbleDictionary dat
184185
break;
185186

186187
case KEY_REQUEST_MODE_LOITER:
187-
((DroidPlannerApp) applicationContext).getDrone().getState()
188-
.changeFlightMode(ApmModes.ROTOR_LOITER);
188+
((DroidPlannerApp) applicationContext).getDrone().getGuidedPoint().pauseAtCurrentLocation();
189189
break;
190190

191191
case KEY_REQUEST_MODE_RTL:

Core/src/org/droidplanner/core/drone/DroneInterfaces.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ public enum DroneEventsType {
181181
* 'Follow' mode has been disabled.
182182
*/
183183
FOLLOW_STOP,
184+
185+
/**
186+
* 'Follow' state has been updated.
187+
*/
188+
FOLLOW_UPDATE,
184189

185190
/**
186191
*

Core/src/org/droidplanner/core/gcs/follow/Follow.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717

1818
public class Follow implements OnDroneListener, LocationReceiver {
1919

20-
// Set of return value for the 'toggleFollowMeState' method.
21-
public static final int FOLLOW_INVALID_STATE = -1;
22-
public static final int FOLLOW_DRONE_NOT_ARMED = -2;
23-
public static final int FOLLOW_DRONE_DISCONNECTED = -3;
24-
public static final int FOLLOW_START = 0;
25-
public static final int FOLLOW_END = 1;
26-
27-
private boolean followMeEnabled = false;
20+
/** Set of return value for the 'toggleFollowMeState' method.*/
21+
public enum FollowStates {
22+
FOLLOW_INVALID_STATE, FOLLOW_DRONE_NOT_ARMED, FOLLOW_DRONE_DISCONNECTED, FOLLOW_START, FOLLOW_RUNNING, FOLLOW_END,
23+
};
24+
25+
private FollowStates state = FollowStates.FOLLOW_INVALID_STATE;
2826
private Drone drone;
2927

3028
private ROIEstimator roiEstimator;
@@ -40,48 +38,49 @@ public Follow(Drone drone, Handler handler, LocationFinder locationFinder) {
4038
drone.addDroneListener(this);
4139
}
4240

43-
public int toggleFollowMeState() {
41+
public void toggleFollowMeState() {
4442
final State droneState = drone.getState();
4543
if (droneState == null) {
46-
return FOLLOW_INVALID_STATE;
44+
state = FollowStates.FOLLOW_INVALID_STATE;
45+
return;
4746
}
4847

4948
if (isEnabled()) {
5049
disableFollowMe();
51-
drone.getState().changeFlightMode(ApmModes.ROTOR_LOITER);
52-
return FOLLOW_END;
5350
} else {
5451
if (drone.getMavClient().isConnected()) {
5552
if (drone.getState().isArmed()) {
5653
drone.getState().changeFlightMode(ApmModes.ROTOR_GUIDED);
5754
enableFollowMe();
58-
return FOLLOW_START;
5955
} else {
60-
return FOLLOW_DRONE_NOT_ARMED;
56+
state = FollowStates.FOLLOW_DRONE_NOT_ARMED;
6157
}
6258
} else {
63-
return FOLLOW_DRONE_DISCONNECTED;
59+
state = FollowStates.FOLLOW_DRONE_DISCONNECTED;
60+
6461
}
6562
}
63+
return;
6664
}
6765

6866
private void enableFollowMe() {
6967
locationFinder.enableLocationUpdates();
70-
followMeEnabled = true;
68+
state = FollowStates.FOLLOW_START;
7169
drone.notifyDroneEvent(DroneEventsType.FOLLOW_START);
7270
}
7371

7472
private void disableFollowMe() {
7573
locationFinder.disableLocationUpdates();
76-
if (followMeEnabled) {
77-
followMeEnabled = false;
74+
if (isEnabled()) {
75+
state = FollowStates.FOLLOW_END;
7876
MavLinkROI.resetROI(drone);
77+
drone.getGuidedPoint().pauseAtCurrentLocation();
7978
drone.notifyDroneEvent(DroneEventsType.FOLLOW_STOP);
8079
}
8180
}
8281

8382
public boolean isEnabled() {
84-
return followMeEnabled;
83+
return state == FollowStates.FOLLOW_RUNNING || state == FollowStates.FOLLOW_START;
8584
}
8685

8786
@Override
@@ -106,8 +105,12 @@ public Length getRadius() {
106105
@Override
107106
public void onLocationChanged(Location location) {
108107
if (location.getAccuracy() < 10.0) {
108+
state = FollowStates.FOLLOW_RUNNING;
109109
followAlgorithm.processNewLocation(location);
110+
}else{
111+
state = FollowStates.FOLLOW_START;
110112
}
113+
drone.notifyDroneEvent(DroneEventsType.FOLLOW_UPDATE);
111114
roiEstimator.onLocationChanged(location);
112115
}
113116

@@ -127,4 +130,8 @@ public void cycleType() {
127130
public FollowModes getType() {
128131
return followAlgorithm.getType();
129132
}
133+
134+
public FollowStates getState() {
135+
return state;
136+
}
130137
}

0 commit comments

Comments
 (0)