Beispiel #1
0
int main ()
{
    Joystick joystick(1);

    while (true)
    {
        // Restrict rate
        usleep(1000);

        // Attempt to sample an event from the joystick
        JoystickEvent event;
        if (joystick.sample(&event))
        {
            if (event.isButton())
            {
                printf("Button %u is %s\n", event.number, event.value == 0 ? "up" : "down");
            }
            else if (event.isAxis())
            {
                printf("Axis %u is at position %d\n", event.number, event.value);
            }
        }
    }

    return 0;

}
Beispiel #2
0
void joystickControl()
{
	// Attempt to sample an event from the joystick
    JoystickEvent event;
    if (joystick->sample(&event))
    {
      if (event.isButton())
      {
        printf("Button %u is %s\n",
          event.number,
          event.value == 0 ? "up" : "down");
      }
      else if (event.isAxis())
      {
        printf("Axis %u is at position %d\n", event.number, event.value);
		switch(event.number)
		{
			case 0:
				//balanceControl.spinSpeed =(float)event.value/JOYSTICK_AXIS_MAX;
				smonthSpinSpeed = (float)event.value/JOYSTICK_AXIS_MAX;
				//balanceControl.factorL = event.value/JOYSTICK_AXIS_MAX;
				//balanceControl.factorR = 1-balanceControl.factorL;
			break;
			case 1:
			break;
			case 2:		//右手左右
			break;
			case 3:		//右手前后
				//angle = axisToAngle(event.value);
				//printf("angle %f\r\n", angle);
				//servoSetAngle(&servoH, axisToAngle(event.value));
				smonthSpeed = -(float)event.value/JOYSTICK_AXIS_MAX * 10;
				
				//balanceControl.pidSpeed.desired = -(float)event.value/JOYSTICK_AXIS_MAX * 5;
			break;
		}
      }
  	}

  	balanceControl.pidSpeed.desired = LPF(balanceControl.pidSpeed.desired, smonthSpeed);
  	balanceControl.spinSpeed = LPF(balanceControl.spinSpeed, smonthSpinSpeed);

  	speed_need = LPF(speed_need, smonthSpeed);
}
Beispiel #3
0
 void check_controller(rov_context_t *context)
 {
     JoystickEvent event;
     bool result = context->joystick->sample(&event);
     if(result && !event.isInitialState())
     {
         if(event.isAxis())
         {
             int value = event.value;
             switch(event.number)
             {
                 case 0: // The x axis
                 {
                     x = value;
                     move_xy(context, x, y);
                 } break;
                 case 1: // The y axis
                 {
                     y = value;
                     move_xy(context, x, y);
                 } break;
                 case 2: // The twist axis
                 {
                     rotate_z(context, value);
                 } break;
                 case 3: // The kull axis
                 {
                     move_z(context, value);
                 } break;
                 case 4: // Top x-axis
                 {
                     top_x = value;
                     balance(context, top_x, top_y);
                 } break;
                 case 5: // Top y-axis
                 {
                     top_y = value;
                     balance(context, top_x, top_y);
                 } break;
             }
         }
         else if(event.isButton())
         {
             if (event.value)
             {
                 switch(event.number)
                 {
                     case 0:
                     {
                         rov_interface::control_gripper(context, 20);
                     } break;
                     case 1:
                     {
                         rov_interface::control_gripper(context, 150);
                     } break;
                     case 2:
                     {
                         rov_interface::switch_camera(context, 3);
                     } break;
                     case 3:
                     {
                         rov_interface::switch_camera(context, 4);
                     } break;
                     case 4:
                     {
                         rov_interface::switch_camera(context, 8);
                     } break;
                     case 8:
                     {
                         valve_opener_pwm -= 16;
                     } break;
                     case 9:
                     {
                         valve_opener_pwm += 16;
                     } break;
                 }
             }
             if (event.number == 10)
             {
                 rov_interface::set_motor(context, VALVE_OPENER, event.value, false, valve_opener_pwm);
             }
             else if (event.number == 11)
             {
                 rov_interface::set_motor(context, VALVE_OPENER, false, event.value, valve_opener_pwm);
             }
         }
     }
 }
Beispiel #4
0
int main(int argc, char *argv[])
{
	logOpen();
	initXWindows();
	init_opengl();
	init_sounds();
	load_sounds();
	Game game;
	gblock_info gbi;
	gbi.width = 8;
	gbi.height = 8;
	gbi.rows = 100;
	gbi.columns = 100;
	begin_game(game, gbi);
	Joystick joystick;
	init(&game);
	init_textures(game);
	printf("%f\n",game.Player_1.stats.color[0]);
	srand(time(NULL));
	clock_gettime(CLOCK_REALTIME, &timePause);
	clock_gettime(CLOCK_REALTIME, &timeStart);
	int done=0;
	while (!done) {
		while (XPending(dpy)) {
			XEvent e;
			XNextEvent(dpy, &e);
			check_resize(&e);
			check_mouse(&e, &game);
			done = check_keys(&e);
		}
		//Joystick events need to be checked outside of XPending(dpy)
		JoystickEvent event;
		if (joystick.sample(&event)) {
			if (event.isButton() || event.isAxis()){
				getJoystickEvent(event, joy, axis);
			}
		}
		clock_gettime(CLOCK_REALTIME, &timeCurrent);
		timeSpan = timeDiff(&timeStart, &timeCurrent);
		timeCopy(&timeStart, &timeCurrent);
		physicsCountdown += timeSpan;
		while (physicsCountdown >= physicsRate) {
			physics(&game);
			physicsCountdown -= physicsRate;
		}
		/*if (argc == 1) {
			if (titleScreen) {
				if (keys[XK_Return]) {
					enterPressed = keys[XK_Return];
				}
				if (keys[XK_Down]) {
					downPressed ^= keys[XK_Down];
					upPressed = 0;
					enterPressed = 0;
				}
				if (keys[XK_Up]) {
					upPressed ^= keys[XK_Up];
					downPressed = 0;
					enterPressed = 0;
				}
				titleScreen = renderTitleScreen(introTextures, introImages, 
								enterPressed, downPressed, upPressed, keys);
			} else if (Pause) {
	
			QUIT = PAUSE(&game, keys);
			if (QUIT)
				return(0);

		} else if (winCondition) {
				//test
					endCredits(&game, keys);
			} 
			else {
				glClearColor(0.8, 0.8, 0.8, 1.0);
				render(&game);
			}
		}  
		if (winCondition) {
			//test
				endCredits(&game, keys);
		}  
		else if (Pause) {
	
			QUIT = PAUSE(&game, keys);
			if (QUIT)
				return(0);

		} else {
		    glClearColor(0.8,0.8,0.8,1.0);
		    render(&game);
		}*/
		render(&game);
		glXSwapBuffers(dpy, win);
	}
	cleanupXWindows();
	cleanup_fonts();
	logClose();
	release_sounds();
	return 0;
}