Commit 02459dae authored by Lukas Aukenthaler's avatar Lukas Aukenthaler
Browse files

some docs

parent d63623dd
Pipeline #11693 skipped
......@@ -186,4 +186,5 @@ public class BallCatchingActivity extends Activity implements CvCameraViewListen
lowestPointGround = HomographyActivity.convertPoint(MainActivity.mHomo, lowestPoint);
}
}
\ No newline at end of file
package com.example.lena.helloworld;
/**
* This class allowes to save beacons
* This class allows to save beacons
* Created by lena on 25.04.16.
*/
public class Beacon {
......@@ -9,7 +9,7 @@ public class Beacon {
private Blob top;
private Blob bot;
public Beacon (Blob t, Blob b) {
public Beacon (Blob t, Blob b) {//auto flip
if (t.lowestPoint.y < b.lowestPoint.y) {
this.top = t;
this.bot = b;
......@@ -37,6 +37,11 @@ public class Beacon {
this.bot = bot;
}
/** equals
* checks if two beacons contain the exact same blobs
* @param other
* @return boolean
*/
public boolean equals (Beacon other) {
if(this.top.equals(other.top) && this.bot.equals(other.bot)) {
return true;
......
......@@ -32,12 +32,12 @@ import java.util.List;
/*TODO: fix order of blobs in beacon; change HSV values*/
public class BeaconDetectionActivity extends Activity implements CameraBridgeViewBase.CvCameraViewListener2 {
private ColorBlobDetector mDetector;
private String TAG = "Beeeacons";
private static final int TEST = -1;
private CameraHelper camHelp;
private Mat mRgba;
private Scalar CONTOUR_COLOR = new Scalar(255, 0, 0, 255);
public ColorBlobDetector mDetector;
public String TAG = "Beeeacons";
public static final int TEST = -1;
public CameraHelper camHelp;
public Mat mRgba;
public Scalar CONTOUR_COLOR = new Scalar(255, 0, 0, 255);
public enum COLOR {YELLOW, RED, BLUE /*ORANGE,*/ };
public HashMap<COLOR, Scalar> colorMap = new HashMap<COLOR, Scalar>(){{put(COLOR.RED, new Scalar(6, 74, 62)); put(COLOR.BLUE, new Scalar(213, 90, 53)); put(COLOR.YELLOW, new Scalar(60, 90, 63)) /*put(COLOR.ORANGE, new Scalar(30, 80, 91))*/;}};
......@@ -51,7 +51,7 @@ public class BeaconDetectionActivity extends Activity implements CameraBridgeVie
public ArrayList<Beacon> beaconList = new ArrayList<>();
public Odometry odometry = new Odometry();
private void convertHSVtoPseudo() {
public void convertHSVtoPseudo() {
for(Scalar s : colorMap.values()) {
Utilities.showLog("old Scalar: " + s.toString());
s.val[0] *= 0.70833; //255/360
......@@ -61,7 +61,15 @@ public class BeaconDetectionActivity extends Activity implements CameraBridgeVie
}
}
private boolean checkAndAddBeacon(Blob blob1, Blob blob2) {
/** checkAndAddBeacon
* this function checks if two blobs are close enough to form a beacon (by comparing their highest to their lowest point)
* if they are, this function also determines which one is on top and then adds a new beacon object containing the two blob objects
* @param blob1
* @param blob2
* @return true if they are a beacon
* false if not
*/
public boolean checkAndAddBeacon(Blob blob1, Blob blob2) {
if(blob1.color != blob2.color) {
if(beaconCoordinates.containsKey(new Pair<COLOR, COLOR>(blob1.color, blob2.color))) {
if (Math.abs(blob1.highestPoint.x - blob2.lowestPoint.x) <= 100) {
......@@ -87,7 +95,13 @@ public class BeaconDetectionActivity extends Activity implements CameraBridgeVie
return false;
}
private int detectBeacons() {
/** detectBeacons
* loops through all blobs and checks if they are in close vicinity to each other, if they are they form a beacon become marked .
* Marked blobs cannot form another beacon.
* The function checkAndAddBeacon is called to add the beacons
* @return the num of beacons found
*/
public int detectBeacons() {
int numBeacon = 0;
Utilities.showLog("kacktusse size: " + kacktusse.size());
for(Blob blob : kacktusse) {
......@@ -108,7 +122,7 @@ public class BeaconDetectionActivity extends Activity implements CameraBridgeVie
return numBeacon;
}
private BaseLoaderCallback blc = new BaseLoaderCallback(this) {
public BaseLoaderCallback blc = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
......@@ -160,6 +174,11 @@ public class BeaconDetectionActivity extends Activity implements CameraBridgeVie
mRgba.release();
}
/** onCameraFrame
* iterates over every color and adds blobs and tries to match them to beacons
* @param inputFrame
* @return a Mat containing the rgba values
*/
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
Utilities.showLog("NEW ");
......@@ -215,14 +234,4 @@ public class BeaconDetectionActivity extends Activity implements CameraBridgeVie
private void checkBeaconThirdTime() {
for (Beacon beacon : beaconList) {
if (beacon.getTop().lowestPoint.y > beacon.getBot().lowestPoint.y) {
Blob blobTop = beacon.getBot();
Blob blobBot = beacon.getTop();
beacon.setBot(blobBot);
beacon.setTop(blobTop);
}
}
}
}
......@@ -13,6 +13,8 @@ public class Blob {
public Point lowestPointGround;
public boolean isUsed = false;
// constructor
public Blob(BeaconDetectionActivity.COLOR c, Point low, Point high, Point lowG) {
this.color = c;
this.highestPoint = high;
......@@ -20,6 +22,7 @@ public class Blob {
this.lowestPointGround = lowG;
}
//copy constructor
public Blob(Blob other) {
this.color = other.color;
this.highestPoint = other.highestPoint;
......@@ -27,6 +30,16 @@ public class Blob {
this.lowestPointGround = other.lowestPointGround;
}
/** equals
* checks if two blob objects repesent the same blob
* @param blob blob to compare to
* @return
* true: if both blobs have the same
* -color
* -lowest pt (ground and img)
* -highest pt
* false: else
*/
public boolean equals (Blob blob) {
if (this.highestPoint != blob.highestPoint || this.lowestPoint != blob.lowestPoint || this.color != blob.color || this.lowestPointGround != blob.lowestPointGround) {
return false;
......@@ -34,6 +47,10 @@ public class Blob {
return true;
}
/** toString
* human readable representation of a blob
* @return String
*/
public String toString() {
return ("color " + color + " high: " + highestPoint + " low: "+ lowestPoint + " ground: " + lowestPointGround);
}
......
......@@ -14,7 +14,7 @@ import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.util.AttributeSet;
//TODO: DOC
public class CameraHelper extends JavaCameraView {
public CameraHelper(Context context, AttributeSet attrs) {
......
......@@ -32,7 +32,7 @@ import org.opencv.imgproc.Imgproc;
import java.util.HashMap;
import java.util.List;
//TODO: DOC
public class ColorBlobDetectionActivity extends Activity implements OnTouchListener, CvCameraViewListener2 {
private static final String TAG = "OCVSample::Activity";
......@@ -238,9 +238,11 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe
}
/*TODO: set and reset the colours with ontouch events*/
public void greenButtonOnClick(View view) {
/** greenButtonOnClick
* detects green in the image
* @param view
*/
public void greenButtonOnClick(View view) {
if (mRgba.empty()) {
Toast.makeText(getApplicationContext(), "The homography matrix hasn't been initialized yet!", Toast.LENGTH_LONG).show();
return;
......
......@@ -51,13 +51,16 @@ public class ColorBlobDetector {
mDilatedMask = new Mat();
mHierarchy = new Mat();
for(int i = 0; i < lowestPoint.length; i++) {
for(int i = 0; i < lowestPoint.length; i++) {//initializing all the highest/lowest points
lowestPoint[i] = new Point(josef.x, josef.y);
highestPoint[i] = new Point(heinrich.x, heinrich.y);
}
hi = new Point(heinrich.x, heinrich.y);
}
/** resetPoints
* resets all reference points to their initial values
*/
public void resetPoints() {
for(int i = 0; i < lowestPoint.length; i++) {
lowestPoint[i] = new Point(josef.x, josef.y);
......@@ -67,6 +70,9 @@ public class ColorBlobDetector {
hi = new Point(heinrich.x, heinrich.y);
}
/** onFrame
* resets all reference points to their initial values
*/
public void onFrame() {
Utilities.showLog("resetting\n\n\n\n\n");
this.resetPoints();
......@@ -95,7 +101,10 @@ public class ColorBlobDetector {
public Point getHighestPoint(int i) { return highestPoint[i]; }
/** sets the base color for this ColorBlobDetector
*
* @param hsvColor base color
*/
public void setHsvColor(Scalar hsvColor) {
double minH = (hsvColor.val[0] >= mColorRadius.val[0]) ? hsvColor.val[0]-mColorRadius.val[0] : 0;
double maxH = (hsvColor.val[0]+mColorRadius.val[0] <= 255) ? hsvColor.val[0]+mColorRadius.val[0] : 255;
......@@ -130,6 +139,12 @@ public class ColorBlobDetector {
mMinContourArea = area;
}
/** process
* process scans the image for blobs of the specified color and adds blobs (if possible)
* @param rgbaImage
* @param c
*/
public void process(Mat rgbaImage, BeaconDetectionActivity.COLOR c) {
Imgproc.pyrDown(rgbaImage, mPyrDownMat);
Imgproc.pyrDown(mPyrDownMat, mPyrDownMat);
......
......@@ -21,6 +21,7 @@ import com.physicaloid.lib.usb.driver.uart.UartConfig;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import java.io.IOException;
......@@ -79,24 +80,11 @@ public class MovementActivity extends Activity {
}
openUsbSerial();
};
public ReadHelper read() {
//TODO: HERE!
byte[] buf = new byte[24];
int l = 0;
if (physicaloid.isOpened()) {
l = physicaloid.read(buf, buf.length);
String text = buf.toString();//WTF
Utilities.showLog("returned: " + text);
Toast.makeText(getApplicationContext(),"Mayo: " + text, Toast.LENGTH_SHORT);
}
else{
Toast.makeText(getApplicationContext(), "Bollocks", Toast.LENGTH_SHORT).show();
}
return new ReadHelper(buf, l);
}
/**
* called when the activity is destroyed
*/
@Override
public void onDestroy(){
super.onDestroy();
......@@ -149,7 +137,7 @@ public class MovementActivity extends Activity {
roBro.readWrite("10");
roBro.readWrite("10");
roBro.readWrite("10");
Timer timer = new Timer(i, this);
Timer timer = new Timer((long) (i*(Utilities.TICKS_CIRCUMFERENCE / (Math.PI *2* Utilities.WHEEL_DIAMETER))), this);
Thread t=new Thread(timer);
roBro.readWrite("i");
t.start();
......@@ -171,31 +159,18 @@ public class MovementActivity extends Activity {
}
public void turnRight(double degrees){
}
public void turnRight(int toSpinR, int toSpinL){
ReadHelper tmp = roBro.readWrite("v");
int[] res = Utilities.processResponse(tmp.toString());
Utilities.showLog(tmp.toString());
Utilities.showLog(res);
if(res.length > 1) {
Toast.makeText(getApplicationContext(), "Foglet: " + res[0] + " " + res[1], Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplicationContext(), "Boglet", Toast.LENGTH_SHORT).show();
}
//return(new Pair(Integer.parseInt(parts[0]), Integer.parseInt(parts[1])));
Toast.makeText(getApplicationContext(), tmp.toString(), Toast.LENGTH_SHORT).show();
}
/** turnRight
* turns the robot right by x degrees
* calculation is done by measuring the relation of wheel diameter and axis diameter and then measuring the ticks needed to turn
*
* @param degrees degrees to turn
*/
public void turnRight(int degrees) {
roBro.readWrite("10");
roBro.readWrite("-10");
roBro.readWrite("i");
double tmp = ((float)degrees/720) * Utilities.TICKS_CIRCUMFERENCE * Utilities.WHEEL_TO_RADIUS;
Utilities.showLog("Ugga: " + tmp + " " + ((float)degrees/360) + " " + Utilities.TICKS_CIRCUMFERENCE + " " + Utilities.WHEEL_TO_RADIUS);
Utilities.showLog("Turn Right: " + tmp + " " + ((float)degrees/360) + " " + Utilities.TICKS_CIRCUMFERENCE + " " + Utilities.WHEEL_TO_RADIUS);
Toast.makeText(getApplicationContext(), "Thread started: " + (int) tmp, Toast.LENGTH_SHORT).show();
Timer timer = new Timer((int) tmp, this);
Thread t=new Thread(timer);
......@@ -209,13 +184,18 @@ public class MovementActivity extends Activity {
}
/** turnLeft
* turns the robot right by x degrees
* calculation is done by measuring the relation of wheel diameter and axis diameter and then measuring the ticks needed to turn
*
* @param degrees degrees to turn
*/
public void turnLeft(int degrees) {
roBro.readWrite("-10");
roBro.readWrite("10");
roBro.readWrite("i");
double tmp = ((float)degrees/720) * Utilities.TICKS_CIRCUMFERENCE * Utilities.WHEEL_TO_RADIUS;
Utilities.showLog("Ugga: " + tmp + " " + ((float)degrees/360) + " " + Utilities.TICKS_CIRCUMFERENCE + " " + Utilities.WHEEL_TO_RADIUS);
Utilities.showLog("Turn Left: " + tmp + " " + ((float)degrees/360) + " " + Utilities.TICKS_CIRCUMFERENCE + " " + Utilities.WHEEL_TO_RADIUS);
Toast.makeText(getApplicationContext(), "Thread started: " + (int) tmp, Toast.LENGTH_SHORT).show();
Timer timer = new Timer((int) tmp, this);
Thread t=new Thread(timer);
......@@ -228,6 +208,10 @@ public class MovementActivity extends Activity {
}
}
/** timerDone
* fct called by threads that expire, causes robot to stop
*/
public void timerDone(){
roBro.stop();
}
......@@ -279,89 +263,64 @@ public class MovementActivity extends Activity {
}
/** queryVelocity
* queries the robots velocity
* this method is unused, the method RobotWhisperer.queryVelocity() does the same job
* @return velocity parameters
*/
public int[] queryVelocity(){
return roBro.queryVelocity();
}
/** queryMotor
* queries the robots motor values
* this method is unused, the method RobotWhisperer.queryMotor() does the same job
* @return motor parameters
*/
public int[] queryMotor(){
return roBro.queryMotor();
}
/** queryDistance
* queries the robots distance sensors
* this method is unused, the method RobotWhisperer.queryDistance() does the same job
* @return distance parameters
*/
public int[] queryDistance(){
return roBro.queryDistance();
}
/** stop
* causes the robot to accelerate into hyperspace
*/
public void stop(){
roBro.stop();
}
/** clearStack
* clears the robots stack by sending the EOL sequence
*/
public void clearStack(){
roBro.clearStack();
}
String convertBytesToChar(byte[] rbuf, int len) {
int tmpbuf;
boolean lastDataIs0x0D = false;
StringBuilder res = new StringBuilder();
for (int i = 0; i < len; ++i) {
if (SHOW_DEBUG) {
Log.d(TAG, "Read Data[" + i + "] : " + rbuf[i]);
}
// "\r":CR(0x0D) "\n":LF(0x0A)
if ((rbuf[i] == 0x0D) && (rbuf[i + 1] == 0x0A)) {
res.append(CR);
res.append(LF);
res.append(BR);
++i;
} else if ((rbuf[i] == 0x0D)) {
// case of rbuf[last] == 0x0D and rbuf[0] == 0x0A
res.append(CR);
lastDataIs0x0D = true;
} else if (lastDataIs0x0D && (rbuf[0] == 0x0A)) {
res.append(LF);
res.append(BR);
lastDataIs0x0D = false;
} else if (lastDataIs0x0D && (i != 0)) {
// only disable flag
lastDataIs0x0D = false;
--i;
} else {
res.append((char) rbuf[i]);
}
Utilities.showLog("QWER: " + (char) rbuf[i]);
}
return res.toString();
}
/** foglet
* test function for the square test
*/
public void foglet(){
forward(6000);
forward(40);
turnLeft(90);
forward(6000);
forward(40);
turnLeft(90);
forward(6000);
forward(40);
turnLeft(90);
forward(6000);
forward(40);
turnLeft(90);
}
/**
* <p>Unescapes any Java literals found in the <code>String</code> to a
* <code>Writer</code>.</p>
* <p/>
* <p>For example, it will turn a sequence of <code>'\'</code> and
* <code>'n'</code> into a newline character, unless the <code>'\'</code>
* is preceded by another <code>'\'</code>.</p>
* <p/>
* <p>A <code>null</code> string input has no effect.</p>
/** moveButtonOnClick
* function called when the button "move me" is clicked
*
* @param str the <code>String</code> to unescape, may be null
* @throws IllegalArgumentException if the Writer is <code>null</code>
* @throws IOException if error occurs on underlying Writer
* @param view
*/
public void moveButtonOnClick(View view) {
if (roBro.physicaloid.isOpened()) {
Utilities.showLog(TAG + "Button Pressed");
......@@ -536,14 +495,16 @@ public class MovementActivity extends Activity {
}
public void stopButtonOnClick(View view) {
forward(100);
}
public void leftButtonOnClick(View view) {
int[] tmp = roBro.queryDistance();
Toast.makeText(getApplicationContext(), "Distance: " + Utilities.dumpIntArray(tmp), Toast.LENGTH_SHORT).show();
}
public void rightButtonOnClick(View view) {
int[] tmp = roBro.queryMotor();
Toast.makeText(getApplicationContext(), "Motor: " + Utilities.dumpIntArray(tmp), Toast.LENGTH_SHORT).show();
}
}
......@@ -20,6 +20,10 @@ public class ReadHelper {
data = b;
}
/** append
* appends two ReadHelpers by concatenating their byte arrays and summing up their lengths
* @param o other RH to append
*/
public void append(ReadHelper o){
byte[] tmp = new byte[data.length + o.data.length];
System.arraycopy(data, 0, tmp, 0, data.length);
......@@ -28,6 +32,11 @@ public class ReadHelper {
data = tmp;
}
/** toString
* this is basically ksukse's convertBytesToChar function
* @return String representing the data
*/
@Override
public String toString() {
boolean lastDataIs0x0D = false;
StringBuilder res = new StringBuilder();
......
......@@ -4,12 +4,7 @@ package com.example.lena.helloworld;
* Created by auki on 19.06.16.
*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.usb.UsbManager;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
......@@ -17,12 +12,6 @@ import com.physicaloid.lib.Physicaloid;
import com.physicaloid.lib.usb.driver.uart.UartConfig;
import java.io.IOException;
/**
* Created by lena on 28.05.16.
*/
public class RobotWhisperer{
public UartConfig uartConfig;
public static final String TAG = "RobotWhisperer";
......@@ -51,12 +40,19 @@ public class RobotWhisperer{
this.context = context;
this.onCreate();
}
/** clearStack
* clears the robots stack by sending the EOL sequence
*/
public void clearStack(){
readWrite(CR);
}
/** read
* reads the robots output
* @return a ReadHelper containing the data read
*/
public ReadHelper read() {