2011-09-08 22:29:39 -03:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
// Command Event Handlers
|
|
|
|
/********************************************************************************/
|
|
|
|
static void
|
2011-10-25 22:27:23 -03:00
|
|
|
handle_process_nav_cmd()
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
|
|
|
// reset navigation integrators
|
|
|
|
// -------------------------
|
|
|
|
reset_I();
|
|
|
|
|
2011-10-27 16:43:19 -03:00
|
|
|
gcs_send_text_fmt(PSTR("Executing command ID #%i"),next_nav_command.id);
|
2011-10-25 22:27:23 -03:00
|
|
|
switch(next_nav_command.id){
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
case MAV_CMD_NAV_TAKEOFF:
|
|
|
|
do_takeoff();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_WAYPOINT: // Navigate to Waypoint
|
|
|
|
do_nav_wp();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_LAND: // LAND to Waypoint
|
|
|
|
do_land();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_LOITER_UNLIM: // Loiter indefinitely
|
|
|
|
do_loiter_unlimited();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_LOITER_TURNS: // Loiter N Times
|
|
|
|
do_loiter_turns();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_LOITER_TIME:
|
|
|
|
do_loiter_time();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_RETURN_TO_LAUNCH:
|
|
|
|
do_RTL();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-25 22:27:23 -03:00
|
|
|
handle_process_condition_command()
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2011-10-27 16:43:19 -03:00
|
|
|
gcs_send_text_fmt(PSTR("Executing command ID #%i"),next_nonnav_command.id);
|
2011-10-25 22:27:23 -03:00
|
|
|
switch(next_nonnav_command.id){
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
case MAV_CMD_CONDITION_DELAY:
|
|
|
|
do_wait_delay();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_CONDITION_DISTANCE:
|
|
|
|
do_within_distance();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_CONDITION_CHANGE_ALT:
|
|
|
|
do_change_alt();
|
|
|
|
break;
|
|
|
|
|
2011-10-25 22:27:23 -03:00
|
|
|
/* case MAV_CMD_NAV_LAND_OPTIONS: // TODO - Add the command or equiv to MAVLink (repair in verify_condition() also)
|
2011-09-18 01:00:49 -03:00
|
|
|
gcs_send_text_P(SEVERITY_LOW,PSTR("Landing options set"));
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
// pitch in deg, airspeed m/s, throttle %, track WP 1 or 0
|
2011-10-25 22:27:23 -03:00
|
|
|
landing_pitch = next_nav_command.lng * 100;
|
|
|
|
g.airspeed_cruise = next_nav_command.alt * 100;
|
|
|
|
g.throttle_cruise = next_nav_command.lat;
|
|
|
|
landing_distance = next_nav_command.p1;
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
SendDebug_P("MSG: throttle_cruise = ");
|
|
|
|
SendDebugln(g.throttle_cruise,DEC);
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-25 22:27:23 -03:00
|
|
|
static void handle_process_do_command()
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2011-10-27 16:43:19 -03:00
|
|
|
gcs_send_text_fmt(PSTR("Executing command ID #%i"),next_nonnav_command.id);
|
2011-10-25 22:27:23 -03:00
|
|
|
switch(next_nonnav_command.id){
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
case MAV_CMD_DO_JUMP:
|
|
|
|
do_jump();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_DO_CHANGE_SPEED:
|
|
|
|
do_change_speed();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_DO_SET_HOME:
|
|
|
|
do_set_home();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_DO_SET_SERVO:
|
|
|
|
do_set_servo();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_DO_SET_RELAY:
|
|
|
|
do_set_relay();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_DO_REPEAT_SERVO:
|
|
|
|
do_repeat_servo();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_DO_REPEAT_RELAY:
|
|
|
|
do_repeat_relay();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_no_commands()
|
|
|
|
{
|
2011-10-27 16:43:19 -03:00
|
|
|
gcs_send_text_fmt(PSTR("Returning to Home"));
|
2011-10-25 22:27:23 -03:00
|
|
|
next_nav_command = home;
|
|
|
|
next_nav_command.alt = read_alt_to_hold();
|
|
|
|
next_nav_command.id = MAV_CMD_NAV_LOITER_UNLIM;
|
2011-10-27 16:43:19 -03:00
|
|
|
nav_command_ID = MAV_CMD_NAV_LOITER_UNLIM;
|
|
|
|
non_nav_command_ID = WAIT_COMMAND;
|
|
|
|
handle_process_nav_cmd();
|
|
|
|
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
// Verify command Handlers
|
|
|
|
/********************************************************************************/
|
|
|
|
|
2011-10-25 22:27:23 -03:00
|
|
|
static bool verify_nav_command() // Returns true if command complete
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
switch(nav_command_ID) {
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
case MAV_CMD_NAV_TAKEOFF:
|
|
|
|
return verify_takeoff();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_LAND:
|
|
|
|
return verify_land();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_WAYPOINT:
|
|
|
|
return verify_nav_wp();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_LOITER_UNLIM:
|
|
|
|
return verify_loiter_unlim();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_LOITER_TURNS:
|
|
|
|
return verify_loiter_turns();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_LOITER_TIME:
|
|
|
|
return verify_loiter_time();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_NAV_RETURN_TO_LAUNCH:
|
|
|
|
return verify_RTL();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-10-25 22:27:23 -03:00
|
|
|
gcs_send_text_P(SEVERITY_HIGH,PSTR("verify_nav: Invalid or no current Nav cmd"));
|
2011-09-08 22:29:39 -03:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-25 22:27:23 -03:00
|
|
|
static bool verify_condition_command() // Returns true if command complete
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
switch(non_nav_command_ID) {
|
2011-09-08 22:29:39 -03:00
|
|
|
case NO_COMMAND:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_CONDITION_DELAY:
|
|
|
|
return verify_wait_delay();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_CONDITION_DISTANCE:
|
|
|
|
return verify_within_distance();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MAV_CMD_CONDITION_CHANGE_ALT:
|
|
|
|
return verify_change_alt();
|
|
|
|
break;
|
2011-10-27 16:43:19 -03:00
|
|
|
|
|
|
|
case WAIT_COMMAND:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
default:
|
2011-10-25 22:27:23 -03:00
|
|
|
gcs_send_text_P(SEVERITY_HIGH,PSTR("verify_conditon: Invalid or no current Condition cmd"));
|
2011-09-08 22:29:39 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
// Nav (Must) commands
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
static void do_RTL(void)
|
|
|
|
{
|
|
|
|
control_mode = RTL;
|
|
|
|
crash_timer = 0;
|
|
|
|
next_WP = home;
|
|
|
|
|
|
|
|
// Altitude to hold over home
|
|
|
|
// Set by configuration tool
|
|
|
|
// -------------------------
|
|
|
|
next_WP.alt = read_alt_to_hold();
|
|
|
|
|
|
|
|
if (g.log_bitmask & MASK_LOG_MODE)
|
|
|
|
Log_Write_Mode(control_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_takeoff()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
set_next_WP(&next_nav_command);
|
2011-09-08 22:29:39 -03:00
|
|
|
// pitch in deg, airspeed m/s, throttle %, track WP 1 or 0
|
2011-10-25 22:27:23 -03:00
|
|
|
takeoff_pitch = (int)next_nav_command.p1 * 100;
|
2011-09-08 22:29:39 -03:00
|
|
|
//Serial.printf_P(PSTR("TO pitch:")); Serial.println(takeoff_pitch);
|
|
|
|
//Serial.printf_P(PSTR("home.alt:")); Serial.println(home.alt);
|
2011-10-25 22:27:23 -03:00
|
|
|
takeoff_altitude = next_nav_command.alt;
|
2011-09-08 22:29:39 -03:00
|
|
|
//Serial.printf_P(PSTR("takeoff_altitude:")); Serial.println(takeoff_altitude);
|
|
|
|
next_WP.lat = home.lat + 1000; // so we don't have bad calcs
|
|
|
|
next_WP.lng = home.lng + 1000; // so we don't have bad calcs
|
|
|
|
takeoff_complete = false; // set flag to use gps ground course during TO. IMU will be doing yaw drift correction
|
2011-09-28 00:14:42 -03:00
|
|
|
// Flag also used to override "on the ground" throttle disable
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_nav_wp()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
set_next_WP(&next_nav_command);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_land()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
set_next_WP(&next_nav_command);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_loiter_unlimited()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
set_next_WP(&next_nav_command);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_loiter_turns()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
set_next_WP(&next_nav_command);
|
|
|
|
loiter_total = next_nav_command.p1 * 360;
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_loiter_time()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
set_next_WP(&next_nav_command);
|
2011-09-08 22:29:39 -03:00
|
|
|
loiter_time = millis();
|
2011-10-25 22:27:23 -03:00
|
|
|
loiter_time_max = next_nav_command.p1; // units are (seconds * 10)
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
// Verify Nav (Must) commands
|
|
|
|
/********************************************************************************/
|
|
|
|
static bool verify_takeoff()
|
|
|
|
{
|
|
|
|
if (g_gps->ground_speed > 300){
|
|
|
|
if(hold_course == -1){
|
|
|
|
// save our current course to take off
|
|
|
|
if(g.compass_enabled) {
|
|
|
|
hold_course = dcm.yaw_sensor;
|
|
|
|
} else {
|
|
|
|
hold_course = g_gps->ground_course;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hold_course > -1){
|
|
|
|
// recalc bearing error with hold_course;
|
|
|
|
nav_bearing = hold_course;
|
|
|
|
// recalc bearing error
|
|
|
|
calc_bearing_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_loc.alt > takeoff_altitude) {
|
|
|
|
hold_course = -1;
|
|
|
|
takeoff_complete = true;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_land()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
// we don't verify landing - we never go to a new Nav command after Land
|
2011-09-08 22:29:39 -03:00
|
|
|
if (((wp_distance > 0) && (wp_distance <= (2*g_gps->ground_speed/100)))
|
|
|
|
|| (current_loc.alt <= next_WP.alt + 300)){
|
|
|
|
|
|
|
|
land_complete = 1; //Set land_complete if we are within 2 seconds distance or within 3 meters altitude
|
|
|
|
|
|
|
|
if(hold_course == -1){
|
|
|
|
// save our current course to land
|
|
|
|
//hold_course = yaw_sensor;
|
|
|
|
// save the course line of the runway to land
|
|
|
|
hold_course = crosstrack_bearing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hold_course > -1){
|
|
|
|
// recalc bearing error with hold_course;
|
|
|
|
nav_bearing = hold_course;
|
|
|
|
// recalc bearing error
|
|
|
|
calc_bearing_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
update_crosstrack();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_nav_wp()
|
|
|
|
{
|
|
|
|
hold_course = -1;
|
|
|
|
update_crosstrack();
|
|
|
|
if ((wp_distance > 0) && (wp_distance <= g.waypoint_radius)) {
|
2011-10-25 22:27:23 -03:00
|
|
|
gcs_send_text_fmt(PSTR("Reached Waypoint #%i"),nav_command_index);
|
2011-09-08 22:29:39 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// add in a more complex case
|
|
|
|
// Doug to do
|
|
|
|
if(loiter_sum > 300){
|
2011-09-18 05:02:33 -03:00
|
|
|
gcs_send_text_P(SEVERITY_MEDIUM,PSTR("Missed WP"));
|
2011-09-08 22:29:39 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_loiter_unlim()
|
|
|
|
{
|
|
|
|
update_loiter();
|
|
|
|
calc_bearing_error();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_loiter_time()
|
|
|
|
{
|
|
|
|
update_loiter();
|
|
|
|
calc_bearing_error();
|
|
|
|
if ((millis() - loiter_time) > (unsigned long)loiter_time_max * 10000l) { // scale loiter_time_max from (sec*10) to milliseconds
|
2011-10-25 22:27:23 -03:00
|
|
|
gcs_send_text_P(SEVERITY_LOW,PSTR("verify_nav: LOITER time complete"));
|
2011-09-08 22:29:39 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_loiter_turns()
|
|
|
|
{
|
|
|
|
update_loiter();
|
|
|
|
calc_bearing_error();
|
|
|
|
if(loiter_sum > loiter_total) {
|
|
|
|
loiter_total = 0;
|
2011-10-25 22:27:23 -03:00
|
|
|
gcs_send_text_P(SEVERITY_LOW,PSTR("verify_nav: LOITER orbits complete"));
|
2011-09-08 22:29:39 -03:00
|
|
|
// clear the command queue;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_RTL()
|
|
|
|
{
|
|
|
|
if (wp_distance <= g.waypoint_radius) {
|
2011-09-18 01:00:49 -03:00
|
|
|
gcs_send_text_P(SEVERITY_LOW,PSTR("Reached home"));
|
2011-09-08 22:29:39 -03:00
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
// Condition (May) commands
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
static void do_wait_delay()
|
|
|
|
{
|
|
|
|
condition_start = millis();
|
2011-10-25 22:27:23 -03:00
|
|
|
condition_value = next_nonnav_command.lat * 1000; // convert to milliseconds
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_change_alt()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
condition_rate = next_nonnav_command.lat;
|
|
|
|
condition_value = next_nonnav_command.alt;
|
2011-09-08 22:29:39 -03:00
|
|
|
target_altitude = current_loc.alt + (condition_rate / 10); // Divide by ten for 10Hz update
|
|
|
|
next_WP.alt = condition_value; // For future nav calculations
|
|
|
|
offset_altitude = 0; // For future nav calculations
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_within_distance()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
condition_value = next_nonnav_command.lat;
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
// Verify Condition (May) commands
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
static bool verify_wait_delay()
|
|
|
|
{
|
|
|
|
if ((unsigned)(millis() - condition_start) > condition_value){
|
|
|
|
condition_value = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_change_alt()
|
|
|
|
{
|
|
|
|
if( (condition_rate>=0 && current_loc.alt >= condition_value) || (condition_rate<=0 && current_loc.alt <= condition_value)) {
|
|
|
|
condition_value = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
target_altitude += condition_rate / 10;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_within_distance()
|
|
|
|
{
|
|
|
|
if (wp_distance < condition_value){
|
|
|
|
condition_value = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
// Do (Now) commands
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
static void do_loiter_at_location()
|
|
|
|
{
|
|
|
|
next_WP = current_loc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_jump()
|
|
|
|
{
|
|
|
|
struct Location temp;
|
2011-10-25 22:27:23 -03:00
|
|
|
if(next_nonnav_command.lat > 0) {
|
|
|
|
|
|
|
|
nav_command_ID = NO_COMMAND;
|
|
|
|
non_nav_command_ID = NO_COMMAND;
|
|
|
|
temp = get_cmd_with_index(g.command_index);
|
|
|
|
temp.lat = next_nonnav_command.lat - 1; // Decrement repeat counter
|
|
|
|
|
|
|
|
set_cmd_with_index(temp, g.command_index);
|
|
|
|
g.command_index.set_and_save(next_nonnav_command.p1 - 1);
|
|
|
|
} else if (next_nonnav_command.lat == -1) { // A repeat count of -1 = repeat forever
|
|
|
|
nav_command_ID = NO_COMMAND;
|
|
|
|
non_nav_command_ID = NO_COMMAND;
|
|
|
|
g.command_index.set_and_save(next_nonnav_command.p1 - 1);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_change_speed()
|
|
|
|
{
|
|
|
|
// Note: we have no implementation for commanded ground speed, only air speed and throttle
|
2011-10-25 22:27:23 -03:00
|
|
|
if(next_nonnav_command.alt > 0)
|
|
|
|
g.airspeed_cruise.set_and_save(next_nonnav_command.alt * 100);
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2011-10-25 22:27:23 -03:00
|
|
|
if(next_nonnav_command.lat > 0)
|
|
|
|
g.throttle_cruise.set_and_save(next_nonnav_command.lat);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_set_home()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
if(next_nonnav_command.p1 == 1 && GPS_enabled) {
|
2011-09-08 22:29:39 -03:00
|
|
|
init_home();
|
|
|
|
} else {
|
|
|
|
home.id = MAV_CMD_NAV_WAYPOINT;
|
2011-10-25 22:27:23 -03:00
|
|
|
home.lng = next_nonnav_command.lng; // Lon * 10**7
|
|
|
|
home.lat = next_nonnav_command.lat; // Lat * 10**7
|
|
|
|
home.alt = max(next_nonnav_command.alt, 0);
|
2011-09-08 22:29:39 -03:00
|
|
|
home_is_set = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_set_servo()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
APM_RC.OutputCh(next_nonnav_command.p1 - 1, next_nonnav_command.alt);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_set_relay()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
if (next_nonnav_command.p1 == 1) {
|
2011-10-01 19:55:41 -03:00
|
|
|
relay.on();
|
2011-10-25 22:27:23 -03:00
|
|
|
} else if (next_nonnav_command.p1 == 0) {
|
2011-10-01 19:55:41 -03:00
|
|
|
relay.off();
|
2011-09-08 22:29:39 -03:00
|
|
|
}else{
|
2011-10-01 19:55:41 -03:00
|
|
|
relay.toggle();
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_repeat_servo()
|
|
|
|
{
|
2011-10-25 22:27:23 -03:00
|
|
|
event_id = next_nonnav_command.p1 - 1;
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2011-10-25 22:27:23 -03:00
|
|
|
if(next_nonnav_command.p1 >= CH_5 + 1 && next_nonnav_command.p1 <= CH_8 + 1) {
|
2011-09-08 22:29:39 -03:00
|
|
|
|
|
|
|
event_timer = 0;
|
2011-10-25 22:27:23 -03:00
|
|
|
event_delay = next_nonnav_command.lng * 500.0; // /2 (half cycle time) * 1000 (convert to milliseconds)
|
|
|
|
event_repeat = next_nonnav_command.lat * 2;
|
|
|
|
event_value = next_nonnav_command.alt;
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2011-10-25 22:27:23 -03:00
|
|
|
switch(next_nonnav_command.p1) {
|
2011-09-08 22:29:39 -03:00
|
|
|
case CH_5:
|
|
|
|
event_undo_value = g.rc_5.radio_trim;
|
|
|
|
break;
|
|
|
|
case CH_6:
|
|
|
|
event_undo_value = g.rc_6.radio_trim;
|
|
|
|
break;
|
|
|
|
case CH_7:
|
|
|
|
event_undo_value = g.rc_7.radio_trim;
|
|
|
|
break;
|
|
|
|
case CH_8:
|
|
|
|
event_undo_value = g.rc_8.radio_trim;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
update_events();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_repeat_relay()
|
|
|
|
{
|
|
|
|
event_id = RELAY_TOGGLE;
|
|
|
|
event_timer = 0;
|
2011-10-25 22:27:23 -03:00
|
|
|
event_delay = next_nonnav_command.lat * 500.0; // /2 (half cycle time) * 1000 (convert to milliseconds)
|
|
|
|
event_repeat = next_nonnav_command.alt * 2;
|
2011-09-08 22:29:39 -03:00
|
|
|
update_events();
|
|
|
|
}
|