View Single Post
  #5   Spotlight this post!  
Unread 02-08-2016, 08:34 PM
MaikeruKonare's Avatar
MaikeruKonare MaikeruKonare is offline
Programming Division Captain
AKA: Michael Conard
FRC #4237 (Team Lance-a-Bot)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2012
Location: Michigan
Posts: 15
MaikeruKonare is an unknown quantity at this point
Re: Wondering about GRIP

This is the sample code.

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\n", retval);
        else printf("fork okay continuing with parent robot code\n");
    }

    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.
Reply With Quote