Go to Post FIRST is an opportunity for me to tackle problems that have long been solved. - Madison [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 17-02-2016, 12:41
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
NetworkTables not refreshing

I am using grip with networktables and I do not think I am setting it up properly. Here is my code:
Code:
package org.usfirst.frc.team2847.robot.subsystems;

import org.usfirst.frc.team2847.robot.RobotMap;
import org.usfirst.frc.team2847.robot.commands.JoystickDrive;

import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.command.PIDSubsystem;
import edu.wpi.first.wpilibj.networktables.NetworkTable;

/**
 *
 */
public class Drivetrain extends PIDSubsystem {

	// Initialize your subsystem here

	double[] greenAreasArray = {};
	double[] greenXArray = {};
	double[] greenYArray = {};
	double[] defaultValue = new double[0];

	double maxArea = 0;
	double greenX = 0;
	double greenY = 0;
	double offsetX;

	int arrayNum = 0;

	// create our drivetrain object
	RobotDrive myDriveTrain = new RobotDrive(RobotMap.frontLeftDrive, RobotMap.rearRightDrive);

	NetworkTable table = NetworkTable.getTable("GRIP/myContoursReport");

	public Drivetrain() {
		// Use these to get going:
		// setSetpoint() - Sets where the PID controller should move the system
		// to
		// enable() - Enables the PID controller.
		super("Drivetrain", RobotMap.kDriveP, RobotMap.kDriveI, RobotMap.kDriveD);
		setPercentTolerance(5.0);

		// viz

	}

	// Put methods for controlling this subsystem
	// here. Call these from Commands.

	public void initDefaultCommand() {
		// Set the default command for a subsystem here.
		setDefaultCommand(new JoystickDrive());
	}

	// make the method for our drivetrain
	public void manDrive(double leftValue, double rightValue) {
		myDriveTrain.tankDrive(leftValue, rightValue);
	}

	/*
	 * starts a counter and for each item in the number array compares it to the
	 * max value from before in the end of the loop we should have max = the
	 * biggest value in our array we do this to find out which contour is our
	 * target this should filter out any minor interference in the camera
	 */

	public boolean isContours() {
		table = NetworkTable.getTable("GRIP/myContoursReport");
		greenAreasArray = table.getNumberArray("area", defaultValue);
		if (greenAreasArray.length > 0) {
			System.out.println(greenAreasArray.length);
			return true;
		} else {
			System.out.println("no array");
			return false;
		}
	}

	public void findMaxArea() {
		if (isContours()) {
			System.out.println("Areas:");
			for (int counter = 0; counter < greenAreasArray.length; counter++) {
				if (greenAreasArray[counter] > maxArea) {
					maxArea = greenAreasArray[counter];
					arrayNum = counter;
					System.out.println(greenAreasArray[counter]);
				}
			}
			System.out.print(maxArea);
		}
	}

	public void updateArea() {
		findMaxArea();
	}

	public void useCenter() {
		this.updateArea();
		if (isContours()) {
			greenXArray = table.getNumberArray("centerX", defaultValue);
			greenYArray = table.getNumberArray("centerY", defaultValue);
			greenX = greenXArray[arrayNum];
			greenY = greenYArray[arrayNum];
		}
	}

	public double offsetCalc() {
		this.useCenter();
		offsetX = 320 - greenX;
		return offsetX;
	}

	protected double returnPIDInput() {
		// Return your input value for the PID loop
		// e.g. a sensor, like a potentiometer:
		// yourPot.getAverageVoltage() / kYourMaxVoltage;
		return greenY;
	}

	protected void usePIDOutput(double output) {
		// Use output to drive your system, like a motor
		// e.g. yourMotor.set(output);
		double go;
		go = (output * 0.50);
		if (offsetCalc() > 0) {
			this.manDrive(go * (greenX / 320), go);
		} else if (offsetCalc() < 0) {
			this.manDrive(go, go * (greenX / 320));
		} else {
			this.manDrive(go, go);
		}

		System.out.println(go);
	}
}
I currently use a button to call the PID, but my area array doesnt update. Its always 1001.1. How am I supposed to set up the NetworkTable, as a server, do I need to give it an IP? I am using Outline viewer server to view the GRIP tables right now, but how do I replicate that in my code to update.
Reply With Quote
  #2   Spotlight this post!  
Unread 17-02-2016, 17:03
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: NetworkTables not refreshing

Possibly related, I currently have the GRIP SmartDashboard plugin, I have a contour drawn on my screen and it is stuck and not updating. Could this be part of the issue?
Reply With Quote
  #3   Spotlight this post!  
Unread 18-02-2016, 11:35
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: NetworkTables not refreshing

I rebooted the computer, now the GRIP extension doesn't display the frozen info on the screen, but if I open outline viewer I can see the NetworkTable is filled with information. When I run my code and try to output the contents of the table, my code instead says that the array is empty. How do I point the NetworkTable to localhost?
Reply With Quote
  #4   Spotlight this post!  
Unread 19-02-2016, 12:01
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: NetworkTables not refreshing

Well it looks like I'm just talking to myself here, but if anyone else stumbles upon this, the issue is, GRIP can push the values to localhost, but network tables only reads the roboRIO-2847-FRC.local, so the fix is pointing GRIP at the roboRIO not localhost. Also make sure to put NetworkTable.setServerMode() in the robotInit().
Reply With Quote
  #5   Spotlight this post!  
Unread 21-02-2016, 10:58
An Outlier An Outlier is offline
Registered User
AKA: Julian Bernard
FRC #5687 (The Outliers)
Team Role: Programmer
 
Join Date: Mar 2015
Rookie Year: 2015
Location: Milky Way Galexy
Posts: 31
An Outlier is an unknown quantity at this point
Re: NetworkTables not refreshing

MY Team is ALSO having the same problems, only with a Raspberry PI.

We can see the NetworkTables in the LabView dashboard, but according to the code on our RoboRio, our "GRIP" Table does not exist.

We also tried sending the values to a Sub-Table, and just writing the variables in the SmartDashboard table.

No matter where we put them, the LabView dashboard COULD see them, and our RoboRio code COULD NOT.

Any help would be fantastic, our team is completely stumped.
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 22:37.

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