Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto mission assistant #1538

Merged
merged 8 commits into from
Jul 31, 2015
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {
compile 'com.google.android.gms:play-services-analytics:7.5.0'

compile 'com.sothree.slidinguppanel:library:2.0.2'
compile 'com.github.traex.rippleeffect:library:1.3'

compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
Expand All @@ -15,8 +16,8 @@ dependencies {
compile 'com.android.support:design:22.2.1'

//DroneKit-Android client library.
compile 'com.o3dr.android:dronekit-android:2.5.4'

// compile 'com.o3dr.android:dronekit-android:2.5.6'
compile (name: 'dronekit-android.2.5.7', ext:'aar')
compile 'me.grantland:autofittextview:0.2.1'
compile(name:'shimmer-android-release', ext:'aar')

Expand Down
Binary file added Android/res/drawable-hdpi/ic_pause_white_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Android/res/drawable-hdpi/ic_replay_white_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Android/res/drawable-mdpi/ic_pause_white_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Android/res/drawable-mdpi/ic_replay_white_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Android/res/drawable-xhdpi/ic_pause_white_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Android/res/drawable-xhdpi/ic_replay_white_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Android/res/drawable-xxhdpi/ic_pause_white_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Android/res/drawable-xxhdpi/ic_replay_white_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 88 additions & 6 deletions Android/res/layout/fragment_mode_auto.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ModeDetail"
style="@style/ModeDetailText"
android:background="@drawable/mode_desc_rectangle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mode_auto"/>
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">

<TextView
android:id="@+id/ModeDetail"
style="@style/ModeDetailText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/mode_desc_rectangle"
android:text="@string/mode_auto" />

<ProgressBar
android:id="@+id/mission_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginBottom="10dp"
android:animationResolution="@android:integer/config_shortAnimTime"
android:indeterminate="false"
android:max="100"
android:progress="0"
android:progressBackgroundTint="@android:color/holo_blue_dark"
android:progressTint="@android:color/holo_blue_dark" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_margin="5dp"
android:background="@drawable/button_blue"
android:gravity="center"
android:orientation="horizontal">

<com.andexert.library.RippleView
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TShapinsky the LinearLayout children should have the layout_weight attribute so they can stretch to fill out all the space within their parent is necessary.

android:layout_width="80dp"
android:layout_height="match_parent">

<ImageView
android:id="@+id/mc_prev"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:scaleType="fitCenter"
android:src="@drawable/ic_skip_previous_white_24dp" />
</com.andexert.library.RippleView>

<com.andexert.library.RippleView
android:layout_width="80dp"
android:layout_height="match_parent">

<ImageView
android:id="@+id/mc_pause"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:scaleType="fitCenter"
android:src="@drawable/ic_pause_white_24dp" />
</com.andexert.library.RippleView>

<com.andexert.library.RippleView
android:layout_width="80dp"
android:layout_height="match_parent">

<ImageView
android:id="@+id/mc_restart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:scaleType="fitCenter"
android:src="@drawable/ic_replay_white_24dp" />
</com.andexert.library.RippleView>

<com.andexert.library.RippleView
android:layout_width="80dp"
android:layout_height="match_parent">

<ImageView
android:id="@+id/mc_next"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:scaleType="fitCenter"
android:src="@drawable/ic_skip_next_white_24dp" />
</com.andexert.library.RippleView>
</LinearLayout>

</LinearLayout>

5 changes: 5 additions & 0 deletions Android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@
<string name="label_type_plane">Plane</string>
<string name="label_type_rover">Rover</string>
<string name="label_type_unknown">Unknown</string>
<string name="mode_auto_current_command">Current command:</string>
<string name="mode_auto_estimated_finish">Estimated to finish:</string>
<string name="mission_control_label">Mission control:</string>
<string name="wp_speed">WP Speed:</string>
<string name="mission_progress">Mission progress:</string>
<string name="imu_calibration_start_error">Unable to start imu calibration</string>
<string name="horizontal_speed_empty">hs: —</string>
<string name="horizontal_speed_telem">hs: %s</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,169 @@
package org.droidplanner.android.fragments.mode;

import org.droidplanner.android.R;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.LocalBroadcastManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;

import com.o3dr.android.client.Drone;
import com.o3dr.android.client.apis.MissionApi;
import com.o3dr.android.client.apis.VehicleApi;
import com.o3dr.services.android.lib.drone.attribute.AttributeEvent;
import com.o3dr.services.android.lib.drone.attribute.AttributeEventExtra;
import com.o3dr.services.android.lib.drone.attribute.AttributeType;
import com.o3dr.services.android.lib.drone.mission.Mission;
import com.o3dr.services.android.lib.drone.property.VehicleMode;
import com.o3dr.services.android.lib.model.AbstractCommandListener;

import org.droidplanner.android.DroidPlannerApp;
import org.droidplanner.android.R;
import org.droidplanner.android.proxy.mission.MissionProxy;

public class ModeAutoFragment extends Fragment implements View.OnClickListener{
public static final String WPNAV_SPEED = "WPNAV_SPEED";
private Drone drone;

private static final IntentFilter eventFilter = new IntentFilter();
static{
eventFilter.addAction(AttributeEvent.MISSION_ITEM_UPDATED);
eventFilter.addAction(AttributeEvent.PARAMETER_RECEIVED);
eventFilter.addAction(AttributeEvent.GPS_POSITION);
}
private final BroadcastReceiver eventReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
switch (action){
case AttributeEvent.MISSION_ITEM_UPDATED:
mission = drone.getAttribute(AttributeType.MISSION);
int currentMissionItem = intent.getIntExtra(AttributeEventExtra.EXTRA_MISSION_CURRENT_MISSION_ITEM, 0);
nextWaypoint = intent.getIntExtra(AttributeEventExtra.EXTRA_MISSION_CURRENT_WAYPOINT, 0);
mission.setCurrentMissionItem(currentMissionItem);
break;
case AttributeEvent.GPS_POSITION:
remainingMissionLength = intent.getDoubleExtra(AttributeEventExtra.EXTRA_MISSION_REMAINING_DISTANCE, 0);
updateMission();
break;
}
}
};
private Mission mission;
private int nextWaypoint;
private ProgressBar missionProgress;
private double remainingMissionLength;
private boolean missionFinished;

public class ModeAutoFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_mode_auto, container, false);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.findViewById(R.id.mc_pause).setOnClickListener(this);
view.findViewById(R.id.mc_restart).setOnClickListener(this);
view.findViewById(R.id.mc_next).setOnClickListener(this);
view.findViewById(R.id.mc_prev).setOnClickListener(this);
missionProgress = (ProgressBar) view.findViewById(R.id.mission_progress);
}

