Go to Post Getting your questions answered is what the big thick manual is for....GO READ. - Dorienne [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-02-2013, 21:58
DjMaddius's Avatar
DjMaddius DjMaddius is offline
Registered User
AKA: Matt Smith
FRC #2620 (Southgate Titans)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Southgate, Mi
Posts: 161
DjMaddius is an unknown quantity at this point
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   Spotlight this post!  
Unread 07-02-2013, 22:54
bgg's Avatar
bgg bgg is offline
Registered User
FRC #3679
 
Join Date: Nov 2011
Location: San Marcos
Posts: 27
bgg is an unknown quantity at this point
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   Spotlight this post!  
Unread 08-02-2013, 12:09
DjMaddius's Avatar
DjMaddius DjMaddius is offline
Registered User
AKA: Matt Smith
FRC #2620 (Southgate Titans)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Southgate, Mi
Posts: 161
DjMaddius is an unknown quantity at this point
Re: Getting distance to the goal

Quote:
Originally Posted by bgg View Post
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.
Well, we used one of those last year, but if anything gets in the way, a frisbee or a bot or even the pyramid, it will return a false distance. So I was thinking of going with the photon cannon idea and using the distance between the top and bottom retroreflective tape to give me my distance using some basic trig functions. I was just seeing if there were any very efficient algorithms on doing this. I don't want it to take up a ton of processing obviously.
  #4   Spotlight this post!  
Unread 08-02-2013, 12:27
Jeffy's Avatar
Jeffy Jeffy is offline
Retired, for now
AKA: Jeff Gier
FRC #2410 (Metal Mustang Robotics) #159 (Alpine Robotics)
Team Role: College Student
 
Join Date: Mar 2008
Rookie Year: 2008
Location: Fort Collins
Posts: 523
Jeffy has a brilliant futureJeffy has a brilliant futureJeffy has a brilliant futureJeffy has a brilliant futureJeffy has a brilliant futureJeffy has a brilliant futureJeffy has a brilliant futureJeffy has a brilliant futureJeffy has a brilliant futureJeffy has a brilliant futureJeffy has a brilliant future
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.
__________________
Metal Mustang Robotics 2410 (2008-2011)
2008 STL Rookie All-Star
2010 GKC Finalists
2010 OKC Champions
Alpine Robotics 159 (2012-)
2012 CO Finalists

700 miles from home, 2 miles from FRC. Life is good.
  #5   Spotlight this post!  
Unread 08-02-2013, 13:13
DjMaddius's Avatar
DjMaddius DjMaddius is offline
Registered User
AKA: Matt Smith
FRC #2620 (Southgate Titans)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Southgate, Mi
Posts: 161
DjMaddius is an unknown quantity at this point
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   Spotlight this post!  
Unread 08-02-2013, 14:00
DjMaddius's Avatar
DjMaddius DjMaddius is offline
Registered User
AKA: Matt Smith
FRC #2620 (Southgate Titans)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Southgate, Mi
Posts: 161
DjMaddius is an unknown quantity at this point
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   Spotlight this post!  
Unread 08-02-2013, 16:58
Kusha's Avatar
Kusha Kusha is offline
Crimpin' ain't easy
AKA: Kusha Gharahi
no team (Looking for a team)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Dallas, Texas
Posts: 207
Kusha is a jewel in the roughKusha is a jewel in the roughKusha is a jewel in the roughKusha is a jewel in the rough
Re: Getting distance to the goal

Quote:
Originally Posted by DjMaddius View Post
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.
I am very interested in seeing this as I am having difficulty doing this with vision processing.
__________________
https://kusha.me
  #8   Spotlight this post!  
Unread 08-02-2013, 17:02
Quenty's Avatar
Quenty Quenty is offline
Registered User
FRC #1984 (Raider Revolution Robotics)
Team Role: Programmer
 
Join Date: Feb 2013
Rookie Year: 2012
Location: Earth
Posts: 1
Quenty is an unknown quantity at this point
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   Spotlight this post!  
Unread 08-02-2013, 17:38
Justin m's Avatar
Justin m Justin m is offline
Registered User
FRC #2028 (Phantom Mentalists)
Team Role: Programmer
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Hampton, va
Posts: 14
Justin m is an unknown quantity at this point
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;
    }
