2011-03-08 08:20:48 -04:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// called by 10 Hz loop
|
|
|
|
// --------------------
|
|
|
|
void update_commands(void)
|
|
|
|
{
|
|
|
|
// This function loads commands into three buffers
|
|
|
|
// when a new command is loaded, it is processed with process_XXX()
|
|
|
|
// ----------------------------------------------------------------
|
2011-03-02 22:32:50 -04:00
|
|
|
if(home_is_set == false){
|
2010-12-19 12:40:33 -04:00
|
|
|
return; // don't do commands
|
|
|
|
}
|
2011-02-18 23:59:58 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
if(control_mode == AUTO){
|
2011-03-02 22:32:50 -04:00
|
|
|
load_next_command_from_EEPROM();
|
2010-12-19 12:40:33 -04:00
|
|
|
process_next_command();
|
2011-03-02 22:32:50 -04:00
|
|
|
}else if(control_mode == GCS_AUTO){
|
|
|
|
/*if( there is a command recieved )
|
|
|
|
process_next_command();
|
|
|
|
*/
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 22:32:50 -04:00
|
|
|
void verify_commands(void)
|
|
|
|
{
|
|
|
|
if(verify_must()){
|
|
|
|
command_must_index = NO_COMMAND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(verify_may()){
|
|
|
|
command_may_index = NO_COMMAND;
|
|
|
|
}
|
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-03-02 22:32:50 -04:00
|
|
|
void load_next_command_from_EEPROM()
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
2011-03-02 22:32:50 -04:00
|
|
|
// fetch next command if the next command queue is empty
|
|
|
|
// -----------------------------------------------------
|
|
|
|
if(next_command.id == NO_COMMAND){
|
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
next_command = get_wp_with_index(g.waypoint_index + 1);
|
2011-03-02 22:32:50 -04:00
|
|
|
|
|
|
|
//if(next_command.id != NO_COMMAND){
|
2011-02-18 23:59:58 -04:00
|
|
|
//SendDebug("MSG <load_next_command> fetch found new cmd from list at index ");
|
|
|
|
//SendDebug((g.waypoint_index + 1),DEC);
|
|
|
|
//SendDebug(" with cmd id ");
|
|
|
|
//SendDebugln(next_command.id,DEC);
|
2011-03-02 22:32:50 -04:00
|
|
|
//}
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2011-02-18 23:59:58 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// If the preload failed, return or just Loiter
|
|
|
|
// generate a dynamic command for RTL
|
|
|
|
// --------------------------------------------
|
2011-03-02 22:32:50 -04:00
|
|
|
if(next_command.id == NO_COMMAND){
|
2010-12-19 12:40:33 -04:00
|
|
|
// we are out of commands!
|
2011-02-18 23:59:58 -04:00
|
|
|
gcs.send_text(SEVERITY_LOW,"out of commands!");
|
|
|
|
//SendDebug("MSG <load_next_command> out of commands, g.waypoint_index: ");
|
|
|
|
//SendDebugln(g.waypoint_index,DEC);
|
2011-02-24 01:56:59 -04:00
|
|
|
handle_no_commands();
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void process_next_command()
|
|
|
|
{
|
|
|
|
// these are waypoint/Must commands
|
|
|
|
// ---------------------------------
|
|
|
|
if (command_must_index == 0){ // no current command loaded
|
2011-02-18 23:59:58 -04:00
|
|
|
if (next_command.id < MAV_CMD_NAV_LAST ){
|
2010-12-19 12:40:33 -04:00
|
|
|
increment_WP_index();
|
2011-02-18 23:59:58 -04:00
|
|
|
//save_command_index(); // to Recover from in air Restart
|
2011-02-17 03:09:13 -04:00
|
|
|
command_must_index = g.waypoint_index;
|
2011-02-18 23:59:58 -04:00
|
|
|
|
|
|
|
//SendDebug("MSG <process_next_command> new command_must_id ");
|
|
|
|
//SendDebug(next_command.id,DEC);
|
|
|
|
//SendDebug(" index:");
|
|
|
|
//SendDebugln(command_must_index,DEC);
|
|
|
|
if (g.log_bitmask & MASK_LOG_CMD)
|
2011-02-17 03:09:13 -04:00
|
|
|
Log_Write_Cmd(g.waypoint_index, &next_command);
|
2010-12-19 12:40:33 -04:00
|
|
|
process_must();
|
|
|
|
}
|
|
|
|
}
|
2011-02-18 23:59:58 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// these are May commands
|
|
|
|
// ----------------------
|
|
|
|
if (command_may_index == 0){
|
2011-02-18 23:59:58 -04:00
|
|
|
if (next_command.id > MAV_CMD_NAV_LAST && next_command.id < MAV_CMD_CONDITION_LAST ){
|
2010-12-19 12:40:33 -04:00
|
|
|
increment_WP_index();// this command is from the command list in EEPROM
|
2011-02-17 03:09:13 -04:00
|
|
|
command_may_index = g.waypoint_index;
|
2010-12-19 12:40:33 -04:00
|
|
|
//Serial.print("new command_may_index ");
|
|
|
|
//Serial.println(command_may_index,DEC);
|
2011-02-17 03:09:13 -04:00
|
|
|
if (g.log_bitmask & MASK_LOG_CMD)
|
|
|
|
Log_Write_Cmd(g.waypoint_index, &next_command);
|
2010-12-19 12:40:33 -04:00
|
|
|
process_may();
|
|
|
|
}
|
|
|
|
}
|
2011-02-18 23:59:58 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// these are do it now commands
|
|
|
|
// ---------------------------
|
2011-02-18 23:59:58 -04:00
|
|
|
if (next_command.id > MAV_CMD_CONDITION_LAST){
|
|
|
|
increment_WP_index();// this command is from the command list in EEPROM
|
2011-02-17 03:09:13 -04:00
|
|
|
if (g.log_bitmask & MASK_LOG_CMD)
|
2011-02-18 23:59:58 -04:00
|
|
|
Log_Write_Cmd(g.waypoint_index, &next_command);
|
2010-12-19 12:40:33 -04:00
|
|
|
process_now();
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 22:32:50 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
/*
|
|
|
|
These functions implement the waypoint commands.
|
|
|
|
*/
|
2011-03-02 22:32:50 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
void process_must()
|
|
|
|
{
|
2011-02-18 23:59:58 -04:00
|
|
|
//SendDebug("process must index: ");
|
|
|
|
//SendDebugln(command_must_index,DEC);
|
|
|
|
|
|
|
|
gcs.send_text(SEVERITY_LOW,"New cmd: <process_must>");
|
|
|
|
gcs.send_message(MSG_COMMAND_LIST, g.waypoint_index);
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
// clear May indexes
|
|
|
|
command_may_index = 0;
|
|
|
|
command_may_ID = 0;
|
|
|
|
|
|
|
|
command_must_ID = next_command.id;
|
|
|
|
|
2011-02-18 23:59:58 -04:00
|
|
|
// loads the waypoint into Next_WP struct
|
|
|
|
// --------------------------------------
|
2011-03-02 22:32:50 -04:00
|
|
|
//set_next_WP(&next_command);
|
2011-02-18 23:59:58 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// invalidate command so a new one is loaded
|
|
|
|
// -----------------------------------------
|
2011-03-02 22:32:50 -04:00
|
|
|
handle_process_must();
|
|
|
|
next_command.id = NO_COMMAND;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void process_may()
|
|
|
|
{
|
|
|
|
//Serial.print("process_may cmd# ");
|
2011-02-18 23:59:58 -04:00
|
|
|
//Serial.println(g.waypoint_index,DEC);
|
2010-12-19 12:40:33 -04:00
|
|
|
command_may_ID = next_command.id;
|
|
|
|
|
2011-02-18 23:59:58 -04:00
|
|
|
gcs.send_text(SEVERITY_LOW,"<process_may> New may command loaded:");
|
|
|
|
gcs.send_message(MSG_COMMAND_LIST, g.waypoint_index);
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-03-02 22:32:50 -04:00
|
|
|
handle_process_may();
|
|
|
|
|
|
|
|
// invalidate command so a new one is loaded
|
|
|
|
// -----------------------------------------
|
|
|
|
next_command.id = NO_COMMAND;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void process_now()
|
|
|
|
{
|
|
|
|
const float t5 = 100000.0;
|
|
|
|
//Serial.print("process_now cmd# ");
|
2011-02-17 03:09:13 -04:00
|
|
|
//Serial.println(g.waypoint_index,DEC);
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-03-02 22:32:50 -04:00
|
|
|
gcs.send_text(SEVERITY_LOW, "<process_now> New now command loaded: ");
|
|
|
|
gcs.send_message(MSG_COMMAND_LIST, g.waypoint_index);
|
|
|
|
handle_process_now();
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
// invalidate command so a new one is loaded
|
|
|
|
// -----------------------------------------
|
2011-03-02 22:32:50 -04:00
|
|
|
next_command.id = NO_COMMAND;
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|