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.