mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
AndroidGCS: Joystick can now control UAV
This commit is contained in:
parent
bd280f6fec
commit
fc18dac90b
@ -23,7 +23,7 @@
|
||||
|
||||
<activity android:name="ObjectBrowser" android:label="@string/object_browser_name" />
|
||||
<activity android:name="PFD" android:label="PFD" />
|
||||
<activity android:name="Controller" android:label="@string/object_browser_name" />
|
||||
<activity android:name="Controller" android:label="@string/controller_name" />
|
||||
<activity android:name="Preferences" android:label="@string/preference_title" />
|
||||
<activity android:name="UAVLocation" android:label="@string/location_name"/>
|
||||
<activity android:name="ObjectEditor" android:label="ObjectEditor"
|
||||
|
@ -2,6 +2,7 @@
|
||||
<resources>
|
||||
<string name="app_name">OpenPilot GCS Home</string>
|
||||
<string name="object_browser_name">Browser</string>
|
||||
<string name="controller_name">Controller</string>
|
||||
<string name="pfd_name">PFD</string>
|
||||
<string name="location_name">Map</string>
|
||||
<string name="logger_name">Logging</string>
|
||||
@ -25,6 +26,5 @@
|
||||
<string name="update_button">Update</string>
|
||||
<string name="save_button">Save</string>
|
||||
<string name="send_button">Send</string>
|
||||
<string name="controller_name">Controller</string>
|
||||
<string name="manual_control_values_">Manual control values:</string>
|
||||
</resources>
|
||||
|
@ -11,6 +11,7 @@ import org.openpilot.uavtalk.UAVObjectField;
|
||||
|
||||
import com.MobileAnarchy.Android.Widgets.Joystick.DualJoystickView;
|
||||
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener;
|
||||
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickView;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -50,6 +51,18 @@ public class Controller extends ObjectManagerActivity {
|
||||
manualView.setText("Hello");
|
||||
}
|
||||
|
||||
Observer settingsUpdated = new Observer() {
|
||||
@Override
|
||||
public void update(Observable observable, Object data) {
|
||||
// Once we have updated settings we can active the GCS receiver mode
|
||||
Log.d(TAG,"Got update from settings");
|
||||
activateGcsReceiver();
|
||||
UAVDataObject manualControlSettings = (UAVDataObject) objMngr.getObject("ManualControlSettings");
|
||||
if(manualControlSettings != null) {
|
||||
manualControlSettings.removeUpdatedObserver(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
void onOPConnected() {
|
||||
@ -60,16 +73,25 @@ public class Controller extends ObjectManagerActivity {
|
||||
if(manualControl != null) {
|
||||
manualControl.addUpdatedObserver(updatedObserver);
|
||||
}
|
||||
|
||||
activateGcsReceiver();
|
||||
|
||||
DualJoystickView joystick = (DualJoystickView) findViewById(R.id.dualjoystickView);
|
||||
|
||||
|
||||
UAVDataObject manualControlSettings = (UAVDataObject) objMngr.getObject("ManualControlSettings");
|
||||
if(manualControlSettings != null) {
|
||||
Log.d(TAG, "Requested settings update");
|
||||
manualControlSettings.addUpdatedObserver(updatedObserver);
|
||||
manualControlSettings.updateRequested();
|
||||
}
|
||||
|
||||
final double MOVEMENT_RANGE = 50.0;
|
||||
DualJoystickView joystick = (DualJoystickView) findViewById(R.id.dualjoystickView);
|
||||
joystick.setMovementConstraint(JoystickView.CONSTRAIN_BOX);
|
||||
joystick.setMovementRange((int)MOVEMENT_RANGE, (int)MOVEMENT_RANGE);
|
||||
|
||||
// Hardcode a Mode 1 listener for now
|
||||
joystick.setOnJostickMovedListener(new JoystickMovedListener() {
|
||||
public void OnMoved(int pan, int tilt) {
|
||||
pitch = -(double) tilt / 10.0;
|
||||
yaw = (double) pan / 10.0;
|
||||
pitch = (double) tilt / MOVEMENT_RANGE;
|
||||
yaw = (double) pan / MOVEMENT_RANGE;
|
||||
updated = true;
|
||||
leftJoystickHeld = true;
|
||||
}
|
||||
@ -78,8 +100,11 @@ public class Controller extends ObjectManagerActivity {
|
||||
public void OnReturnedToCenter() { }
|
||||
}, new JoystickMovedListener() {
|
||||
public void OnMoved(int pan, int tilt) {
|
||||
throttle = (double) (tilt + 10) / 20.0;
|
||||
roll = (double) pan / 10.0;
|
||||
throttle = (double) (-tilt + (MOVEMENT_RANGE -5)) / (MOVEMENT_RANGE - 5);
|
||||
throttle *= 0.5;
|
||||
if (throttle < 0)
|
||||
throttle = -1;
|
||||
roll = (double) pan / MOVEMENT_RANGE;
|
||||
updated = true;
|
||||
rightJoystickHeld = true;
|
||||
}
|
||||
@ -120,7 +145,7 @@ public class Controller extends ObjectManagerActivity {
|
||||
});
|
||||
}
|
||||
};
|
||||
sendTimer.schedule(controllerTask, 500, 50);
|
||||
sendTimer.schedule(controllerTask, 500, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,6 +180,7 @@ public class Controller extends ObjectManagerActivity {
|
||||
*/
|
||||
private void activateGcsReceiver() {
|
||||
UAVObject manualControlSettings = objMngr.getObject("ManualControlSettings");
|
||||
|
||||
if (manualControlSettings == null) {
|
||||
Toast.makeText(this, "Failed to get manual control settings", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
|
@ -159,7 +159,7 @@ public class TelemetryMonitor extends Observable{
|
||||
// objPending = null;
|
||||
|
||||
if(!success) {
|
||||
Log.e(TAG, "Transaction failed: " + obj.getName() + " sending again.");
|
||||
//Log.e(TAG, "Transaction failed: " + obj.getName() + " sending again.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user