Wondering about GRIP

Hi we are new to vision this year, and have gotten GRIP to work for us.
We have gotten GRIP to get, process images, and give us info on network tables. We are at the point that we are ready to integrate GRIP into our code. We are just unsure of a couple of things.

  1. How to start GRIP from C++ code.
  2. How to get NetworkTables numbers into our code for processing.

Thanks in advance

The GRIP Wiki is located here: https://github.com/WPIRoboticsProjects/GRIP/wiki

thanks but i have been to the wiki and it is not much help. there is some code but no explanation and i don’t know enough to decipher it. if someone will please explain how to do these things too me like i’m five that would be great

The sample code is spawning a separate process via the fork() function and then executing a command line that is running a separate java grip program in that process.

The other part of the code is getting a subset of the network table containing the contour report and parsing it out.

This is the sample code.

#include <unistd.h>
#include <stdio.h>
#include "WPILib.h"

class MyRobot: public IterativeRobot
{
	std::shared_ptr<NetworkTable> grip;

    const char *JAVA = "/usr/local/frc/JRE/bin/java";

    char *GRIP_ARGS[5] = { "java", "-jar", "/home/lvuser/grip.jar", "/home/lvuser/project.grip", NULL };

public:

	MyRobot():grip(NetworkTable::GetTable("GRIP")){std::cout << "GRIP Test in Constructor" << std::endl;}

    void RobotInit() override {
    	std::cout << "GRIP Test in RobotInit" << std::endl;
        /* Run GRIP in a new process */
        int retval=fork();
        if ( retval == 0) {
        	// in the child process so start Java with the GRIP program
            if (execv(JAVA, GRIP_ARGS) == -1) {
                perror("Error running GRIP in new process");
            }
        }
        // in the parent process
        else if (retval == -1) printf("fork error returned to parent error %d
", retval);
        else printf("fork okay continuing with parent robot code
");
    }

    void AutonomousPeriodic() override {
    	std::cout << "GRIP Test in AutonomousPeriodoc" << std::endl;

    	double init[3];init[0]=2.3; init[1]=3.4;init[2]=4.5;

    	while(true){
    		/* Get published values from GRIP using NetworkTables */

    		auto areas = grip->GetNumberArray("MyTargetTable/area", llvm::ArrayRef<double>());
    		for (auto area : areas) {
    			std::cout << "Got contour with area=" << area << std::endl;
    		}

    		auto blobsx = grip->GetNumberArray("myBlobsReport/x", init /*llvm::ArrayRef<double>()*/);
    		for (auto blob : blobsx) {
    			std::cout << "Got blob with x=" << blob << std::endl;
    		}

    		auto blobsy = grip->GetNumberArray("myBlobsReport/y", init /*llvm::ArrayRef<double>()*/);
    		for (auto blob : blobsy) {
    			std::cout << "Got blob with y=" << blob << std::endl;
    		}

    		auto blobssize = grip->GetNumberArray("myBlobsReport/size", init /*llvm::ArrayRef<double>()*/);
    		for (auto blob : blobssize) {
    			std::cout << "Got blob with size=" << blob << std::endl;
    		}
    	}
   }
};

START_ROBOT_CLASS(MyRobot)

If you’re still having issues, the author of Grip has an account on ChiefDelphi. He will find you eventually and give you his pro advice.

Still having these problems

Could you explain what these problems are? There’s sample code for both of your questions here, but if there are any questions you have about it, I can answer them.