Skip to content
Browse files

added experimental (probably broken) control for the mindstorm shotbot

  • Loading branch information...
1 parent b29fc52 commit 6168ba6c65008d838fc3d669daa30f1036053078 @chrisii committed May 23, 2012
View
BIN res/drawable-hdpi/text_welcome_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
14 src/fhnw/emoba/ControlView.java
@@ -137,7 +137,7 @@ private void doDraw(Canvas canvas){
}
/** Handle to the application context, used to e.g. fetch drawables. */
- private Context mContext;
+ private MADStromActivity mContext;
/** The thread that actually draws the animation */
private ControlThread mThread;
@@ -162,7 +162,7 @@ public ControlView(Context context, AttributeSet attrs) {
// register our interest in hearing about changes to our surface
SurfaceHolder holder = getHolder();
holder.addCallback(this);
- mContext = context;
+ mContext = (MADStromActivity) context;
}
@Override
@@ -257,7 +257,7 @@ public void surfaceDestroyed(SurfaceHolder holder) {
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
- // TODO Auto-generated method stub
+ // TODO Maybe necessary to increase the resolution
}
@@ -269,7 +269,13 @@ public void onSensorChanged(SensorEvent event) {
//calculate new coordinates of controlpoint
if (mThread!=null){
mThread.mControlPoint.setX(mCanvasWidth/2 - (mCanvasWidth/20)*azimut);
- mThread.mControlPoint.setY(mCanvasHeight/2 + (mCanvasHeight/20)*pitch);
+ mThread.mControlPoint.setY(mCanvasHeight/2 + (mCanvasHeight/20)*pitch);
+ //Calculate new Velocity
+ Log.v(MADStromActivity.TAG, "CAW: " + Integer.toString(mCanvasWidth)+" "+"X: "+Float.toString(mThread.mControlPoint.getX()));
+ Log.v(MADStromActivity.TAG, "CAH: " + Integer.toString(mCanvasHeight)+" "+"Y: "+Float.toString(mThread.mControlPoint.getY()));
+ double velX = mThread.mControlPoint.getX()/mCanvasWidth;
+ double velY = mThread.mControlPoint.getY()/mCanvasHeight;
+ mContext.setVelocity(velX,velY);
}
}
View
29 src/fhnw/emoba/MADStromActivity.java
@@ -143,7 +143,7 @@ private View buildControlViewLayout(){
LinearLayout controlViewLayout = new LinearLayout(this);
controlViewLayout.setOrientation(LinearLayout.VERTICAL);
//adding the SurfaceView to the controlViewLayout
- mControlView = new ControlView(getApplicationContext(), null);
+ mControlView = new ControlView(this, null);
LinearLayout.LayoutParams ControlViewParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT, 1.0F);
@@ -158,6 +158,10 @@ private View buildControlViewLayout(){
public void onClick(View v) {
// TODO: Real Implementation
Toast.makeText(MADStromActivity.this, "Action", Toast.LENGTH_SHORT).show();
+ //emits action on Robot;
+ if (mRobot!=null){
+ mRobot.action(true);
+ }
}
});
LinearLayout.LayoutParams actionButtonParams = new LinearLayout.LayoutParams(
@@ -185,6 +189,10 @@ protected void onStop() {
Log.v(TAG, "Turning off bluetooth");
mBluetoothAdapter.disable();
}
+ //stops the robot incase the application gets killed
+ if (mRobot!=null && !mRobot.isEmergencyStop()){
+ mRobot.emergencyStop(true);
+ }
}
@@ -285,6 +293,7 @@ public void handleLegoBrickMessage(Message message) {
case BluetoothChannel.STATE_CONNECTERROR:
Log.v(TAG, "Lost connection to robot");
displayToast("Connection error occurred");
+ mRobot = null;
//no call to pause() is necessary anymore
//this.switchToConnectView();
break;
@@ -338,4 +347,22 @@ public void run() {
});
}
+ public void setVelocity(double velX, double velY){
+ if (mRobot!=null){
+ mRobot.setVelocity(velX, velY);
+ }
+ }
+
+ public void turn(int degree){
+ if (mRobot!=null){
+ mRobot.turn(degree);
+ }
+ }
+
+ public void setEmergencyStop(){
+ if (mRobot!=null){
+ mRobot.emergencyStop(true);
+ }
+ }
+
}

0 comments on commit 6168ba6

Please sign in to comment.
Something went wrong with that request. Please try again.