Go to Post Only think of Gracious Professionalism as a standard to work toward personally. Never use it as a gauge to point out someone else’s shortcomings. - Rich Kressly [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
  #1   Spotlight this post!  
Unread 28-01-2013, 17:17
barre006 barre006 is offline
Registered User
FRC #2526
 
Join Date: Jan 2013
Location: Maple Grove
Posts: 1
barre006 is an unknown quantity at this point
Centering Camera and Robot

We need to figure out how to get our camera to center itself on rectangular objects.

Basically, we can get the camera to take a picture and recognize the rectangle as a target. But the rectangle in the image isn't centered. We want the robot and camera to move until the rectangle is in the dead center of the camera and the image, that way we can aim correctly.

Thank you in advance for any assistance you might be able to offer us, we're really looking forward to finally using vision targeting this year.
Reply With Quote
  #2   Spotlight this post!  
Unread 28-01-2013, 17:48
2472Programer 2472Programer is offline
Programming Captain
AKA: Dane Jensen
FRC #2472 (The Centurions)
Team Role: Programmer
 
Join Date: May 2012
Rookie Year: 2006
Location: Circle Pines, MN
Posts: 13
2472Programer is an unknown quantity at this point
Re: Centering Camera and Robot

I faced this problem a few weeks ago and here is my solution

Code:
 private void centerShooter() {
        
        ColorImage image = null;
        
        BinaryImage thresholdImage = null;
        
        BinaryImage bigObjectsImage = null;
        
        BinaryImage convexHullImage = null;
        
        BinaryImage filteredImage = null;
        int biggestindex = 99;
        int widest = 0;
        int highest = 0;
        ParticleAnalysisReport[] reports = null;
        

        try{
            
            image = camera.getImage();
            
            
            thresholdImage = image.thresholdRGB(0, 25, 20, 225, 0, 225);
            
           // thresholdImage.
            
            bigObjectsImage = thresholdImage.removeSmallObjects(false, 2);
            
            convexHullImage =  bigObjectsImage.convexHull(false);
            
            filteredImage = convexHullImage.particleFilter(cc);
            
            reports = filteredImage.getOrderedParticleAnalysisReports();
            for (int i = 0; i < reports.length + 1; i++ ){
                
                            
                if ((reports[i].imageHeight > highest) && (reports[i].imageWidth > widest))
                {
                    widest = reports[i].imageWidth;
                    highest = reports[i].imageHeight;
                    biggestindex = i;
                    
                    System.out.println("Problem's not here");
                }
            
            
        
                System.out.println("Test");
        
                SmartDashboard.putString("Filtered Image", filteredImage.toString());
                
                outputstring = "Height = " + reports[biggestindex].toString() + "Width = " + reports[biggestindex].toString();
                System.out.println (outputstring);
                
                SmartDashboard.putString("Dimensions: ", outputstring);
                
                SmartDashboard.putInt ("Targets Found", reports.length);
                
                SmartDashboard.putInt("height of Target", reports[biggestindex].imageHeight);
                
                SmartDashboard.putInt("Width of Target", reports[biggestindex].imageWidth);      
                
            
                if(reports[biggestindex].center_mass_y>centerdown){
                   
                    increaseShooterAngle();
                    
                    Timer.delay(.3);
                    
                    shooterAngle.set(Relay.Value.kOff);
                    
                    System.out.println("Increase");
                    
                }else if(reports[biggestindex].center_mass_y<centerup){
                    
                    decreaseShooterAngle();
                    
                    Timer.delay(.3);
                    
                    shooterAngle.set(Relay.Value.kOff);
                    
                    System.out.println("Decrease");

                    
                }else{
                    
                    System.out.println("You're Good");
                    
                }
                if(reports[biggestindex].center_mass_x>centerleft){
                    
                    toTheLeft();
                    
                }else if(reports[biggestindex].center_mass_x<centerright){
                    
                    toTheRight();
                    
                }else{
                    
                    tank.tankDrive(0, 0);
                }
                
                    
            
            }
            
                     
        }catch(Exception ex){
            //System.out.println("Failed");
            
            SmartDashboard.putString("Error", ex.getMessage());
            
        }finally{
            
        }
        
        try{
            
            filteredImage.free();
            
            convexHullImage.free();
            
            bigObjectsImage.free();
            
            thresholdImage.free();
            
            image.free();
            
        }catch(NIVisionException ex){
            
        }
    }
This still isn't perfect, as most times the robot completely misses the vision target, a problem that I must face today, and this code likes to also track white light... no explanation needed and in terms of the Y axis tracking, you may want to have a sensor that can tell you the angle of the shooter and have the shooter move until it is at the right angle.
Reply With Quote
  #3   Spotlight this post!  
Unread 29-01-2013, 00:49
divixsoft's Avatar
divixsoft divixsoft is offline
Registered User
FRC #0835
 
Join Date: Feb 2011
Location: MI
Posts: 29
divixsoft is an unknown quantity at this point
Re: Centering Camera and Robot

why not calculate the angle, than use a gyro with a pid loop to turn?
Reply With Quote
  #4   Spotlight this post!  
Unread 29-01-2013, 03:43
jesusrambo jesusrambo is offline
Self-Proclaimed Programmer Messiah
AKA: JD Russo
FRC #2035 (Robo Rockin' Bots)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2010
Location: Carmel, CA
Posts: 114
jesusrambo is an unknown quantity at this point
Re: Centering Camera and Robot

Hey, try checking out my guide. It explains how to do the vision processing parts of what you're trying to do.

As for the rest, check out my code for automatic turret tracking. RobotMap.top[0] is the reported x coordinate of the center of the detected target. If you're doing your own vision processing, just pass it that value as such. CameraXOffset is just 160, the x value of the center of the camera's vision. HorizontalTurretAxis.rotate() is a method I added to HorizontalTurretAxis, but replace that with whatever you want the PID output to be of course.

If you need more explanation on how this works please ask.

TL;DR image processing sends x,y coordinates of detected target back to a command that runs a PID controller using that coordinate as input and your motors as output to align itself.
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 12:54.

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