Go to Post Building a robot to survive 2 districts, a Regional, a Region Championship, and World Championships (plus 4 - soon to be 5 - off season events) is a challenge in itself. - Jared Russell [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Spotlight this post!  
Unread 21-02-2016, 22:27
s-taylor s-taylor is offline
Scott Taylor
FRC #1735 (Green Reapers)
Team Role: Mentor
 
Join Date: Feb 2014
Rookie Year: 2014
Location: Auburn, MA
Posts: 19
s-taylor is an unknown quantity at this point
Re: NETWORK TABLE HELP! (ROBOREALM)

FWIW, here's the code we were running earlier today to extract the vision data for target tracking.

in vision.java (autogenerated subsystem from RobotBuilder):
Code:
	// create a new constructor
	public Vision() {		
    // Get a pointer to the networkTable.  "StrongholdContours" is the name we entered into the publish box in GRIP
    table = NetworkTable.getTable("GRIP/StrongholdContours");
	}
and here's the actual function. We had some issues with null sets (if no contours found) and hit some race conditions where the two array reads got different sizes because of an intervening update and some noise. I hacked around those for the moment, but will have to figure something a little better. But, anyway... this did produce the right X values for left-right tracking. All the other reads were pretty much the same. the xRes variable was the pixel resolution in the X direction, which was 320 for us.

Code:
    public double getRawTargetXpos() {
    	double xPos; // return value
    	
    	// 1) Get the current list of targets found.  There might be more than one visible at a time
       	// first, get the vision system data for the target
    	double[] defaultValue = new double[0]; // set up a default value in case the table isn't published yet

    	// Get all needed table items at the same time, in case the table updates between reads.
    	// (could end up with different array sizes)
    	double[] targetX = table.getNumberArray("centerX", defaultValue);
		double[] areas = table.getNumberArray("area", defaultValue);
		if (targetX.length != areas.length) {
			// here the table updated in the middle; we'll have to punt
			System.out.println("NetworkTable udpated in the middle of getRawTargetXpos; returning first valid entry");
	    	if (targetX.length==0)
	    	{
	    		// we didn't find ANY object.  Return a perfectly centered answer so that the system doesn't
	    		// try to adapt
	    		xPos = xRes/2;
	    	}
	    	else xPos = targetX[0];
	    	return xPos;
		}
   	
    	// For initial debug, just print out the table so we can see what's going on
/*
    	System.out.print("centerX: ");
    	for (double xval : targetX) { // for each target found,
    		System.out.print(xval + " ");
    	}
    	System.out.println();
*/    	
    	
    	// 2) Choose the one that has the largest area.  This is PROBABLY the closest target (and most in-line)
    	//    Don't want to choose the one closest to the center because that might actually be the target
    	//    for a different face that's very oblique to our robot position.
		int largestIdx = 0;
    	if (targetX.length > 1) {
    		double largest = 0;
    		for (int c = 0; c < areas.length; c++) {
    			if (areas[c] > largest){
    				largest = areas[c];
    				largestIdx = c;
    			}
    		}
    	}
    	
    	if (targetX.length==0)
    	{
    		// we didn't find ANY object.  Return a perfectly centered answer so that the system doesn't
    		// try to adapt
    		xPos = xRes/2;
    	}
    	else xPos = targetX[largestIdx];
    	
    	return xPos;
    }
Reply With Quote
 


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:46.

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