Go to Post There is no such thing as "un-GP." - Tetraman [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #16   Spotlight this post!  
Unread 06-02-2017, 12:13
SamCarlberg's Avatar
SamCarlberg SamCarlberg is online now
GRIP, WPILib. 2084 alum
FRC #2084
Team Role: Mentor
 
Join Date: Nov 2015
Rookie Year: 2009
Location: MA
Posts: 161
SamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to behold
Re: Will the RoboRio handle this? (Upgrade to coprocessor?)

Code:
while (!visionThreadHighGoal.isInterrupted()) {
Please don't do this. This prevents the pipeline from ever running.

Documentation
__________________
WPILib
GRIP, RobotBuilder
Reply With Quote
  #17   Spotlight this post!  
Unread 06-02-2017, 12:30
Lesafian Lesafian is offline
Registered User
AKA: Jeremy Styma
FRC #6077 (Wiking Kujon)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2016
Location: Posen, Michigan
Posts: 38
Lesafian is an unknown quantity at this point
Re: Will the RoboRio handle this? (Upgrade to coprocessor?)

Quote:
Originally Posted by rich2202 View Post
Follow this thread on switching between cameras:

https://www.chiefdelphi.com/forums/s...d.php?t=154806
I was able to get rid of the VisionThread's, and make a single thread. I'm going to decide what to do with the centerX and width values in my lineUp method based on which cam is selected (the cam also decides whether we're going for goals or gears).

Do you think the roboRio can handle this? (It will be much faster imo.)
Code:
				new Thread(() -> {
			double[] red = { 0, 0, 255 };
			double[] green = { 0, 255, 0 };
			Scalar color = new Scalar(red);
			while (!Thread.interrupted()) {
				selectedVid.grabFrame(image);
				if (pipeline.filterContoursOutput().size() >= 2) {
					pipeline.process(image);
					if (!isTargetFound) {
						color.set(red);
					} else {
						color.set(green);
					}
					Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
					Rect r1 = Imgproc.boundingRect(pipeline.filterContoursOutput().get(1));
					Imgproc.rectangle(image, new Point(r.x, r.y), new Point(r.x + r.width, r.y + r.height), color, 2);
					Imgproc.rectangle(image, new Point(r1.x, r1.y), new Point(r1.x + r1.width, r1.y + r1.height), color,
							2);
					synchronized (imgLock) {
						centerX = r.x + (r.x + r.width) / 2;
						width = r.width;
					}
					outputStream.putFrame(image);
				} else {
					synchronized (imgLock) {
						centerX = 0.0;
						width = 0.0;
						isTargetFound = false;
					}
					outputStream.putFrame(image);
				}
				try {
					Thread.sleep(100);
				} catch (Exception e) {

					e.printStackTrace();
				}
			}
		}).start();
^ opposed to the code I pasted in the initial question.

Here is the basis of my lineUp and isLinedUp methods.
Code:
	public void lineUp() {

		// Default variables
		double centerX = 0.0;
		double width = 0.0;
		double fwd = 0;
		
		//Update the values.
		this.isLinedUp();

		// Check to see if the shot is lined up.
		if (!isTargetFound) {
			// Synchronize variables from thread to thread
			synchronized (imgLock) {
				centerX = this.centerX;
				width = this.width;
			}

			/*
			 * If the robot is too far, drive forwards If the robot is too
			 * close, drive backwards
			 */
			if (width > tooFar) {
				fwd = -width * 0.0025;
			} else if (width < tooClose) {
				fwd = width * 0.005;
			} else {
				fwd = 0;
			}
			double turn = centerX - imageCenter;
			drive.mecanumDrive_Cartesian(fwd, 0, turn * 0.005, 0);
			
		} else {
			SmartDashboard.putString(shotReady, "true");
		}

	}

	/*
	 * Decide which method of lining up to use, and line up the robot
	 * accordingly.
	 */
	public boolean isLinedUp() {
		// Default values
		double centerX = 0.0;
		double width = 0.0;

		// Sync the processed images from grip to the local variables
		synchronized (imgLock) {
			centerX = this.centerX;
			width = this.width;
		}

		/*
		 * Check and see if the robot is where it needs to be if true: tell the
		 * driver to shoot if false: initiate this.lineUp and test again once
		 * the robot believes it is lined up.
		 */
		if (whichCam) {
			//High goal logic
			boolean isXCentered = (centerX + gripTolerance >= imageCenter) && (centerX - gripTolerance <= imageCenter);
			boolean isDistance4ft4inch = (width + gripTolerance >= tooClose) && (width - gripTolerance <= tooFar);

			if (isXCentered && isDistance4ft4inch) {
				SmartDashboard.putString(shotReady, "true");
				isTargetFound = true;
				return true;
			} else {
				this.lineUp();
				SmartDashboard.putString(gearReady, "false");
				isTargetFound = false;
				return false;
			}
		} else {
			//TODO:
			//Gear logic
		}
		return false;
	}
Sorry to bombard you with code, but do you think I could get away with this?

Last edited by Lesafian : 06-02-2017 at 12:40.
Reply With Quote
  #18   Spotlight this post!  
Unread 06-02-2017, 12:38
Lesafian Lesafian is offline
Registered User
AKA: Jeremy Styma
FRC #6077 (Wiking Kujon)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2016
Location: Posen, Michigan
Posts: 38
Lesafian is an unknown quantity at this point
Re: Will the RoboRio handle this? (Upgrade to coprocessor?)

Quote:
Originally Posted by SamCarlberg View Post
Code:
while (!visionThreadHighGoal.isInterrupted()) {
Please don't do this. This prevents the pipeline from ever running.

Documentation
Oh shoot, didn't even think about that haha. Could you look at my last reply? I'm not sure if I have to use VisionThread or VisionRunner, but I think my code will work.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:44.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi