// uncomment line below to run one of the mission tests
run_mission_test();
// uncomment line below to run the mission pause/resume test
//run_resume_test();
// wait forever
while(true) {
hal.scheduler->delay(1000);
}
}
// run_mission_test - tests the stop and resume feature
void run_mission_test()
{
// uncomment one of the init_xxx() commands below to run the test
init_mission(); // run simple mission with many nav commands and one do-jump
//init_mission_no_nav_commands(); // mission should start the first do command but then complete
//init_mission_endless_loop(); // mission should ignore the jump that causes the endless loop and complete
// mission with a do-jump to the previous command which is a "do" command
// ideally we would execute this previous "do" command the number of times specified in the do-jump command but this is tricky so we ignore the do-jump
// mission should run the "do" command once and then complete
//init_mission_jump_to_nonnav();
// mission which starts with do comamnds
// first command to execute should be the first do command followed by the first nav command
// second do command should execute after 1st do command completes
// third do command (which is after 1st nav command) should start after 1st nav command completes
//init_mission_starts_with_do_commands();
// init_mission_ends_with_do_commands - initialise a mission which ends with do comamnds
// a single do command just after nav command will be started but not verified because mission will complete
// final do command will not be started
//init_mission_ends_with_do_commands();
// init_mission_ends_with_jump_command - initialise a mission which ends with a jump comamnd
// mission should complete after the do-jump is executed the appropriate number of times
// init_mission_no_nav_commands - initialise a mission with no navigation commands
// mission should ignore the jump that causes the endless loop and complete
void init_mission_no_nav_commands()
{
AP_Mission::Mission_Command cmd;
// clear mission
mission.clear();
// Command #0 : "do" command
cmd.id = MAV_CMD_DO_SET_ROI;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 11;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #1 : "do" command
cmd.id = MAV_CMD_DO_CHANGE_SPEED;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 0;
cmd.content.location.lat = 0;
cmd.content.location.lng = 0;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #2 : "do" command
cmd.id = MAV_CMD_DO_SET_SERVO;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #3 : do-jump to first waypoint 3 times
cmd.id = MAV_CMD_DO_JUMP;
cmd.content.jump.target = 1;
cmd.content.jump.num_times = 1;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
}
// init_mission_endless_loop - initialise a mission with a do-jump that causes an endless loop
// mission should start the first do command but then complete
void init_mission_endless_loop()
{
AP_Mission::Mission_Command cmd;
// clear mission
mission.clear();
// Command #0 : do-jump command to itself
cmd.id = MAV_CMD_DO_JUMP;
cmd.content.jump.target = 0;
cmd.content.jump.num_times = 2;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #1 : take-off to 10m
cmd.id = MAV_CMD_NAV_TAKEOFF;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 10;
cmd.content.location.lat = 0;
cmd.content.location.lng = 0;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #2 : waypoint
cmd.id = MAV_CMD_NAV_WAYPOINT;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 11;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
}
// init_mission_jump_to_nonnav - initialise a mission with a do-jump to the previous command which is a "do" command
// ideally we would execute this previous "do" command the number of times specified in the do-jump command but this is tricky so we ignore the do-jump
// mission should run the "do" command once and then complete
void init_mission_jump_to_nonnav()
{
AP_Mission::Mission_Command cmd;
// clear mission
mission.clear();
// Command #0 : take-off to 10m
cmd.id = MAV_CMD_NAV_TAKEOFF;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 10;
cmd.content.location.lat = 0;
cmd.content.location.lng = 0;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #1 : do-roi command
cmd.id = MAV_CMD_DO_SET_ROI;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 11;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #2 : do-jump command to #1
cmd.id = MAV_CMD_DO_JUMP;
cmd.content.jump.target = 1;
cmd.content.jump.num_times = 2;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #3 : waypoint
cmd.id = MAV_CMD_NAV_WAYPOINT;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 22;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
}
// init_mission_starts_with_do_commands - initialise a mission which starts with do comamnds
// first command to execute should be the first do command followed by the first nav command
// second do command should execute after 1st do command completes
// third do command (which is after 1st nav command) should start after 1st nav command completes
void init_mission_starts_with_do_commands()
{
AP_Mission::Mission_Command cmd;
// clear mission
mission.clear();
// Command #0 : First "do" command
cmd.id = MAV_CMD_DO_SET_ROI;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 11;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #1 : Second "do" command
cmd.id = MAV_CMD_DO_CHANGE_SPEED;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 0;
cmd.content.location.lat = 0;
cmd.content.location.lng = 0;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #2 : take-off to 10m
cmd.id = MAV_CMD_NAV_TAKEOFF;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 10;
cmd.content.location.lat = 0;
cmd.content.location.lng = 0;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #3 : Third "do" command
cmd.id = MAV_CMD_DO_SET_ROI;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 22;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #4 : waypoint
cmd.id = MAV_CMD_NAV_WAYPOINT;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 33;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
}
// init_mission_ends_with_do_commands - initialise a mission which ends with do comamnds
// a single do command just after nav command will be started but not verified because mission will complete
// final do command will not be started
void init_mission_ends_with_do_commands()
{
AP_Mission::Mission_Command cmd;
// clear mission
mission.clear();
// Command #0 : take-off to 10m
cmd.id = MAV_CMD_NAV_TAKEOFF;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 10;
cmd.content.location.lat = 0;
cmd.content.location.lng = 0;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #1 : "do" command
cmd.id = MAV_CMD_DO_SET_ROI;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 22;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #2 : waypoint
cmd.id = MAV_CMD_NAV_WAYPOINT;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 33;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #3 : "do" command after last nav command (but not at end of mission)
cmd.id = MAV_CMD_DO_CHANGE_SPEED;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 0;
cmd.content.location.lat = 0;
cmd.content.location.lng = 0;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #4 : "do" command at end of mission
cmd.id = MAV_CMD_DO_SET_ROI;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 22;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
}
// init_mission_ends_with_jump_command - initialise a mission which ends with a jump comamnd
// mission should complete after the do-jump is executed the appropriate number of times
void init_mission_ends_with_jump_command()
{
AP_Mission::Mission_Command cmd;
// clear mission
mission.clear();
// Command #0 : take-off to 10m
cmd.id = MAV_CMD_NAV_TAKEOFF;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 10;
cmd.content.location.lat = 0;
cmd.content.location.lng = 0;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #1 : "do" command
cmd.id = MAV_CMD_DO_SET_ROI;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 22;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #2 : waypoint
cmd.id = MAV_CMD_NAV_WAYPOINT;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 33;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #3 : "do" command after last nav command (but not at end of mission)
cmd.id = MAV_CMD_DO_CHANGE_SPEED;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 0;
cmd.content.location.lat = 0;
cmd.content.location.lng = 0;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #4 : "do" command at end of mission
cmd.id = MAV_CMD_DO_SET_ROI;
cmd.content.location.options = 0;
cmd.content.location.p1 = 0;
cmd.content.location.alt = 22;
cmd.content.location.lat = 12345678;
cmd.content.location.lng = 23456789;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
// Command #5 : do-jump command to #2 two times
cmd.id = MAV_CMD_DO_JUMP;
cmd.content.jump.target = 2;
cmd.content.jump.num_times = 2;
if (!mission.add_cmd(cmd)) {
hal.console->printf_P(PSTR("failed to add command\n"));
}
}
// print_mission - print out the entire mission to the console