@Override
public void onClick(View v) {
if(mission == null){
mission = drone.getAttribute(AttributeType.MISSION);
}
switch(v.getId()){
case R.id.mc_pause: {
drone.pauseAtCurrentLocation();
break;
}
case R.id.mc_restart: {
gotoMissionItem(0);
break;
}
case R.id.mc_next: {
gotoMissionItem(mission.getCurrentMissionItem() + 1);
break;
}
case R.id.mc_prev: {
gotoMissionItem(mission.getCurrentMissionItem() - 1);
break;
}
}
}

@Override
public void onStart() {
super.onStart();
LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(eventReceiver, eventFilter);
}

@Override
public void onStop() {
super.onStop();
LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).unregisterReceiver(eventReceiver);
}

private void gotoMissionItem(final int waypoint){
if(missionFinished || waypoint == 0){
VehicleApi.getApi(drone).setVehicleMode(VehicleMode.COPTER_BRAKE, new AbstractCommandListener() {
@Override
public void onSuccess() {
MissionApi.getApi(drone).startMission(true, true, new AbstractCommandListener() {
@Override
public void onSuccess() {
MissionApi.getApi(drone).gotoMissionItem(waypoint,null);
}

@Override
public void onError(int i) {

}

@Override
public void onTimeout() {

}
});
missionFinished = false;
}

@Override
public void onError(int i) {}

@Override
public void onTimeout() {}
});
}else{
MissionApi.getApi(drone).gotoMissionItem(waypoint,null);
}
}



private void updateMission(){
if(mission == null)
return;
MissionProxy proxy= ((DroidPlannerApp)getActivity().getApplication()).getMissionProxy();
double totalLength = proxy.getMissionLength();
missionProgress.setMax((int) totalLength);
missionProgress.setProgress((int) ((totalLength - remainingMissionLength)));
missionFinished = remainingMissionLength < 5;
}

@Override
public void onAttach(Activity activity) {
drone = ((DroidPlannerApp)activity.getApplication()).getDrone();
super.onAttach(activity);
}
}