I am assuming you can figure out how to filter for targets.

Last edited by Justin m : 08-02-2013 at 19:53. Reason: forgot one important thing
  #10   Spotlight this post!  
Unread 08-02-2013, 19:16
DjMaddius's Avatar
DjMaddius DjMaddius is offline
Registered User
AKA: Matt Smith
FRC #2620 (Southgate Titans)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Southgate, Mi
Posts: 161
DjMaddius is an unknown quantity at this point
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;
    }
}
I have not tested this, though if you need help let me know! I should be able too.
  #11   Spotlight this post!  
Unread 10-02-2013, 22:26
DjMaddius's Avatar
DjMaddius DjMaddius is offline
Registered User
AKA: Matt Smith
FRC #2620 (Southgate Titans)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Southgate, Mi
Posts: 161
DjMaddius is an unknown quantity at this point
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   Spotlight this post!  
Unread 13-02-2013, 21:50
nyaculak nyaculak is offline
Registered User
FRC #0053 (Area 53)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Maryland
Posts: 28
nyaculak will become famous soon enough
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.
__________________
2013 MUC DC 3rd Place, FRC DC Regional, FRC Chesapeake Regional
2012 FRC DC Regional, FRC Chesapeake Regional
ERHS Robotics Club
- FRC Team 53 "Area 53"
www.erhsroboticsclub.org
  #13   Spotlight this post!  
Unread 13-02-2013, 23:14
Gregor's Avatar
Gregor Gregor is offline
#StickToTheStratisQuo
AKA: Gregor Browning
no team
Team Role: College Student
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Kingston, Ontario, Canada
Posts: 2,447
Gregor has a reputation beyond reputeGregor has a reputation beyond reputeGregor has a reputation beyond reputeGregor has a reputation beyond reputeGregor has a reputation beyond reputeGregor has a reputation beyond reputeGregor has a reputation beyond reputeGregor has a reputation beyond reputeGregor has a reputation beyond reputeGregor has a reputation beyond reputeGregor has a reputation beyond repute
Re: Getting distance to the goal

Quote:
Originally Posted by bgg View Post
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.
I wouldn't recommend this. We used one last year. We had issues with teams on our alliance driving in front by accident, throwing our shooting off. Near the end of the second regional, we started to clue in that we should probably tell our alliance partners about it. Turns out this was a bad idea. Teams we played with in one match, and against in later matches (including eliminations) only had to SIT infront of us to throw our shooting off.

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.
__________________
What are nationals? Sounds like a fun American party, can we Canadians come?
“For me, insanity is super sanity. The normal is psychotic. Normal means lack of imagination, lack of creativity.” -Jean Dubuffet
"Insanity is doing the same thing over and over again and expecting different results." -Albert Einstein
FLL 2011-2015 Glen Ames Robotics-Student, Mentor
FRC 2012-2013 Team 907-Scouting Lead, Strategy Lead, Human Player, Driver
FRC 2014-2015 Team 1310-Mechanical, Electrical, Drive Captain
FRC 2011-xxxx Volunteer
How I came to be a FIRSTer
<Since 2011
  #14   Spotlight this post!  
Unread 14-02-2013, 10:28
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Re: Getting distance to the goal

Quote:
Originally Posted by Justin m View Post
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;
    }
I am assuming you can figure out how to filter for targets.
However the height varies as well depending on the height of your robot and how close you are to the target.
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me
  #15   Spotlight this post!  
Unread 14-02-2013, 11:43
rwkling1's Avatar
rwkling1 rwkling1 is offline
Registered User
FRC #2977 (Sir Lancer Bots)
Team Role: Leadership
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Minnesota
Posts: 143
rwkling1 has a spectacular aura aboutrwkling1 has a spectacular aura about
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!
Closed Thread


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 02:22.

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