Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AndySpyBot and HelloAndy examples
- Loading branch information
Showing
23 changed files
with
331 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package=""> | ||
<uses-sdk android:minSdkVersion="10"/> | ||
<application android:debuggable="true" android:icon="@drawable/icon" android:label=""> | ||
<activity android:name=""> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> | ||
<uses-permission android:name="android.permission.CAMERA"/> | ||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import java.io.ByteArrayOutputStream; | ||
import java.net.DatagramPacket; | ||
import java.net.DatagramSocket; | ||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.List; | ||
import android.os.AsyncTask; | ||
|
||
class ImageBroadCaster extends AsyncTask { | ||
private static final int PREVIEW_PORT = 9020; | ||
|
||
public final static int HEADER_SIZE = 5; | ||
public final static int DATAGRAM_MAX_SIZE = 1450 - HEADER_SIZE; | ||
int frame_nb = 0; | ||
public InetAddress ipAddress; | ||
|
||
Bitmap mBitmap; | ||
int width_ima, height_ima; | ||
|
||
private DatagramSocket socket; | ||
|
||
public ImageBroadCaster() { | ||
try { | ||
this.socket = new DatagramSocket(); | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private final void sendUDP(PImage image, String _ipAddress) { | ||
try { | ||
ipAddress = InetAddress.getByName(_ipAddress); | ||
} | ||
catch (UnknownHostException e) | ||
{ | ||
println("Invalid host"); | ||
e.printStackTrace(); | ||
} | ||
mBitmap = (Bitmap) image.getNative(); | ||
if (mBitmap != null) { | ||
int size_p = 0, i; | ||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); | ||
|
||
// change compression rate to change packet size | ||
mBitmap.compress(Bitmap.CompressFormat.JPEG, 50, byteStream); | ||
|
||
byte data[] = byteStream.toByteArray(); | ||
|
||
int nb_packets = (int) Math.ceil(data.length | ||
/ (float) DATAGRAM_MAX_SIZE); | ||
int size = DATAGRAM_MAX_SIZE; | ||
|
||
/* Loop through slices */ | ||
for (i = 0; i < nb_packets; i++) { | ||
if (i > 0 && i == nb_packets - 1) | ||
size = data.length - i * DATAGRAM_MAX_SIZE; | ||
|
||
/* Set additional header */ | ||
byte[] data2 = new byte[HEADER_SIZE + size]; | ||
data2[0] = (byte) frame_nb; | ||
data2[1] = (byte) nb_packets; | ||
data2[2] = (byte) i; | ||
data2[3] = (byte) (size >> 8); | ||
data2[4] = (byte) size; | ||
|
||
/* Copy current slice to byte array */ | ||
System.arraycopy(data, i * DATAGRAM_MAX_SIZE, data2, | ||
HEADER_SIZE, size); | ||
|
||
try { | ||
size_p = data2.length; | ||
DatagramPacket packet = new DatagramPacket(data2, size_p, ipAddress, PREVIEW_PORT); | ||
socket.send(packet); | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
frame_nb++; | ||
|
||
if (frame_nb == 128) | ||
frame_nb = 0; | ||
} | ||
} | ||
|
||
@Override | ||
protected Object doInBackground(Object... arg0) { | ||
sendUDP((PImage) arg0[0], (String) arg0[1]); | ||
return null; | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Updated: 2013-03-17 | ||
* Ankit Daftery | ||
* @ankitdaf | ||
*/ | ||
|
||
import ketai.camera.*; | ||
import ketai.net.*; | ||
import android.graphics.Bitmap; | ||
import com.andyrobo.ui.*; | ||
|
||
KetaiText kt; | ||
KetaiCamera cam; | ||
KetaiButton ok; | ||
|
||
boolean isSpyModeOn=false; | ||
|
||
void setup() { | ||
orientation(PORTRAIT); | ||
imageMode(CORNER); | ||
cam = new KetaiCamera(this, 500, 500, 24); | ||
kt = new KetaiText(this,"ip",KetaiNet.getIP()); | ||
kt.setPosition(width/4,600); | ||
ok = new KetaiButton(this,"ipb","SpyMode Off"); | ||
ok.setPosition(width*3/4,600); | ||
cam.start(); | ||
} | ||
|
||
void draw() { | ||
image(cam, width/4, 0); | ||
} | ||
|
||
void ipClicked() { | ||
println("IP clicked"); | ||
kt.updateText("IP Address","Please Enter a New IP"); | ||
} | ||
|
||
void ipbClicked() { | ||
isSpyModeOn = !isSpyModeOn; | ||
if(isSpyModeOn)ok.setText("SpyMode On"); | ||
else ok.setText("SpyMode Off"); | ||
} | ||
|
||
void onPause() | ||
{ | ||
super.onPause(); | ||
//Make sure to releae the camera when we go | ||
// to sleep otherwise it stays locked | ||
if (cam != null && cam.isStarted()) | ||
cam.stop(); | ||
} | ||
|
||
void onCameraPreviewEvent() | ||
{ | ||
cam.read(); | ||
if(isSpyModeOn) | ||
{ | ||
new ImageBroadCaster().execute(cam, kt.getText()); | ||
} | ||
} | ||
|
||
void exit() { | ||
cam.stop(); | ||
} | ||
|
||
// start/stop camera preview by tapping the screen | ||
void mousePressed() | ||
{ | ||
if (cam.isStarted()) | ||
{ | ||
cam.stop(); | ||
} | ||
else | ||
cam.start(); | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mode.id=processing.mode.android.AndroidMode | ||
mode=Android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="" | ||
android:versionCode="1" | ||
android:versionName="1.0"> | ||
<uses-sdk android:minSdkVersion="10" /> | ||
<application android:label="" | ||
android:icon="@drawable/icon" | ||
android:debuggable="true"> | ||
<activity android:name=""> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Updated: 2013-03-17 | ||
* Ankit Daftery | ||
* @ankitdaf | ||
*/ | ||
|
||
void showFace(String whichFace) { | ||
PImage img; | ||
img = loadImage(whichFace+".jpg"); | ||
image(img,0,0,width,height); | ||
} | ||
|
||
void getFlingDirection(float velocityX,float velocityY) { | ||
int velX = normalizeVelocity(velocityX, displayWidth); | ||
int velY = normalizeVelocity(velocityY, displayHeight); | ||
|
||
double a = Math.atan2(velX, velY); | ||
a = snapAngle(Math.toDegrees(a)); | ||
println("a "+a); | ||
|
||
final double angle = Math.toRadians(a); | ||
int[] ws = c.getWheelSpeeds(255,angle); | ||
c.andyMove(ws[0],ws[1]); | ||
//c.andyStopAfter(1000); | ||
} | ||
|
||
int normalizeVelocity(float velocity,int maxValue) { | ||
int v = (int) (velocity / maxValue); | ||
v = (250 * v) / 6; | ||
return v; | ||
} | ||
|
||
double snapAngle(double d) { | ||
if (d < -155) { | ||
return -180; | ||
} | ||
|
||
if (d < -115) { | ||
return -135; | ||
} | ||
|
||
if (d < -70) { | ||
return -90; | ||
} | ||
|
||
if (d < -20) { | ||
return -45; | ||
} | ||
|
||
if (d > 155) { | ||
return 180; | ||
} | ||
|
||
if (d > 115) { | ||
return 135; | ||
} | ||
|
||
if (d > 70) { | ||
return 90; | ||
} | ||
|
||
if (d > 20) { | ||
return 45; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Updated: 2013-03-17 | ||
* Ankit Daftery | ||
* @ankitdaf | ||
*/ | ||
|
||
import ketai.ui.*; | ||
import android.view.MotionEvent; | ||
import com.andyrobo.*; | ||
import com.andyrobo.motor.*; | ||
import com.andyrobo.audio.*; | ||
|
||
AndyMotorController c; | ||
AndyGesture gesture; | ||
|
||
int count=0; | ||
void setup() { | ||
orientation(PORTRAIT); | ||
gesture = new AndyGesture(this); | ||
showFace("smile"); | ||
c = new AndyMotorController(this); | ||
c.begin(); | ||
} | ||
|
||
void draw() { | ||
} | ||
|
||
|
||
public boolean surfaceTouchEvent(MotionEvent event) { | ||
|
||
//call to keep mouseX, mouseY, etc updated | ||
super.surfaceTouchEvent(event); | ||
//forward event to class for processing | ||
return gesture.surfaceTouchEvent(event); | ||
} | ||
|
||
void onFling(float x,float y,float px,float py,float vx,float vy) { | ||
getFlingDirection(vx,vy); | ||
if(count==0) showFace("confused"); | ||
else if (count==1) showFace("laugh"); | ||
else if (count==2) showFace("smile"); | ||
else if (count==3) showFace("scared"); | ||
else if (count==4) showFace("angry"); | ||
count=count+1; | ||
if(count==5) count=0; | ||
} | ||
|
||
void onPause() { | ||
c.finish(); | ||
super.onPause(); | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mode.id=processing.mode.android.AndroidMode | ||
mode=Android |
Oops, something went wrong.