Exemple #1
0
void freeScene(Scene * scene)
{
    freeCamera(scene->camera);
    freeWorld(scene->world);
    freeWater(scene->water);
    free(scene->context);
    free(scene);
    glfwTerminate();
}
///functions
int main(int argc, char* argv[])
{
	//input parameters
	if(argc != 3){
		printf("usage: %s <first ip> <second ip>\n", argv[0]);
        return EXIT_FAILURE;
	}
	//set Kinect angles to 0° & set LED colour
	if(freenect_sync_set_tilt_degs(0, 0)){
        printf("Could not tilt device 0.\n");
        return EXIT_FAILURE;
	}
	if(freenect_sync_set_led(LED_GREEN, 0)){
        printf("Could not change LED of device 0.\n");
        return EXIT_FAILURE;
	}
	//set UDP socket
	struct sockaddr_in si_other, si_other2;
	int s, i, slen=sizeof(si_other);
	char buf[BUFLEN];
	if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1){
		fprintf(stderr, "socket() failed\n");
		return 1;
	}
	//first IP
	memset((char *) &si_other, 0, sizeof(si_other));
	si_other.sin_family = AF_INET;
	si_other.sin_port = htons(PORT);
	if (inet_aton(argv[1], &si_other.sin_addr)==0) {
		fprintf(stderr, "inet_aton() failed\n");
		return 1;
	}
	//second IP
	memset((char *) &si_other2, 0, sizeof(si_other2));
	si_other2.sin_family = AF_INET;
	si_other2.sin_port = htons(PORT);
	if (inet_aton(argv[2], &si_other2.sin_addr)==0) {
		fprintf(stderr, "inet_aton() failed\n");
		return 1;
	}
	//set cameras
	TDepthCamera mainCam;
	createPrimaryCamera(&mainCam, 0);
	//get calibration values acquired by calibration program.
	FILE* pFile = NULL;
	pFile = fopen("calibrationValuesOne.cal", "r");
	if(pFile == NULL){
		puts("Could not get calibration data.");
	}else{
		fread(&minZ, sizeof(int), 1, pFile);
		fread(&maxZ, sizeof(int), 1, pFile);
	}
	fclose(pFile);
	TVecList mainList;
	unsigned int timestamp;
	contLoop = 1;
	//show current calibration values.
	printf("Current calibration values:\nCeiling: %d, Floor: %d\n", maxZ, minZ);
	puts("\n\nAre those values correct? [Y/N]");
	char tmpChar = getchar();
	if(tmpChar == 'N' || tmpChar == 'n'){
        contLoop = 0;
        puts("\nUse calibration program to correct the values.");
	}
	fflush(stdin);
	//start thread
	pthread_t thread;
	int rc;
	long t = 0;
	rc = pthread_create(&thread, NULL, readAsync, (void *)t);
	if (rc){
		printf("ERROR; return code from pthread_create() is %d\n", rc);
		exit(-1);
	}
	//main loop
	while(contLoop){
		//acquire data for main Kinect & process data
		if(updateCamera(&mainCam, &timestamp)){
            printf("Could not update feed for device 0.");
            return EXIT_FAILURE;
		}
		if(detectDrone(mainCam.data, &mainList, &vec3DDistance)){
            printf("Could not process data for for device 0.");
            return EXIT_FAILURE;
		}
		//display list
		system("clear");
		puts("Press Enter to exit.\n\n---------------\nLIST:");
		displayVecList(&mainList);
		//send position to the given IP address
		TVec4D* maxVect = maxPointList(&mainList);
		if(maxVect != NULL){
            writePacket(buf, 'k', maxVect->x, maxVect->y, maxVect->z);
			if (sendto(s, buf, BUFLEN, 0, &si_other, slen)==-1){
				fprintf(stderr, "sendto() failed\n");
				return 1;
			}
			if (sendto(s, buf, BUFLEN, 0, &si_other2, slen)==-1){
				fprintf(stderr, "sendto() failed\n");
				return 1;
			}
		}
	}
	//close socket
	close(s);
	//free all data
	freeCamera(&mainCam);
	//stop kinects
	freenect_sync_stop();
	//stop pthread
	pthread_exit(NULL);
	return EXIT_SUCCESS;
}