Exemplo n.º 1
0
DEFINE_THREAD_ROUTINE(drone_main_thread, data) {
  ardrone_tool_set_ui_pad_select(0); // Do not send any emergency signal
  ardrone_at_set_navdata_all();

//  Uint32 emergencyPulseStartTime = SDL_GetTicks() + EMERGENCY_SIGNAL_PULSE_DURATION;
//
//  int doRun = 1;
//
//  while (doRun) {
//    ardrone_tool_update();
//
//    pthread_mutex_lock(&drone_sharedDataMutex);
//    int emergencyPulseMS = SDL_GetTicks() - emergencyPulseStartTime;
//    if ((drone_emergency != drone_targetEmergency) && ((emergencyPulseMS > 2 * EMERGENCY_SIGNAL_PULSE_DURATION) || (emergencyPulseMS < EMERGENCY_SIGNAL_PULSE_DURATION))) {
//      ardrone_tool_set_ui_pad_select(1);
//
//      if (emergencyPulseMS > 2 * EMERGENCY_SIGNAL_PULSE_DURATION) {
//        emergencyPulseStartTime = SDL_GetTicks();
//      }
//    } else {
//      ardrone_tool_set_ui_pad_select(0);
//    }
//
//    doRun = drone_doRun;
//    pthread_mutex_unlock(&drone_sharedDataMutex);
//  }
//
  Uint32 startTime;

  // Enforce landing...
  startTime = SDL_GetTicks();
  while ((!drone_landed) && (SDL_GetTicks() - startTime < DRONE_LAND_WAIT_LIMIT)) {
    drone_land();
    ardrone_tool_update();
  }
  if (!drone_landed) {
    fprintf(stderr, "Warning! Drone could not land within %d seconds! Trying to set emergency flag...\n", DRONE_LAND_WAIT_LIMIT / 1000);
    startTime = SDL_GetTicks();
    while ((!(drone_emergency) || (drone_landed)) && (SDL_GetTicks() - startTime < DRONE_EMERGENCY_WAIT_LIMIT)) {
      drone_setEmergency(1);
      ardrone_tool_update();
    }

    if ((!(drone_emergency) || (drone_landed))) {
      fprintf(stderr, "Error! Drone could not land and no emergency flag could be set. If it is still flying: Good luck!\n");
    }
  }

  return 0;
}
Exemplo n.º 2
0
int main ()
{
	float CENTER = 79.5;
	float OFFSET = 0.05;
	
	drone_connect();
	
	enable_drone_vision();	
	drone_front_camera();
	
	sleep(2);
	
	drone_takeoff();
	
	printf("Black button to exit test loop and land the drone");
	
	float x, y;
	
	track_update();
	while(!black_button())
	{
		x = OFFSET * ((track_x(0,0) - CENTER) / CENTER);
		y = OFFSET * ((track_y(0,0) - CENTER) / CENTER);
		
		if(track_count(0) > 0)
		{
			printf("Items tracking: %d\n", track_count(0));
			drone_move(0,0, x, y);
		}
		els	
		{
			printf("No items: Hovering \n");
			drone_hover();
		}
		sleep(4);
		track_update();
	}
		
	printf("Landing");
	drone_move(0,0,0,-.25);
	sleep(0.5);
	
	drone_land();
	
	drone_disconnect();
	
	return 0;
}
Exemplo n.º 3
0
/*
 * Class:     Drone
 * Method:    land
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_cbccore_ARDrone_land(JNIEnv * env, jobject obj){
	
	drone_land();
}