|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Getting distance to the goal
Just wondering what other teams are using/have used to get the distance to the goal. If I have the distance to the goal I can throw the distance into my equation for our shooter and spit out the angle I need the shooter at to make the shot. Really, my quesetion is what is the most efficient manner when using vision processing to get the distance to the 3 ptn frisbee goal? I'm using java right now (doing a build on labview and java)
Any help is much appreciated! |
|
#2
|
||||
|
||||
|
Re: Getting distance to the goal
We've used a sonic rangefinder which came with fewer headaches but less sophistication and detail than vision processing. This might get the job done for what you need. Mount it centered on the front of the bot and the distance to the wall can be used for calculating shooter speed/shot distance. A voucher from MaxBotix was included in KOP and might be a sensible solution.
|
|
#3
|
||||
|
||||
|
Re: Getting distance to the goal
Quote:
|
|
#4
|
||||
|
||||
|
Re: Getting distance to the goal
Most teams I have talked with plan on using the pyramid to their advantage when lining up a shot. I think its a great plan.
|
|
#5
|
||||
|
||||
|
Re: Getting distance to the goal
I agree, but I'd like to be able to shoot from wherever, speeding things up ten fold.
Anywho, I found the whitepaper on tracking, http://firstforge.wpi.edu/sf/go/doc1302?nav=1 I don't quite understand the whole distance calculations where they are getting the width of the entire field of view. |
|
#6
|
||||
|
||||
|
Re: Getting distance to the goal
Alrighty, I think I've got it, I'll upload my java class in a few, its untested but theoretically works. I'll have to test it tomorrow at our meeting.
|
|
#7
|
|||||
|
|||||
|
Re: Getting distance to the goal
I am very interested in seeing this as I am having difficulty doing this with vision processing.
|
|
#8
|
||||
|
||||
|
Re: Getting distance to the goal
I think there's a java API out there, but I'm not sure what it's called. D:
|
|
#9
|
||||
|
||||
|
Re: Getting distance to the goal
What the you have to do is determine the width of the target in pixels, given a constant value w/ the target centered, and find the hypotenuse, which is your distance
EDIT: Use the height for distance, not the width.The width can vary with angle to the target. Example: Note, these are necessary constants Code:
public static final int IMAGE_WIDTH = 320;
public static final int IMAGE_HEIGHT = 240;
public static final double TARGET_WIDTH = 2.0;
public static final double TARGET_HEIGHT = 1.5;
public static final double RECTANGLE_QUALITY_THRESHOLD = 95.0;
public static final double PARTICLE_TO_IMAGE_THRESHOLD = 0.05;
public static final double PARTICLE_AREA_THRESHOLD = 250.0;
protected double fieldOfViewWidth = 0.0;
/**
* Return distance to target in inches
*
* @param targetHeightInPixels
* @return
*/
public double GetDistanceToTarget(int targetHeightInPixels)
{
double fieldOfViewHeight = TARGET_HEIGHT / targetHeightInPixels * IMAGE_HEIGHT;
distance = (fieldOfViewHeight / 2.0) /
/*
* tan 23.5 degrees
*/
0.4348123749;
return distance * 12.0 * 1.4;
}
Last edited by Justin m : 08-02-2013 at 19:53. Reason: forgot one important thing |
|
#10
|
||||
|
||||
|
Re: Getting distance to the goal
Appreciate the reply's! Sorry it took a few hours for me to post the code, left for a few hours for dinner and such..
Code:
package org.first.team2620;
import com.sun.squawk.util.MathUtils;
import edu.wpi.first.wpilibj.DriverStationLCD;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.camera.AxisCameraException;
import edu.wpi.first.wpilibj.image.BinaryImage;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.CriteriaCollection;
import edu.wpi.first.wpilibj.image.NIVision.MeasurementType;
import edu.wpi.first.wpilibj.image.NIVisionException;
import edu.wpi.first.wpilibj.image.ParticleAnalysisReport;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
*
* @author frc2620
*/
public class CameraDistanceCalc {
private AxisCamera camera_;
private CriteriaCollection cc;
private DriverStationLCD b_LCD;
public CameraDistanceCalc(AxisCamera cam)
{
camera_ = cam;
cc = new CriteriaCollection();
cc.addCriteria(MeasurementType.IMAQ_MT_BOUNDING_RECT_WIDTH, 30, 400, false);
cc.addCriteria(MeasurementType.IMAQ_MT_BOUNDING_RECT_HEIGHT, 40, 400, false);
b_LCD = DriverStationLCD.getInstance();
b_LCD.updateLCD();
}
public CameraDistanceCalc(String cameraIP)
{
camera_ = AxisCamera.getInstance(cameraIP);
cc = new CriteriaCollection();
cc.addCriteria(MeasurementType.IMAQ_MT_BOUNDING_RECT_WIDTH, 30, 400, false);
cc.addCriteria(MeasurementType.IMAQ_MT_BOUNDING_RECT_HEIGHT, 40, 400, false);
b_LCD = DriverStationLCD.getInstance();
b_LCD.updateLCD();
}
public double calcDistance()
{
double distance = 0;
try
{
ColorImage image = camera_.getImage();
//ColorImage image;
//image = new RGBImage("/10ft2.jpg");
//BinaryImage thresholdImage = image.thresholdRGB(25, 255, 0, 45, 0, 47); // keep only red objects
BinaryImage thresholdImage = image.thresholdRGB(0, 45, 25, 225, 0, 45); // Keep only green objects
BinaryImage bigObjectsImage = thresholdImage.removeSmallObjects(false, 2); // remove small artifacts
BinaryImage convexHullImage = bigObjectsImage.convexHull(false); // fill in occluded rectangles
BinaryImage filteredImage = convexHullImage.particleFilter(cc); // find filled in rectangles
ParticleAnalysisReport[] reports = filteredImage.getOrderedParticleAnalysisReports(); // get list of results
ParticleAnalysisReport ThreePtn = reports[reports.length-1]; // Reports is listed by largest to smallest area in the rectangle, 3 ptner should be the smallest area
double tw = 4.5;
double tpw = ThreePtn.boundingRectWidth;
double cw = 320;
double WFOV = tw * (cw / tpw);
distance = (WFOV / 2) / (MathUtils.atan(27 * (Math.PI / 180)));
System.out.println(filteredImage.getNumberParticles() + " " + Timer.getFPGATimestamp());
SmartDashboard.putNumber("Number of Particles: ", filteredImage.getNumberParticles());
SmartDashboard.putNumber("Height: ", filteredImage.getHeight());
SmartDashboard.putNumber("Width: ", filteredImage.getWidth());
SmartDashboard.putNumber("Distance:", distance);
filteredImage.free();
convexHullImage.free();
bigObjectsImage.free();
thresholdImage.free();
image.free();
} catch (AxisCameraException ex) {
ex.printStackTrace();
} catch (NIVisionException ex) {
ex.printStackTrace();
}
return distance;
}
}
|
|
#11
|
||||
|
||||
|
Re: Getting distance to the goal
Has anyone tested my class I made? I'd like to know any results you have from it.
I haven't had a chance to try it yet, other things have out weighed it. |
|
#12
|
|||
|
|||
|
Re: Getting distance to the goal
Team 53 is going to mount the XBOX Kinect directly on our robot and use OpenCV and an on-board computer (Beagle Board) to process our images.
|
|
#13
|
||||
|
||||
|
Re: Getting distance to the goal
Quote:
|
|
#14
|
|||||
|
|||||
|
Re: Getting distance to the goal
Quote:
We had to fall back on our preset shooter values, which weren't nearly as accurate or tuned in as our values from our ultrasonic. We spent all of lunch after alliance selections at our second regional tuning our presets, which we almost entirely used in our elimination matches. |
|
#15
|
||||
|
||||
|
Re: Getting distance to the goal
you see, this is what our team did last year, we built a very complex robot (one that had the shooter able to turn, change the angle, had a range finder, camera, etc.) and we ended up not doing too well at competition because the programming was too complex for the programmers, all i'm saying is, if it doesn't work out, shoot from the front or back of the pyramid and have a set angle and speed, that is what we are doing, good luck!
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|