Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

OpenCV #753

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b170fa7
added mechanum stuf
triacontakai Sep 28, 2019
decf8f7
Renamed files
cyborg48 Sep 28, 2019
9d4361d
Renamed files
cyborg48 Sep 28, 2019
4df9bfb
Adjusted motor directions and values so it turned properly
cyborg48 Oct 5, 2019
0b55bc8
Added autonomous
cyborg48 Oct 12, 2019
ba3a37b
Added code to open camera as sensor (doesn't really work though)
cyborg48 Oct 22, 2019
52af7b6
added outreachbot code
cyborg48 Oct 26, 2019
80a5fa4
Added functions to drive/lift arm using encoders in HwMap, untested
cyborg48 Nov 9, 2019
76df574
fixed inverted strafe
triacontakai Nov 21, 2019
911886a
refactored some movement stuff into functions, working on implementin…
triacontakai Nov 21, 2019
a3221fc
Update
cyborg48 Nov 23, 2019
aa07b1d
change motor names to new stuff
triacontakai Nov 23, 2019
8ce7e28
added arm control stuff; TODO: add encoder stuff
triacontakai Nov 23, 2019
fa8f45d
Update
cyborg48 Nov 26, 2019
c4dc2a5
added+tested arm up-down and extension
triacontakai Nov 30, 2019
5e590a7
Merge remote-tracking branch 'origin/master' into alignfind
cyborg48 Dec 11, 2019
6257cc1
Update
cyborg48 Dec 11, 2019
da43393
Update
cyborg48 Dec 11, 2019
a7c5ad7
changed bindings of nudge to dpad since buttons caused the robot to m…
triacontakai Dec 12, 2019
9d7d446
Update
cyborg48 Dec 13, 2019
42d87fa
Merge remote-tracking branch 'origin/master'
cyborg48 Dec 13, 2019
45c3a80
Got the servo aligner to work
cyborg48 Dec 13, 2019
b6ba49f
Added comments, fixed up some stuff
cyborg48 Dec 14, 2019
c2ceea2
changed grab servo to grab further since grip wasn't tight enough
triacontakai Dec 14, 2019
83a1a20
Merge branch 'master' of https://github.com/triacontakai/ftc_app
triacontakai Dec 14, 2019
24ffc4f
fixed auto-adjust grab hand angle when adjusting height
triacontakai Dec 14, 2019
0554a19
added Gunvir's autonomous
cyborg48 Dec 14, 2019
999e91e
Made adjustments during testing
cyborg48 Dec 14, 2019
5f8cc64
Added OpenCV stuff
cyborg48 Jan 14, 2020
c0b84f5
Added OpenCV stuff
cyborg48 Jan 14, 2020
aa1eeac
Added OpenCV stuff
cyborg48 Jan 14, 2020
96dd683
Added necessary libraries as dependencies to teamcode, fixed importat…
cyborg48 Jan 14, 2020
70aa38c
added some of the gyro stuff, see if you can get it working, I dunno …
cyborg48 Jan 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DogeCV/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions DogeCV/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"


}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir {
dirs '../libs'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(path: ':openCVLibrary3')
implementation (name: 'RobotCore-release', ext: 'aar')
}
25 changes: 25 additions & 0 deletions DogeCV/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/guinea/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
10 changes: 10 additions & 0 deletions DogeCV/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="org.corningrobotics.enderbots.endercv">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.disnodeteam.dogecv;

import android.app.Activity;
import android.content.Context;
import android.view.View;

/**
* Created by guinea on 6/23/17.
* -------------------------------------------------------------------------------------
* Copyright (c) 2018 FTC Team 5484 Enderbots
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
* -------------------------------------------------------------------------------------
* This ViewDisplay displays a View over the entire screen.
* As a singleton, you'll want to pass ActivityViewDisplay.getInstance() instead of directly instantiating it.
*/

public class ActivityViewDisplay implements ViewDisplay {

//There should only be one instance of this class, so make a static reference to it
private static ActivityViewDisplay instance;
private static View main = null;

private ActivityViewDisplay() {
}

public static ActivityViewDisplay getInstance() {
if (instance == null) instance = new ActivityViewDisplay();
return instance;
}

/**
* Sets this display to be the current one in use, and starts it on the UI thread (as opposed to the robot controller thread)
* @param context The context of the OpMode, can be obtained via hardwaremap.appContext;
* @param view The view upon which this activity is to be displayed
*/
public void setCurrentView(final Context context, final View view) {
final Activity activity = (Activity) context;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (main == null)
main = activity.getCurrentFocus();
activity.setContentView(view);
}
});
}

public void removeCurrentView(final Context context) {
final Activity activity = (Activity) context;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.setContentView(main.getRootView());
}
});
}
}
89 changes: 89 additions & 0 deletions DogeCV/src/main/java/com/disnodeteam/dogecv/CameraViewDisplay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.disnodeteam.dogecv;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.ScrollView;


/**
* Created by guinea on 6/23/17.
* -------------------------------------------------------------------------------------
* Copyright (c) 2018 FTC Team 5484 Enderbots
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
* -------------------------------------------------------------------------------------
* Nicely adds/removes a View from the main body of the robot controller app screen.
* As a singleton, you'll want to pass CameraViewDisplay.getInstance() instead of directly instantiating it.
*/

