Browse Source

Sub: Remove transect mode

This experimental mode is no longer relevant
master
Jacob Walser 8 years ago committed by Andrew Tridgell
parent
commit
840521ac8c
  1. 2
      ArduSub/GCS_Mavlink.cpp
  2. 6
      ArduSub/Parameters.cpp
  3. 14
      ArduSub/Parameters.h
  4. 2
      ArduSub/Sub.h
  5. 8
      ArduSub/config.h
  6. 249
      ArduSub/control_transect.cpp
  7. 1
      ArduSub/defines.h
  8. 18
      ArduSub/flight_mode.cpp

2
ArduSub/GCS_Mavlink.cpp

@ -53,7 +53,6 @@ NOINLINE void Sub::send_heartbeat(mavlink_channel_t chan) @@ -53,7 +53,6 @@ NOINLINE void Sub::send_heartbeat(mavlink_channel_t chan)
case GUIDED:
case CIRCLE:
case POSHOLD:
case TRANSECT:
base_mode |= MAV_MODE_FLAG_GUIDED_ENABLED;
// note that MAV_MODE_FLAG_AUTO_ENABLED does not match what
// APM does in any mode, as that is defined as "system finds its own goal
@ -149,7 +148,6 @@ NOINLINE void Sub::send_extended_status1(mavlink_channel_t chan) @@ -149,7 +148,6 @@ NOINLINE void Sub::send_extended_status1(mavlink_channel_t chan)
case SURFACE:
case OF_LOITER:
case POSHOLD:
case TRANSECT:
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_Z_ALTITUDE_CONTROL;
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_XY_POSITION_CONTROL;
break;

6
ArduSub/Parameters.cpp

