mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-21 11:54:15 +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="ObjectBrowser" android:label="@string/object_browser_name" />
|
||||||
<activity android:name="PFD" android:label="PFD" />
|
<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="Preferences" android:label="@string/preference_title" />
|
||||||
<activity android:name="UAVLocation" android:label="@string/location_name"/>
|
<activity android:name="UAVLocation" android:label="@string/location_name"/>
|
||||||
<activity android:name="ObjectEditor" android:label="ObjectEditor"
|
<activity android:name="ObjectEditor" android:label="ObjectEditor"
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">OpenPilot GCS Home</string>
|
<string name="app_name">OpenPilot GCS Home</string>
|
||||||
<string name="object_browser_name">Browser</string>
|
<string name="object_browser_name">Browser</string>
|
||||||
|
<string name="controller_name">Controller</string>
|
||||||
<string name="pfd_name">PFD</string>
|
<string name="pfd_name">PFD</string>
|
||||||
<string name="location_name">Map</string>
|
<string name="location_name">Map</string>
|
||||||
<string name="logger_name">Logging</string>
|
<string name="logger_name">Logging</string>
|
||||||
@ -25,6 +26,5 @@
|
|||||||
<string name="update_button">Update</string>
|
<string name="update_button">Update</string>
|
||||||
<string name="save_button">Save</string>
|
<string name="save_button">Save</string>
|
||||||
<string name="send_button">Send</string>
|
<string name="send_button">Send</string>
|
||||||
<string name="controller_name">Controller</string>
|
|
||||||
<string name="manual_control_values_">Manual control values:</string>
|
<string name="manual_control_values_">Manual control values:</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -11,6 +11,7 @@ import org.openpilot.uavtalk.UAVObjectField;
|
|||||||
|
|
||||||
import com.MobileAnarchy.Android.Widgets.Joystick.DualJoystickView;
|
import com.MobileAnarchy.Android.Widgets.Joystick.DualJoystickView;
|
||||||
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener;
|
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickMovedListener;
|
||||||
|
import com.MobileAnarchy.Android.Widgets.Joystick.JoystickView;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -50,6 +51,18 @@ public class Controller extends ObjectManagerActivity {
|
|||||||
manualView.setText("Hello");
|
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
|
@Override
|
||||||
void onOPConnected() {
|
void onOPConnected() {
|
||||||
@ -60,16 +73,25 @@ public class Controller extends ObjectManagerActivity {
|
|||||||
if(manualControl != null) {
|
if(manualControl != null) {
|
||||||
manualControl.addUpdatedObserver(updatedObserver);
|
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
|
// Hardcode a Mode 1 listener for now
|
||||||
joystick.setOnJostickMovedListener(new JoystickMovedListener() {
|
joystick.setOnJostickMovedListener(new JoystickMovedListener() {
|
||||||
public void OnMoved(int pan, int tilt) {
|
public void OnMoved(int pan, int tilt) {
|
||||||
pitch = -(double) tilt / 10.0;
|
pitch = (double) tilt / MOVEMENT_RANGE;
|
||||||
yaw = (double) pan / 10.0;
|
yaw = (double) pan / MOVEMENT_RANGE;
|
||||||
updated = true;
|
updated = true;
|
||||||
leftJoystickHeld = true;
|
leftJoystickHeld = true;
|
||||||
}
|
}
|
||||||
@ -78,8 +100,11 @@ public class Controller extends ObjectManagerActivity {
|
|||||||
public void OnReturnedToCenter() { }
|
public void OnReturnedToCenter() { }
|
||||||
}, new JoystickMovedListener() {
|
}, new JoystickMovedListener() {
|
||||||
public void OnMoved(int pan, int tilt) {
|
public void OnMoved(int pan, int tilt) {
|
||||||
throttle = (double) (tilt + 10) / 20.0;
|
throttle = (double) (-tilt + (MOVEMENT_RANGE -5)) / (MOVEMENT_RANGE - 5);
|
||||||
roll = (double) pan / 10.0;
|
throttle *= 0.5;
|
||||||
|
if (throttle < 0)
|
||||||
|
throttle = -1;
|
||||||
|
roll = (double) pan / MOVEMENT_RANGE;
|
||||||
updated = true;
|
updated = true;
|
||||||
rightJoystickHeld = 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() {
|
private void activateGcsReceiver() {
|
||||||
UAVObject manualControlSettings = objMngr.getObject("ManualControlSettings");
|
UAVObject manualControlSettings = objMngr.getObject("ManualControlSettings");
|
||||||
|
|
||||||
if (manualControlSettings == null) {
|
if (manualControlSettings == null) {
|
||||||
Toast.makeText(this, "Failed to get manual control settings", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Failed to get manual control settings", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
|
@ -159,7 +159,7 @@ public class TelemetryMonitor extends Observable{
|
|||||||
// objPending = null;
|
// objPending = null;
|
||||||
|
|
||||||
if(!success) {
|
if(!success) {
|
||||||
Log.e(TAG, "Transaction failed: " + obj.getName() + " sending again.");
|
//Log.e(TAG, "Transaction failed: " + obj.getName() + " sending again.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user