void switch_event(byte switchPosition)
{
switch(switchPosition)
{
case 1: // First position
set_mode(MANUAL);
// this is handy function to restart your mission:
reset_waypoint_index();
break;
case 2: // middle position
set_mode(AUTO);
break;
case 3: // last position
set_mode(STABILIZE);
break;
}
}
void waypoint_event(byte event)
{
switch(event)
{
case EVENT_WILL_REACH_WAYPOINT:
// called just before wp_index is incemented
Serial.print("Reached WP:");
Serial.println(wp_index,DEC);
break;
case EVENT_SET_NEW_WAYPOINT_INDEX:
// called just after wp_index is incemented
Serial.print("Now going to WP:");
Serial.println(wp_index,DEC);
break;
case EVENT_LOADED_WAYPOINT:
// called just after wp is loaded from memory
Serial.print("Loaded WP index: ");
Serial.println(wp_index,DEC);
print_current_waypoint();
// custom loitering code
if (wp_index == 3){
set_mode(LOITER);
elapsedTime = 0;
}
break;
// called when the pattern to be flown is automatically restarted
case EVENT_LOOP:
Serial.println("Looped WP Index");
print_current_waypoint();
break;
}
}
// called AFTER every control loop void mainLoop_event(void)
{
if (control_mode == LOITER){
if (wp_index == 2 && elapsedTime > 120000 ){ // 2 minutes
elapsedTime = 0;
// our waypoints index is not altered during LOITER
// All we need to do is reload the waypoint
load_waypoint();
// and return to Autopilot mode!
set_mode(AUTO);
}
}
}

Comment by Sarel P. Wagner on December 25, 2009 at 1:12am 
Comment by Doug Erickson on December 26, 2009 at 10:54am 
Comment by Doug Erickson on December 26, 2009 at 12:43pm 

Comment
Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.24 members
1298 members
47 members
87 members
183 members
© 2013 Created by Chris Anderson.
Powered by

You need to be a member of DIY Drones to add comments!
Join DIY Drones