public class CameraViewDisplay implements ViewDisplay {
private static CameraViewDisplay instance;

View view;
private CameraViewDisplay() {
}

public static CameraViewDisplay getInstance() {
if (instance == null) instance = new CameraViewDisplay();
return instance;
}

public void setCurrentView(final Context context, View newView) {
// finding the resID dynamically allows this class to exist outside of the TeamCode module
final int resID = context.getResources().getIdentifier("RelativeLayout", "id", context.getPackageName());
final Activity activity = (Activity) context;
final View queuedView = newView;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
ViewGroup l = (ViewGroup) activity.findViewById(resID); //R.id.RelativeLayout);
if (view != null) {
l.removeView(view);
}
l.addView(new ScrollView(context));
l.addView(queuedView);
view = queuedView;
}
});
}

public void removeCurrentView(Context context) {
final int resID = context.getResources().getIdentifier("RelativeLayout", "id", context.getPackageName());
final Activity activity = (Activity) context;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
//cameraMonitorViewId
ViewGroup l = (ViewGroup) activity.findViewById(resID); // .id.RelativeLayout);
if (view != null) {
l.removeView(view);
}
view = null;
}
});
}
}
129 changes: 129 additions & 0 deletions DogeCV/src/main/java/com/disnodeteam/dogecv/CustomCameraView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.disnodeteam.dogecv;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.Log;

import org.opencv.BuildConfig;
import org.opencv.android.JavaCameraView;
import org.opencv.android.Utils;
import org.opencv.core.Core;
import org.opencv.core.Mat;

/**
* Created by daniel on 11/11/17.
*
* Used to make screen rotate work.
* -------------------------------------------------------------------------------------
* Copyright (c) 2018 FTC Team 5484 Enderbots
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
* -------------------------------------------------------------------------------------
*/

public class CustomCameraView extends JavaCameraView {
private static final String TAG = "CustomCameraView";

public CustomCameraView(Context context, int cameraId) {
super(context, cameraId);
enableFpsMeter();
}

@Override
protected void deliverAndDrawFrame(CvCameraViewFrame frame) {
Mat modified;

int deviceOrientation = getContext().getResources().getConfiguration().orientation;

if (mListener != null) {
modified = mListener.onCameraFrame(frame);
} else {
modified = frame.rgba();
}

boolean bmpValid = true;
if (modified != null) {
try {
// fix bitmap size
if (mCacheBitmap.getWidth() != modified.cols() || mCacheBitmap.getHeight() != modified.rows()) {
mCacheBitmap = Bitmap.createBitmap(modified.cols(), modified.rows(), Bitmap.Config.ARGB_8888);
}
Utils.matToBitmap(modified, mCacheBitmap);
} catch(Exception e) {
Log.e(TAG, "Mat type: " + modified.cols() + "*" + modified.rows());
Log.e(TAG, "Bitmap type: " + mCacheBitmap.getWidth() + "*" + mCacheBitmap.getHeight());
Log.e(TAG, "Utils.matToBitmap() throws an exception: " + e.getMessage());
bmpValid = false;
}
}

if (bmpValid && mCacheBitmap != null) {
Canvas canvas = getHolder().lockCanvas();
if (canvas != null) {
canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR);
if (BuildConfig.DEBUG)
Log.d(TAG, "mStretch value: " + mScale);

// commented out bc this can add distortion to the image
// maximize size of the bitmap to remove black borders in portrait orientation
//mCacheBitmap = Bitmap.createScaledBitmap(mCacheBitmap, canvas.getWidth(), canvas.getHeight()*(canvas.getWidth()/mCacheBitmap.getWidth()), true);

if (mScale != 0) {
canvas.drawBitmap(mCacheBitmap, new Rect(0,0,mCacheBitmap.getWidth(), mCacheBitmap.getHeight()),
new Rect((int)((canvas.getWidth() - mScale*mCacheBitmap.getWidth()) / 2),
(int)((canvas.getHeight() - mScale*mCacheBitmap.getHeight()) / 2),
(int)((canvas.getWidth() - mScale*mCacheBitmap.getWidth()) / 2 + mScale*mCacheBitmap.getWidth()),
(int)((canvas.getHeight() - mScale*mCacheBitmap.getHeight()) / 2 + mScale*mCacheBitmap.getHeight())), null);
} else {
canvas.drawBitmap(mCacheBitmap, new Rect(0,0,mCacheBitmap.getWidth(), mCacheBitmap.getHeight()),
new Rect((canvas.getWidth() - mCacheBitmap.getWidth()) / 2,
(canvas.getHeight() - mCacheBitmap.getHeight()) / 2,
(canvas.getWidth() - mCacheBitmap.getWidth()) / 2 + mCacheBitmap.getWidth(),
(canvas.getHeight() - mCacheBitmap.getHeight()) / 2 + mCacheBitmap.getHeight()), null);
}

// temporarily rotate canvas to draw FPS meter in correct orientation in portrait
if(deviceOrientation == Configuration.ORIENTATION_PORTRAIT) {
canvas.save();

canvas.rotate(-90, getWidth() / 2, getHeight() / 2);

if (mFpsMeter != null) {
mFpsMeter.measure();
mFpsMeter.draw(canvas, 20, 30);
}

canvas.restore();
}

getHolder().unlockCanvasAndPost(canvas);
}
}
}


}
Loading