@ -674,12 +674,6 @@ const AP_Param::Info Sub::var_info[] = { @@ -674,12 +674,6 @@ const AP_Param::Info Sub::var_info[] = {
// @User: Standard
GGROUP(p_pos_xy, "POS_XY_", AC_P),
#if TRANSECT_ENABLED == ENABLED
GGROUP(pid_crosstrack_control, "XTRACK_", AC_PID),
GGROUP(pid_heading_control, "HEAD_", AC_PID),
#endif
// variables not in the g class which contain EEPROM saved variables
#if CAMERA == ENABLED

14
ArduSub/Parameters.h

@ -367,14 +367,6 @@ public: @@ -367,14 +367,6 @@ public:
AC_P p_pos_xy;
AC_P p_alt_hold;
#if TRANSECT_ENABLED == ENABLED
AC_PID pid_crosstrack_control;
AC_PID pid_heading_control;
#endif
// Autotune
#if AUTOTUNE_ENABLED == ENABLED
AP_Int8 autotune_axis_bitmask;
@ -402,12 +394,6 @@ public: @@ -402,12 +394,6 @@ public:
p_alt_hold(ALT_HOLD_P)
#if TRANSECT_ENABLED == ENABLED
,
pid_crosstrack_control(XTRACK_P, XTRACK_I, XTRACK_D, XTRACK_IMAX, XTRACK_FILT_HZ, XTRACK_DT),
pid_heading_control(HEAD_P, HEAD_I, HEAD_D, HEAD_IMAX, HEAD_FILT_HZ, HEAD_DT)
#endif
{
}
};

2
ArduSub/Sub.h

@ -673,8 +673,6 @@ private: @@ -673,8 +673,6 @@ private:
bool poshold_init(bool ignore_checks);
void poshold_run();
bool transect_init(bool ignore_checks);
void transect_run();
bool stabilize_init(bool ignore_checks);
void stabilize_run();
bool manual_init(bool ignore_checks);

8
ArduSub/config.h

@ -103,14 +103,6 @@ @@ -103,14 +103,6 @@
# define RCMAP_ENABLED DISABLED
#endif
//////////////////////////////////////////////////////////////////////////////
// Experimental transect modes
//
#ifndef TRANSECT_ENABLED
# define TRANSECT_ENABLED DISABLED
#endif
//////////////////////////////////////////////////////////////////////////////
// Rangefinder
//

249
ArduSub/control_transect.cpp

@ -1,249 +0,0 @@ @@ -1,249 +0,0 @@
// ArduSub transect flight mode
// Sub follows a line according to current crosstrack error supplied by XTE NMEA sentence
// Requires GPS providing crosstrack error
// Jacob Walser August 2016
#include "Sub.h"
#include "version.h"
#include "GCS_Mavlink.h"
#if TRANSECT_ENABLED == ENABLED
namespace {
static uint32_t last_transect_message_ms = 0;
float des_velx = 0; // inav earth-frame desired velocity +/- = north/south
float des_vely = 0; // inav earth-frame desired velocity +/- = east/west
float des_velf = 0; // pilot body-frame desired velocity +/- = forward/backward
float des_velr = 0; // pilot body-frame desired velocity +/- = right/left
// Heading PID controller update interval
uint32_t last_pid_ms = 0;
uint8_t pid_dt = 1000/20;
}
// Initialize transect controller
bool Sub::transect_init(bool ignore_checks)
{
// fail to initialise transect mode if no GPS lock
if (!position_ok() && !ignore_checks) {
return false;
}
pos_control.init_xy_controller();
// set speed and acceleration from wpnav's speed and acceleration
pos_control.set_speed_xy(wp_nav.get_speed_xy());
pos_control.set_accel_xy(wp_nav.get_wp_acceleration());
pos_control.set_jerk_xy_to_default();
const Vector3f& curr_pos = inertial_nav.get_position();
const Vector3f& curr_vel = inertial_nav.get_velocity();
// set target position and velocity to current position and velocity
pos_control.set_xy_target(curr_pos.x, curr_pos.y);
pos_control.set_desired_velocity_xy(curr_vel.x, curr_vel.y);
// initialize vertical speeds and acceleration
pos_control.set_speed_z(-g.pilot_velocity_z_max, g.pilot_velocity_z_max);
pos_control.set_accel_z(g.pilot_accel_z);
// initialise position and desired velocity
pos_control.set_alt_target(inertial_nav.get_altitude());
pos_control.set_desired_velocity_z(inertial_nav.get_velocity_z());
last_pilot_heading = ahrs.yaw_sensor;
des_velf = 0;
des_velr = 0;
des_velx = 0;
des_vely = 0;
return true;
}
// should be called at 100hz or more
void Sub::transect_run()
{
uint32_t tnow = millis();
// convert inertial nav earth-frame velocities to body-frame
const Vector3f& vel = inertial_nav.get_velocity();
float vel_fw = vel.x*ahrs.cos_yaw() + vel.y*ahrs.sin_yaw();
float vel_right = -vel.x*ahrs.sin_yaw() + vel.y*ahrs.cos_yaw();
// if not auto armed or motor interlock not enabled set throttle to zero and exit immediately
if (!motors.armed() || !ap.auto_armed || !motors.get_interlock()) {
//reset targets
des_velf = 0;
des_velr = 0;
des_velx = 0;
des_vely = 0;
last_pilot_heading = ahrs.yaw_sensor;
motors.set_desired_spool_state(AP_Motors::DESIRED_SPIN_WHEN_ARMED);
attitude_control.set_throttle_out_unstabilized(0,true,g.throttle_filt);
pos_control.relax_alt_hold_controllers(motors.get_throttle_hover());
pos_control.set_pos_target(inertial_nav.get_position());
pos_control.set_desired_velocity(Vector3f(0,0,0));
return;
}
// apply SIMPLE mode transform to pilot inputs
update_simple_mode();
// set motors to full range
motors.set_desired_spool_state(AP_Motors::DESIRED_THROTTLE_UNLIMITED);
// get pilot's desired yaw rate in centidegrees per second
//float target_yaw_rate = get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
//int16_t xtrack_error = constrain_int16(-gps.crosstrack_error(), -4500, 4500);
int16_t xtrack_error = -channel_lateral->get_control_in() / 10;
double target_yaw_rate = get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
// get pilot desired climb rate
float target_climb_rate = get_pilot_desired_climb_rate(channel_throttle->get_control_in());
target_climb_rate = constrain_float(target_climb_rate, -g.pilot_velocity_z_max, g.pilot_velocity_z_max);
int16_t pilot_lateral = channel_lateral->get_control_in();
int16_t pilot_forward = channel_forward->get_control_in();
float lateral_out = 0;
float forward_out = 0;
// Pilot adjusts desired velocities to maintain during transect
if (pilot_lateral > 1000 || pilot_lateral < -1000 || pilot_forward > 1000 || pilot_forward < -1000) {
des_velf += pilot_forward * 0.0001;
des_velr += pilot_lateral * 0.0001;
// desired forward and right speeds in body-frame
des_velf = constrain_float(des_velf, -25.0, 25.0);
des_velr = constrain_float(des_velr, -25.0, 25.0);
}
// rotate pilot desired velocities to earth-frame
// forward velocity only (maintain zero lateral velocity)
des_vely = des_velf * ahrs.sin_yaw(); // +East / -West
des_velx = des_velf * ahrs.cos_yaw(); // +North / -South
// lateral velocity only (maintain zero forward velocity)
// des_vely = des_velr * ahrs.cos_yaw(); // +East / -West
// des_velx = -des_velr * ahrs.sin_yaw(); // +North / -South
//combined forward/lateral velocities
// des_vely = des_velf * ahrs.sin_yaw() + des_velr * ahrs.cos_yaw(); // +East / -West
// des_velx = des_velf * ahrs.cos_yaw() - des_velr * ahrs.sin_yaw(); // +North / -South
// set target position and velocity to current position and velocity
pos_control.set_desired_velocity_xy(des_velx, des_vely);
// run position controller
pos_control.update_xy_controller(AC_PosControl::XY_MODE_POS_AND_VEL_FF, ekfNavVelGainScaler, false);
// get pos_control forward and lateral outputs from wp_nav pitch and roll (from copter code)
float poscontrol_lateral = pos_control.get_roll(); //
float poscontrol_forward = -pos_control.get_pitch(); // output is reversed
// constrain target forward/lateral values
poscontrol_lateral = constrain_int16(poscontrol_lateral, -aparm.angle_max, aparm.angle_max);
poscontrol_forward = constrain_int16(poscontrol_forward, -aparm.angle_max, aparm.angle_max);
lateral_out = poscontrol_lateral/(float)aparm.angle_max;
forward_out = poscontrol_forward/(float)aparm.angle_max;
motors.set_lateral(lateral_out);
motors.set_forward(forward_out);
// convert pilot input to lean angles
// To-Do: convert get_pilot_desired_lean_angles to return angles as floats
float target_roll, target_pitch;
get_pilot_desired_lean_angles(channel_roll->get_control_in(), channel_pitch->get_control_in(), target_roll, target_pitch, aparm.angle_max);
int32_t error_heading = 0;
if (!is_zero(target_yaw_rate)) {
// Allow pilot to set approximate heading to maintain during transect
last_pilot_heading = ahrs.yaw_sensor;
last_pilot_yaw_input_ms = tnow;
} else {
// Set target heading after we have slowed to a stop after pilot input
if (tnow < last_pilot_yaw_input_ms + 250) {
target_yaw_rate = 0;
last_pilot_heading = ahrs.yaw_sensor;
} else {
// We are holding the current heading
error_heading = last_pilot_heading - ahrs.yaw_sensor;
// Wrap error 0~360 degrees
if (error_heading > 18000) {
error_heading = error_heading - 36000;
} else if (error_heading < -18000) {
error_heading = error_heading + 36000;
}
// Adjust heading to correct for crosstrack error
target_yaw_rate = g.pid_heading_control.get_pid() + g.pid_crosstrack_control.get_pid();
}
}
// Update crosstrack and heading controllers
if (tnow > last_pid_ms + pid_dt) {
last_pid_ms = tnow;
g.pid_heading_control.set_input_filter_all(error_heading);
//g.pid_crosstrack_control.set_input_filter_all(-channel_lateral->get_control_in());
g.pid_crosstrack_control.set_input_filter_all(xtrack_error);
}
// update attitude controller targets
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw(target_roll, target_pitch, target_yaw_rate, get_smoothing_gain());
// adjust climb rate using rangefinder
if (rangefinder_alt_ok()) {
// if rangefinder is ok, use surface tracking
target_climb_rate = get_surface_tracking_climb_rate(target_climb_rate, pos_control.get_alt_target(), G_Dt);
}
// call z axis position controller
if (ap.at_bottom) {
pos_control.relax_alt_hold_controllers(0.0); // clear velocity and position targets, and integrator
pos_control.set_alt_target(inertial_nav.get_altitude() + 10.0f); // set target to 10 cm above bottom
} else {
if (inertial_nav.get_altitude() < g.surface_depth) { // pilot allowed to move up or down freely
pos_control.set_alt_target_from_climb_rate_ff(target_climb_rate, G_Dt, false);
} else if (target_climb_rate < 0) { // pilot allowed to move only down freely
if (pos_control.get_vel_target_z() > 0) {
pos_control.relax_alt_hold_controllers(0); // reset target velocity and acceleration
}
pos_control.set_alt_target_from_climb_rate_ff(target_climb_rate, G_Dt, false);
} else if (pos_control.get_alt_target() > g.surface_depth) { // hold depth at surface level.
pos_control.set_alt_target(g.surface_depth);
}
}
pos_control.update_z_controller();
if (tnow > last_transect_message_ms + 200) {
last_transect_message_ms = tnow;
mavlink_msg_command_long_send(
(mavlink_channel_t)0, //channel
0, //target system
0, //target component
47, //command id
0, //confirmation
des_velf,//1
des_velr,
vel_fw,
vel_right,
forward_out,
lateral_out,
poscontrol_forward
);
//gcs_send_text_fmt(MAV_SEVERITY_INFO, "%ld, %ld, %ld, %f, %d", error_heading, ahrs.yaw_sensor, last_pilot_heading, target_yaw_rate, channel_lateral->get_control_in());
//gcs_send_text_fmt(MAV_SEVERITY_INFO, "%f, %f", g.pid_heading_control.get_pid(), g.pid_crosstrack_control.get_pid());
//gcs_send_text_fmt(MAV_SEVERITY_INFO, "%f, %ld, %ld, %f, %d", vel_fw, ahrs.yaw_sensor, last_pilot_heading, des_velf, gps.crosstrack_error());
}
}
#endif

1
ArduSub/defines.h

@ -100,7 +100,6 @@ enum control_mode_t { @@ -100,7 +100,6 @@ enum control_mode_t {
CIRCLE = 7, // not implemented in sub // automatic circular flight with automatic throttle
SURFACE = 9, // automatically return to surface, pilot maintains horizontal control
OF_LOITER = 10, // deprecated
TRANSECT = 13, // automatic x/y velocity, automatic heading/crosstrack error compensation, automatic depth/throttle
AUTOTUNE = 15, // not implemented in sub // automatically tune the vehicle's roll and pitch gains
POSHOLD = 16, // automatic position hold with manual override, with automatic throttle
MANUAL = 19 // Pass-through input with no stabilization

18
ArduSub/flight_mode.cpp

@ -57,12 +57,6 @@ bool Sub::set_mode(control_mode_t mode, mode_reason_t reason) @@ -57,12 +57,6 @@ bool Sub::set_mode(control_mode_t mode, mode_reason_t reason)
success = surface_init(ignore_checks);
break;
#if TRANSECT_ENABLED == ENABLED
case TRANSECT:
success = transect_init(ignore_checks);
break;
#endif
#if AUTOTUNE_ENABLED == ENABLED
case AUTOTUNE:
success = autotune_init(ignore_checks);
@ -156,12 +150,6 @@ void Sub::update_flight_mode() @@ -156,12 +150,6 @@ void Sub::update_flight_mode()
surface_run();
break;
#if TRANSECT_ENABLED == ENABLED
case TRANSECT:
transect_run();
break;
#endif
#if AUTOTUNE_ENABLED == ENABLED
case AUTOTUNE:
autotune_run();
@ -212,7 +200,6 @@ bool Sub::mode_requires_GPS(control_mode_t mode) @@ -212,7 +200,6 @@ bool Sub::mode_requires_GPS(control_mode_t mode)
case VELHOLD:
case CIRCLE:
case POSHOLD:
case TRANSECT:
return true;
default:
return false;
@ -240,7 +227,7 @@ bool Sub::mode_has_manual_throttle(control_mode_t mode) @@ -240,7 +227,7 @@ bool Sub::mode_has_manual_throttle(control_mode_t mode)
// arming_from_gcs should be set to true if the arming request comes from the ground station
bool Sub::mode_allows_arming(control_mode_t mode, bool arming_from_gcs)
{
if (mode_has_manual_throttle(mode) || mode == VELHOLD || mode == ALT_HOLD || mode == POSHOLD || mode == TRANSECT || (arming_from_gcs && mode == GUIDED)) {
if (mode_has_manual_throttle(mode) || mode == VELHOLD || mode == ALT_HOLD || mode == POSHOLD || (arming_from_gcs && mode == GUIDED)) {
return true;
}
return false;
@ -297,9 +284,6 @@ void Sub::print_flight_mode(AP_HAL::BetterStream *port, uint8_t mode) @@ -297,9 +284,6 @@ void Sub::print_flight_mode(AP_HAL::BetterStream *port, uint8_t mode)
case OF_LOITER:
port->print("OF_LOITER");
break;
case TRANSECT:
port->print("TRANSECT");
break;
case AUTOTUNE:
port->print("AUTOTUNE");
break;

Loading…
Cancel
Save