2011-03-19 07:20:11 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2011-02-24 01:56:59 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// These are function definitions so the Menu can be constructed before the functions
|
|
|
|
// are defined below. Order matters to the compiler.
|
|
|
|
static int8_t test_radio_pwm(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_radio(uint8_t argc, const Menu::arg *argv);
|
2011-01-22 16:25:14 -04:00
|
|
|
static int8_t test_failsafe(uint8_t argc, const Menu::arg *argv);
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t test_stabilize(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_gps(uint8_t argc, const Menu::arg *argv);
|
2011-01-02 16:34:42 -04:00
|
|
|
static int8_t test_adc(uint8_t argc, const Menu::arg *argv);
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t test_imu(uint8_t argc, const Menu::arg *argv);
|
2011-02-24 01:56:59 -04:00
|
|
|
//static int8_t test_dcm(uint8_t argc, const Menu::arg *argv);
|
2011-03-07 02:00:27 -04:00
|
|
|
//static int8_t test_omega(uint8_t argc, const Menu::arg *argv);
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t test_battery(uint8_t argc, const Menu::arg *argv);
|
2011-01-16 23:44:12 -04:00
|
|
|
static int8_t test_current(uint8_t argc, const Menu::arg *argv);
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t test_relay(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_wp(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_pressure(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_mag(uint8_t argc, const Menu::arg *argv);
|
2011-03-17 22:50:27 -03:00
|
|
|
static int8_t test_sonar(uint8_t argc, const Menu::arg *argv);
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t test_xbee(uint8_t argc, const Menu::arg *argv);
|
|
|
|
static int8_t test_eedump(uint8_t argc, const Menu::arg *argv);
|
2011-03-11 17:37:37 -04:00
|
|
|
static int8_t test_rawgps(uint8_t argc, const Menu::arg *argv);
|
2011-03-26 03:35:52 -03:00
|
|
|
static int8_t test_mission(uint8_t argc, const Menu::arg *argv);
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
// This is the help function
|
|
|
|
// PSTR is an AVR macro to read strings from flash memory
|
|
|
|
// printf_P is a version of printf that reads from flash memory
|
|
|
|
/*static int8_t help_test(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
Serial.printf_P(PSTR("\n"
|
|
|
|
"Commands:\n"
|
|
|
|
" radio\n"
|
|
|
|
" servos\n"
|
2011-02-17 05:36:33 -04:00
|
|
|
" g_gps\n"
|
2010-12-19 12:40:33 -04:00
|
|
|
" imu\n"
|
|
|
|
" battery\n"
|
|
|
|
"\n"));
|
|
|
|
}*/
|
|
|
|
|
|
|
|
// Creates a constant array of structs representing menu options
|
|
|
|
// and stores them in Flash memory, not RAM.
|
|
|
|
// User enters the string in the console to call the functions on the right.
|
|
|
|
// See class Menu in AP_Coommon for implementation details
|
|
|
|
const struct Menu::command test_menu_commands[] PROGMEM = {
|
|
|
|
{"pwm", test_radio_pwm},
|
|
|
|
{"radio", test_radio},
|
2011-01-22 16:25:14 -04:00
|
|
|
{"failsafe", test_failsafe},
|
2010-12-19 12:40:33 -04:00
|
|
|
{"stabilize", test_stabilize},
|
|
|
|
{"gps", test_gps},
|
2011-03-03 07:39:52 -04:00
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE
|
2011-01-02 16:34:42 -04:00
|
|
|
{"adc", test_adc},
|
2011-03-03 07:39:52 -04:00
|
|
|
#endif
|
2010-12-19 12:40:33 -04:00
|
|
|
{"imu", test_imu},
|
2011-02-24 01:56:59 -04:00
|
|
|
//{"dcm", test_dcm},
|
2011-03-07 02:00:27 -04:00
|
|
|
//{"omega", test_omega},
|
2010-12-19 12:40:33 -04:00
|
|
|
{"battery", test_battery},
|
2011-01-16 23:44:12 -04:00
|
|
|
{"current", test_current},
|
2010-12-19 12:40:33 -04:00
|
|
|
{"relay", test_relay},
|
|
|
|
{"waypoints", test_wp},
|
2011-03-03 07:39:52 -04:00
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE
|
2010-12-19 12:40:33 -04:00
|
|
|
{"airpressure", test_pressure},
|
2011-03-03 07:39:52 -04:00
|
|
|
#endif
|
2011-03-17 22:50:27 -03:00
|
|
|
{"sonar", test_sonar},
|
2010-12-19 12:40:33 -04:00
|
|
|
{"compass", test_mag},
|
|
|
|
{"xbee", test_xbee},
|
2011-02-17 05:36:33 -04:00
|
|
|
{"eedump", test_eedump},
|
2011-03-11 17:37:37 -04:00
|
|
|
{"rawgps", test_rawgps},
|
2011-03-26 03:35:52 -03:00
|
|
|
{"mission", test_mission},
|
2010-12-19 12:40:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// A Macro to create the Menu
|
|
|
|
MENU(test_menu, "test", test_menu_commands);
|
|
|
|
|
|
|
|
int8_t
|
|
|
|
test_mode(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
Serial.printf_P(PSTR("Test Mode\n\n"));
|
|
|
|
test_menu.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_eedump(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
// hexdump the EEPROM
|
|
|
|
for (i = 0; i < EEPROM_MAX_ADDR; i += 16) {
|
|
|
|
Serial.printf_P(PSTR("%04x:"), i);
|
|
|
|
for (j = 0; j < 16; j++)
|
|
|
|
Serial.printf_P(PSTR(" %02x"), eeprom_read_byte((const uint8_t *)(i + j)));
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_radio_pwm(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
while(1){
|
|
|
|
delay(20);
|
|
|
|
|
|
|
|
// Filters radio input - adjust filters in the radio.pde file
|
|
|
|
// ----------------------------------------------------------
|
|
|
|
read_radio();
|
|
|
|
|
2011-02-24 01:56:59 -04:00
|
|
|
Serial.printf_P(PSTR("IN: 1: %d\t2: %d\t3: %d\t4: %d\t5: %d\t6: %d\t7: %d\t8: %d\n"),
|
|
|
|
g.rc_1.radio_in,
|
|
|
|
g.rc_2.radio_in,
|
|
|
|
g.rc_3.radio_in,
|
|
|
|
g.rc_4.radio_in,
|
|
|
|
g.rc_5.radio_in,
|
|
|
|
g.rc_6.radio_in,
|
|
|
|
g.rc_7.radio_in,
|
|
|
|
g.rc_8.radio_in);
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_radio(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
2010-12-26 20:35:08 -04:00
|
|
|
output_manual_throttle();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
g.rc_1.calc_pwm();
|
|
|
|
g.rc_2.calc_pwm();
|
|
|
|
g.rc_3.calc_pwm();
|
|
|
|
g.rc_4.calc_pwm();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-24 01:56:59 -04:00
|
|
|
Serial.printf_P(PSTR("IN 1: %d\t2: %d\t3: %d\t4: %d\t5: %d\t6: %d\t7: %d\n"),
|
2011-03-02 22:32:50 -04:00
|
|
|
g.rc_1.control_in,
|
|
|
|
g.rc_2.control_in,
|
|
|
|
g.rc_3.control_in,
|
|
|
|
g.rc_4.control_in,
|
2011-02-24 01:56:59 -04:00
|
|
|
g.rc_5.control_in,
|
|
|
|
g.rc_6.control_in,
|
|
|
|
g.rc_7.control_in);
|
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
//Serial.printf_P(PSTR("OUT 1: %d\t2: %d\t3: %d\t4: %d\n"), (g.rc_1.servo_out / 100), (g.rc_2.servo_out / 100), g.rc_3.servo_out, (g.rc_4.servo_out / 100));
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-28 21:36:30 -04:00
|
|
|
/*Serial.printf_P(PSTR( "min: %d"
|
2010-12-26 20:35:08 -04:00
|
|
|
"\t in: %d"
|
|
|
|
"\t pwm_in: %d"
|
|
|
|
"\t sout: %d"
|
|
|
|
"\t pwm_out %d\n"),
|
2011-02-17 05:36:33 -04:00
|
|
|
g.rc_3.radio_min,
|
2011-02-17 03:09:13 -04:00
|
|
|
g.rc_3.control_in,
|
|
|
|
g.rc_3.radio_in,
|
|
|
|
g.rc_3.servo_out,
|
|
|
|
g.rc_3.pwm_out
|
2010-12-26 20:35:08 -04:00
|
|
|
);
|
2010-12-28 21:36:30 -04:00
|
|
|
*/
|
2010-12-19 12:40:33 -04:00
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-22 16:25:14 -04:00
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_failsafe(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
byte fail_test;
|
|
|
|
print_hit_enter();
|
|
|
|
for(int i = 0; i < 50; i++){
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-22 16:25:14 -04:00
|
|
|
oldSwitchPosition = readSwitch();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-25 01:53:36 -04:00
|
|
|
Serial.printf_P(PSTR("Unplug battery, throttle in neutral, turn off radio.\n"));
|
2011-02-17 03:09:13 -04:00
|
|
|
while(g.rc_3.control_in > 0){
|
2011-01-26 03:14:54 -04:00
|
|
|
delay(20);
|
|
|
|
read_radio();
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-22 16:25:14 -04:00
|
|
|
while(1){
|
|
|
|
delay(20);
|
|
|
|
read_radio();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
if(g.rc_3.control_in > 0){
|
|
|
|
Serial.printf_P(PSTR("THROTTLE CHANGED %d \n"), g.rc_3.control_in);
|
2011-01-22 16:25:14 -04:00
|
|
|
fail_test++;
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-22 16:25:14 -04:00
|
|
|
if(oldSwitchPosition != readSwitch()){
|
2011-01-26 03:14:54 -04:00
|
|
|
Serial.printf_P(PSTR("CONTROL MODE CHANGED: "));
|
2011-01-22 16:25:14 -04:00
|
|
|
Serial.println(flight_mode_strings[readSwitch()]);
|
|
|
|
fail_test++;
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-19 22:03:01 -04:00
|
|
|
if(g.throttle_fs_enabled && g.rc_3.get_failsafe()){
|
2011-02-17 03:09:13 -04:00
|
|
|
Serial.printf_P(PSTR("THROTTLE FAILSAFE ACTIVATED: %d, "), g.rc_3.radio_in);
|
2011-01-22 16:25:14 -04:00
|
|
|
Serial.println(flight_mode_strings[readSwitch()]);
|
|
|
|
fail_test++;
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-22 16:25:14 -04:00
|
|
|
if(fail_test > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if(Serial.available() > 0){
|
|
|
|
Serial.printf_P(PSTR("LOS caused no change in ACM.\n"));
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t
|
|
|
|
test_stabilize(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2011-01-02 16:34:42 -04:00
|
|
|
static byte ts_num;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-27 19:09:08 -04:00
|
|
|
// setup the radio
|
|
|
|
// ---------------
|
|
|
|
init_rc_in();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
control_mode = STABILIZE;
|
2011-02-17 03:09:13 -04:00
|
|
|
Serial.printf_P(PSTR("g.pid_stabilize_roll.kP: %4.4f\n"), g.pid_stabilize_roll.kP());
|
2010-12-19 12:40:33 -04:00
|
|
|
Serial.printf_P(PSTR("max_stabilize_dampener:%d\n\n "), max_stabilize_dampener);
|
2010-12-27 19:09:08 -04:00
|
|
|
|
2011-01-25 01:53:36 -04:00
|
|
|
motor_auto_safe = false;
|
|
|
|
motor_armed = true;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
while(1){
|
|
|
|
// 50 hz
|
2011-01-02 16:34:42 -04:00
|
|
|
if (millis() - fast_loopTimer > 19) {
|
2011-01-17 22:48:44 -04:00
|
|
|
delta_ms_fast_loop = millis() - fast_loopTimer;
|
2010-12-19 12:40:33 -04:00
|
|
|
fast_loopTimer = millis();
|
2011-01-17 22:48:44 -04:00
|
|
|
G_Dt = (float)delta_ms_fast_loop / 1000.f;
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
if(g.compass_enabled){
|
2010-12-19 12:40:33 -04:00
|
|
|
medium_loopCounter++;
|
|
|
|
if(medium_loopCounter == 5){
|
|
|
|
compass.read(); // Read magnetometer
|
2011-02-17 03:09:13 -04:00
|
|
|
compass.calculate(dcm.roll, dcm.pitch); // Calculate heading
|
2011-03-07 15:06:29 -04:00
|
|
|
compass.null_offsets(dcm.get_dcm_matrix());
|
2010-12-19 12:40:33 -04:00
|
|
|
medium_loopCounter = 0;
|
|
|
|
}
|
|
|
|
}
|
2011-02-19 22:03:01 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// for trim features
|
|
|
|
read_trim_switch();
|
|
|
|
|
|
|
|
// Filters radio input - adjust filters in the radio.pde file
|
|
|
|
// ----------------------------------------------------------
|
|
|
|
read_radio();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// IMU
|
|
|
|
// ---
|
|
|
|
read_AHRS();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-02 16:34:42 -04:00
|
|
|
// allow us to zero out sensors with control switches
|
2011-02-17 03:09:13 -04:00
|
|
|
if(g.rc_5.control_in < 600){
|
2011-01-25 01:53:36 -04:00
|
|
|
dcm.roll_sensor = dcm.pitch_sensor = 0;
|
2011-01-02 16:34:42 -04:00
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// custom code/exceptions for flight modes
|
|
|
|
// ---------------------------------------
|
|
|
|
update_current_flight_mode();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// write out the servo PWM values
|
|
|
|
// ------------------------------
|
|
|
|
set_servos_4();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-02 16:34:42 -04:00
|
|
|
ts_num++;
|
2011-03-07 02:00:27 -04:00
|
|
|
if (ts_num > 10){
|
2011-01-02 16:34:42 -04:00
|
|
|
ts_num = 0;
|
2011-02-06 03:01:30 -04:00
|
|
|
Serial.printf_P(PSTR("r: %d, p:%d, rc1:%d, "),
|
2011-01-25 01:53:36 -04:00
|
|
|
(int)(dcm.roll_sensor/100),
|
|
|
|
(int)(dcm.pitch_sensor/100),
|
2011-02-17 03:09:13 -04:00
|
|
|
g.rc_1.pwm_out);
|
2011-01-12 21:31:05 -04:00
|
|
|
|
2011-03-07 02:00:27 -04:00
|
|
|
print_motor_out();
|
2011-01-02 16:34:42 -04:00
|
|
|
}
|
|
|
|
// R: 1417, L: 1453 F: 1453 B: 1417
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-25 01:53:36 -04:00
|
|
|
//Serial.printf_P(PSTR("timer: %d, r: %d\tp: %d\t y: %d\n"), (int)delta_ms_fast_loop, ((int)dcm.roll_sensor/100), ((int)dcm.pitch_sensor/100), ((uint16_t)dcm.yaw_sensor/100));
|
|
|
|
//Serial.printf_P(PSTR("timer: %d, r: %d\tp: %d\t y: %d\n"), (int)delta_ms_fast_loop, ((int)dcm.roll_sensor/100), ((int)dcm.pitch_sensor/100), ((uint16_t)dcm.yaw_sensor/100));
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
if(Serial.available() > 0){
|
2011-03-07 15:06:29 -04:00
|
|
|
if(g.compass_enabled){
|
|
|
|
compass.save_offsets();
|
2011-03-27 18:26:34 -03:00
|
|
|
report_compass();
|
2011-03-07 15:06:29 -04:00
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
return (0);
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-26 03:14:54 -04:00
|
|
|
|
2011-03-03 07:39:52 -04:00
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE
|
2011-01-02 16:34:42 -04:00
|
|
|
static int8_t
|
|
|
|
test_adc(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
adc.Init();
|
|
|
|
delay(1000);
|
|
|
|
Serial.printf_P(PSTR("ADC\n"));
|
|
|
|
delay(1000);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-02 16:34:42 -04:00
|
|
|
while(1){
|
|
|
|
for(int i = 0; i < 9; i++){
|
|
|
|
Serial.printf_P(PSTR("i:%d\t"),adc.Ch(i));
|
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
delay(20);
|
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-03 07:39:52 -04:00
|
|
|
#endif
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t
|
|
|
|
test_imu(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
//Serial.printf_P(PSTR("Calibrating."));
|
|
|
|
|
2011-02-20 19:09:28 -04:00
|
|
|
report_imu();
|
2010-12-19 12:40:33 -04:00
|
|
|
imu.init_gyro();
|
2011-02-20 19:09:28 -04:00
|
|
|
report_imu();
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-13 18:32:34 -04:00
|
|
|
//float cos_roll, sin_roll, cos_pitch, sin_pitch, cos_yaw, sin_yaw;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
while(1){
|
|
|
|
delay(20);
|
|
|
|
if (millis() - fast_loopTimer > 19) {
|
2011-01-17 22:48:44 -04:00
|
|
|
delta_ms_fast_loop = millis() - fast_loopTimer;
|
|
|
|
G_Dt = (float)delta_ms_fast_loop / 1000.f; // used by DCM integrator
|
2010-12-19 12:40:33 -04:00
|
|
|
fast_loopTimer = millis();
|
2011-02-13 18:32:34 -04:00
|
|
|
/*
|
2011-02-10 03:10:24 -04:00
|
|
|
Matrix3f temp = dcm.get_dcm_matrix();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-10 03:10:24 -04:00
|
|
|
sin_pitch = -temp.c.x;
|
|
|
|
cos_pitch = sqrt(1 - (temp.c.x * temp.c.x));
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-10 03:10:24 -04:00
|
|
|
cos_roll = temp.c.z / cos_pitch;
|
|
|
|
sin_roll = temp.c.y / cos_pitch;
|
|
|
|
|
|
|
|
yawvector.x = temp.a.x; // sin
|
|
|
|
yawvector.y = temp.b.x; // cos
|
|
|
|
yawvector.normalize();
|
|
|
|
cos_yaw = yawvector.y; // 0 x = north
|
2011-02-17 05:36:33 -04:00
|
|
|
sin_yaw = yawvector.x; // 1 y
|
2011-02-13 18:32:34 -04:00
|
|
|
*/
|
2011-02-10 03:10:24 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// IMU
|
|
|
|
// ---
|
|
|
|
read_AHRS();
|
|
|
|
|
|
|
|
Vector3f accels = imu.get_accel();
|
|
|
|
Vector3f gyros = imu.get_gyro();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
if(g.compass_enabled){
|
2010-12-19 12:40:33 -04:00
|
|
|
medium_loopCounter++;
|
|
|
|
if(medium_loopCounter == 5){
|
|
|
|
compass.read(); // Read magnetometer
|
2011-02-17 03:09:13 -04:00
|
|
|
compass.calculate(dcm.roll, dcm.pitch); // Calculate heading
|
2010-12-19 12:40:33 -04:00
|
|
|
medium_loopCounter = 0;
|
|
|
|
}
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
// We are using the IMU
|
|
|
|
// ---------------------
|
2011-02-24 01:56:59 -04:00
|
|
|
/*
|
2011-01-12 21:31:05 -04:00
|
|
|
Serial.printf_P(PSTR("A: %4.4f, %4.4f, %4.4f\t"
|
|
|
|
"G: %4.4f, %4.4f, %4.4f\t"),
|
|
|
|
accels.x, accels.y, accels.z,
|
|
|
|
gyros.x, gyros.y, gyros.z);
|
2011-02-24 01:56:59 -04:00
|
|
|
*/
|
2011-02-25 01:33:39 -04:00
|
|
|
Serial.printf_P(PSTR("r: %ld\tp: %ld\t y: %ld\n"),
|
2011-01-25 01:53:36 -04:00
|
|
|
dcm.roll_sensor,
|
|
|
|
dcm.pitch_sensor,
|
|
|
|
dcm.yaw_sensor);
|
2011-02-24 01:56:59 -04:00
|
|
|
/*
|
|
|
|
update_trig();
|
2011-02-10 03:10:24 -04:00
|
|
|
Serial.printf_P(PSTR("cp: %1.2f, sp: %1.2f, cr: %1.2f, sr: %1.2f, cy: %1.2f, sy: %1.2f,\n"),
|
2011-02-13 18:32:34 -04:00
|
|
|
cos_pitch_x,
|
|
|
|
sin_pitch_y,
|
|
|
|
cos_roll_x,
|
|
|
|
sin_roll_y,
|
|
|
|
cos_yaw_x, // x
|
|
|
|
sin_yaw_y); // y
|
2011-03-14 03:04:07 -03:00
|
|
|
//*/
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_gps(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
while(1){
|
2011-02-24 01:56:59 -04:00
|
|
|
delay(333);
|
|
|
|
|
|
|
|
// Blink GPS LED if we don't have a fix
|
|
|
|
// ------------------------------------
|
|
|
|
update_GPS_light();
|
|
|
|
|
|
|
|
g_gps->update();
|
|
|
|
|
|
|
|
if (g_gps->new_data){
|
|
|
|
Serial.printf_P(PSTR("Lat: %ld, Lon %ld, Alt: %ldm, #sats: %d\n"),
|
|
|
|
g_gps->latitude,
|
|
|
|
g_gps->longitude,
|
|
|
|
g_gps->altitude/100,
|
|
|
|
g_gps->num_sats);
|
|
|
|
}else{
|
|
|
|
Serial.print(".");
|
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-24 01:56:59 -04:00
|
|
|
/*
|
2010-12-27 19:09:08 -04:00
|
|
|
static int8_t
|
|
|
|
test_dcm(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
Serial.printf_P(PSTR("Gyro | Accel\n"));
|
|
|
|
Vector3f _cam_vector;
|
|
|
|
Vector3f _out_vector;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-27 19:09:08 -04:00
|
|
|
G_Dt = .02;
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
for(byte i = 0; i <= 50; i++){
|
|
|
|
delay(20);
|
|
|
|
// IMU
|
|
|
|
// ---
|
|
|
|
read_AHRS();
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-27 19:09:08 -04:00
|
|
|
Matrix3f temp = dcm.get_dcm_matrix();
|
|
|
|
Matrix3f temp_t = dcm.get_dcm_transposed();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-27 19:09:08 -04:00
|
|
|
Serial.printf_P(PSTR("dcm\n"
|
2011-01-11 17:16:00 -04:00
|
|
|
"%4.4f \t %4.4f \t %4.4f \n"
|
|
|
|
"%4.4f \t %4.4f \t %4.4f \n"
|
|
|
|
"%4.4f \t %4.4f \t %4.4f \n\n"),
|
|
|
|
temp.a.x, temp.a.y, temp.a.z,
|
|
|
|
temp.b.x, temp.b.y, temp.b.z,
|
|
|
|
temp.c.x, temp.c.y, temp.c.z);
|
2010-12-27 19:09:08 -04:00
|
|
|
|
|
|
|
int _pitch = degrees(-asin(temp.c.x));
|
|
|
|
int _roll = degrees(atan2(temp.c.y, temp.c.z));
|
|
|
|
int _yaw = degrees(atan2(temp.b.x, temp.a.x));
|
|
|
|
Serial.printf_P(PSTR( "angles\n"
|
|
|
|
"%d \t %d \t %d\n\n"),
|
2011-02-17 05:36:33 -04:00
|
|
|
_pitch,
|
2011-01-11 17:16:00 -04:00
|
|
|
_roll,
|
|
|
|
_yaw);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-27 19:09:08 -04:00
|
|
|
//_out_vector = _cam_vector * temp;
|
|
|
|
//Serial.printf_P(PSTR( "cam\n"
|
|
|
|
// "%d \t %d \t %d\n\n"),
|
|
|
|
// (int)temp.a.x * 100, (int)temp.a.y * 100, (int)temp.a.x * 100);
|
|
|
|
|
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-24 01:56:59 -04:00
|
|
|
*/
|
2010-12-19 12:40:33 -04:00
|
|
|
/*
|
|
|
|
static int8_t
|
|
|
|
test_dcm(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
Serial.printf_P(PSTR("Gyro | Accel\n"));
|
|
|
|
delay(1000);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
while(1){
|
|
|
|
Vector3f accels = dcm.get_accel();
|
|
|
|
Serial.print("accels.z:");
|
|
|
|
Serial.print(accels.z);
|
|
|
|
Serial.print("omega.z:");
|
|
|
|
Serial.print(omega.z);
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2011-02-24 01:56:59 -04:00
|
|
|
|
2011-03-07 02:00:27 -04:00
|
|
|
/*static int8_t
|
2010-12-19 12:40:33 -04:00
|
|
|
test_omega(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2011-01-02 16:34:42 -04:00
|
|
|
static byte ts_num;
|
|
|
|
float old_yaw;
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
Serial.printf_P(PSTR("Omega"));
|
|
|
|
delay(1000);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-02 16:34:42 -04:00
|
|
|
G_Dt = .02;
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
while(1){
|
2011-01-02 16:34:42 -04:00
|
|
|
delay(20);
|
|
|
|
// IMU
|
|
|
|
// ---
|
|
|
|
read_AHRS();
|
2011-03-06 20:57:06 -04:00
|
|
|
|
2011-01-02 16:34:42 -04:00
|
|
|
float my_oz = (dcm.yaw - old_yaw) * 50;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-02 16:34:42 -04:00
|
|
|
old_yaw = dcm.yaw;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-02 16:34:42 -04:00
|
|
|
ts_num++;
|
|
|
|
if (ts_num > 2){
|
|
|
|
ts_num = 0;
|
|
|
|
//Serial.printf_P(PSTR("R: %4.4f\tP: %4.4f\tY: %4.4f\tY: %4.4f\n"), omega.x, omega.y, omega.z, my_oz);
|
|
|
|
Serial.printf_P(PSTR(" Yaw: %ld\tY: %4.4f\tY: %4.4f\n"), dcm.yaw_sensor, omega.z, my_oz);
|
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2011-01-02 16:34:42 -04:00
|
|
|
return (0);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2011-03-06 20:57:06 -04:00
|
|
|
//*/
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_battery(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
#if BATTERY_EVENT == 1
|
|
|
|
for (int i = 0; i < 20; i++){
|
|
|
|
delay(20);
|
|
|
|
read_battery();
|
|
|
|
}
|
2011-02-24 01:56:59 -04:00
|
|
|
Serial.printf_P(PSTR("Volts: 1:%2.2f, 2:%2.2f, 3:%2.2f, 4:%2.2f\n")
|
|
|
|
battery_voltage1,
|
|
|
|
battery_voltage2,
|
|
|
|
battery_voltage3,
|
|
|
|
battery_voltage4);
|
2010-12-19 12:40:33 -04:00
|
|
|
#else
|
|
|
|
Serial.printf_P(PSTR("Not enabled\n"));
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
#endif
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-01-16 23:44:12 -04:00
|
|
|
static int8_t
|
|
|
|
test_current(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
2011-01-17 22:48:44 -04:00
|
|
|
delta_ms_medium_loop = 100;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-16 23:44:12 -04:00
|
|
|
while(1){
|
2011-01-17 22:48:44 -04:00
|
|
|
delay(100);
|
|
|
|
read_radio();
|
|
|
|
read_current();
|
2011-02-24 01:56:59 -04:00
|
|
|
Serial.printf_P(PSTR("V: %4.4f, A: %4.4f, mAh: %4.4f\n"),
|
|
|
|
current_voltage,
|
|
|
|
current_amps,
|
|
|
|
current_total);
|
2011-01-17 22:48:44 -04:00
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
//if(g.rc_3.control_in > 0){
|
|
|
|
APM_RC.OutputCh(CH_1, g.rc_3.radio_in);
|
|
|
|
APM_RC.OutputCh(CH_2, g.rc_3.radio_in);
|
|
|
|
APM_RC.OutputCh(CH_3, g.rc_3.radio_in);
|
|
|
|
APM_RC.OutputCh(CH_4, g.rc_3.radio_in);
|
2011-01-17 22:48:44 -04:00
|
|
|
//}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-01-16 23:44:12 -04:00
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t
|
|
|
|
test_relay(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
while(1){
|
2011-02-24 01:56:59 -04:00
|
|
|
Serial.printf_P(PSTR("Relay on\n"));
|
2011-02-18 23:59:58 -04:00
|
|
|
relay_on();
|
2010-12-19 12:40:33 -04:00
|
|
|
delay(3000);
|
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-24 01:56:59 -04:00
|
|
|
Serial.printf_P(PSTR("Relay off\n"));
|
2011-02-18 23:59:58 -04:00
|
|
|
relay_off();
|
2010-12-19 12:40:33 -04:00
|
|
|
delay(3000);
|
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_wp(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
delay(1000);
|
2011-04-03 18:11:14 -03:00
|
|
|
//read_EEPROM_waypoint_info();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
// save the alitude above home option
|
2011-03-26 03:35:52 -03:00
|
|
|
Serial.printf_P(PSTR("Hold altitude "));
|
2011-02-25 01:33:39 -04:00
|
|
|
if(g.RTL_altitude < 0){
|
2011-03-26 03:35:52 -03:00
|
|
|
Serial.printf_P(PSTR("\n"));
|
2010-12-19 12:40:33 -04:00
|
|
|
}else{
|
2011-03-26 03:35:52 -03:00
|
|
|
Serial.printf_P(PSTR("of %dm\n"), (int)g.RTL_altitude / 100);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
|
|
|
Serial.printf_P(PSTR("%d waypoints\n"), (int)g.waypoint_total);
|
|
|
|
Serial.printf_P(PSTR("Hit radius: %d\n"), (int)g.waypoint_radius);
|
2011-03-26 03:35:52 -03:00
|
|
|
//Serial.printf_P(PSTR("Loiter radius: %d\n\n"), (int)g.loiter_radius);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-03-26 03:35:52 -03:00
|
|
|
report_wp();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-03-09 10:48:49 -04:00
|
|
|
static int8_t
|
|
|
|
test_rawgps(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2011-03-11 17:37:37 -04:00
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
2011-03-09 10:48:49 -04:00
|
|
|
|
2011-03-11 19:00:40 -04:00
|
|
|
while(1){
|
|
|
|
if (Serial3.available()){
|
|
|
|
digitalWrite(B_LED_PIN, HIGH); // Blink Yellow LED if we are sending data to GPS
|
2011-03-11 17:37:37 -04:00
|
|
|
Serial1.write(Serial3.read());
|
2011-03-11 19:00:40 -04:00
|
|
|
digitalWrite(B_LED_PIN, LOW);
|
|
|
|
}
|
|
|
|
if (Serial1.available()){
|
|
|
|
digitalWrite(C_LED_PIN, HIGH); // Blink Red LED if we are receiving data from GPS
|
2011-03-11 17:37:37 -04:00
|
|
|
Serial3.write(Serial1.read());
|
2011-03-11 19:00:40 -04:00
|
|
|
digitalWrite(C_LED_PIN, LOW);
|
|
|
|
}
|
2011-03-11 17:37:37 -04:00
|
|
|
if(Serial.available() > 0){
|
2011-03-11 19:00:40 -04:00
|
|
|
return (0);
|
2011-03-11 17:37:37 -04:00
|
|
|
}
|
2011-03-11 19:00:40 -04:00
|
|
|
}
|
2011-03-09 10:48:49 -04:00
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_xbee(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
Serial.printf_P(PSTR("Begin XBee X-CTU Range and RSSI Test:\n"));
|
2011-03-10 15:25:54 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
while(1){
|
2011-03-11 19:03:56 -04:00
|
|
|
if (Serial3.available())
|
2011-03-10 17:27:22 -04:00
|
|
|
Serial3.write(Serial3.read());
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-03 07:39:52 -04:00
|
|
|
#if HIL_MODE != HIL_MODE_ATTITUDE
|
2010-12-19 12:40:33 -04:00
|
|
|
static int8_t
|
|
|
|
test_pressure(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2011-02-25 01:33:39 -04:00
|
|
|
Serial.printf_P(PSTR("Uncalibrated relative airpressure\n"));
|
2010-12-19 12:40:33 -04:00
|
|
|
print_hit_enter();
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
home.alt = 0;
|
|
|
|
wp_distance = 0;
|
2011-02-24 01:56:59 -04:00
|
|
|
init_barometer();
|
2011-02-25 01:33:39 -04:00
|
|
|
reset_I();
|
|
|
|
|
|
|
|
// to prevent boost from skewing results
|
|
|
|
cos_pitch_x = cos_roll_x = 1;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
while(1){
|
2011-02-25 01:33:39 -04:00
|
|
|
if (millis() - fast_loopTimer > 100) {
|
2011-01-17 22:48:44 -04:00
|
|
|
delta_ms_fast_loop = millis() - fast_loopTimer;
|
|
|
|
G_Dt = (float)delta_ms_fast_loop / 1000.f; // used by DCM integrator
|
2010-12-19 12:40:33 -04:00
|
|
|
fast_loopTimer = millis();
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-25 01:33:39 -04:00
|
|
|
if (millis() - medium_loopTimer > 100) {
|
2010-12-19 12:40:33 -04:00
|
|
|
medium_loopTimer = millis();
|
|
|
|
|
|
|
|
read_radio(); // read the radio first
|
2011-02-17 05:36:33 -04:00
|
|
|
next_WP.alt = home.alt + g.rc_6.control_in; // 0 - 2000 (20 meters)
|
2011-02-21 00:30:56 -04:00
|
|
|
next_WP.alt = max(next_WP.alt, 30);
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2011-02-21 00:30:56 -04:00
|
|
|
read_trim_switch();
|
2011-02-25 01:33:39 -04:00
|
|
|
update_alt();
|
|
|
|
output_auto_throttle();
|
|
|
|
|
2011-03-11 17:37:37 -04:00
|
|
|
Serial.printf_P(PSTR("B_alt: %ld, S_alt: %ld, \tnext_alt: %ld \terror: %ld, \tcruise: %d, \tint: %6.2f \tout:%d\n"),
|
2011-02-21 00:30:56 -04:00
|
|
|
baro_alt,
|
2011-03-11 17:37:37 -04:00
|
|
|
sonar_alt,
|
2011-02-06 14:50:16 -04:00
|
|
|
next_WP.alt,
|
|
|
|
altitude_error,
|
2011-02-19 17:04:05 -04:00
|
|
|
(int)g.throttle_cruise,
|
2011-02-25 01:33:39 -04:00
|
|
|
g.pid_baro_throttle.get_integrator(),
|
2011-02-17 03:09:13 -04:00
|
|
|
g.rc_3.servo_out);
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
/*
|
|
|
|
Serial.print("Altitude: ");
|
|
|
|
Serial.print((int)current_loc.alt,DEC);
|
|
|
|
Serial.print("\tnext_alt: ");
|
|
|
|
Serial.print((int)next_WP.alt,DEC);
|
|
|
|
Serial.print("\talt_err: ");
|
|
|
|
Serial.print((int)altitude_error,DEC);
|
|
|
|
Serial.print("\ttNom: ");
|
2011-02-17 03:09:13 -04:00
|
|
|
Serial.print(g.,DEC);
|
2010-12-19 12:40:33 -04:00
|
|
|
Serial.print("\ttOut: ");
|
2011-02-17 03:09:13 -04:00
|
|
|
Serial.println(g.rc_3.servo_out,DEC);
|
2010-12-19 12:40:33 -04:00
|
|
|
*/
|
|
|
|
//Serial.print(" Raw pressure value: ");
|
|
|
|
//Serial.println(abs_pressure);
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-03 07:39:52 -04:00
|
|
|
#endif
|
2010-12-19 12:40:33 -04:00
|
|
|
|
|
|
|
static int8_t
|
|
|
|
test_mag(uint8_t argc, const Menu::arg *argv)
|
2011-04-08 16:13:31 -03:00
|
|
|
{
|
|
|
|
if(g.compass_enabled) {
|
|
|
|
//Serial.printf_P(PSTR("MAG_ORIENTATION: %d\n"), MAG_ORIENTATION);
|
|
|
|
|
|
|
|
print_hit_enter();
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
delay(250);
|
|
|
|
compass.read();
|
|
|
|
compass.calculate(0,0);
|
|
|
|
Vector3f maggy = compass.get_offsets();
|
|
|
|
Serial.printf_P(PSTR("Heading: %ld, XYZ: %d, %d, %d,\tXYZoff: %6.2f, %6.2f, %6.2f\n"),
|
|
|
|
(wrap_360(ToDeg(compass.heading) * 100)) /100,
|
|
|
|
compass.mag_x,
|
|
|
|
compass.mag_y,
|
|
|
|
compass.mag_z,
|
|
|
|
maggy.x,
|
|
|
|
maggy.y,
|
|
|
|
maggy.z);
|
|
|
|
|
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
}
|
2011-04-08 16:13:31 -03:00
|
|
|
} else {
|
|
|
|
Serial.printf_P(PSTR("Compass: "));
|
|
|
|
print_enabled(false);
|
|
|
|
return (0);
|
|
|
|
}
|
2010-12-19 12:40:33 -04:00
|
|
|
}
|
|
|
|
|
2011-03-17 22:50:27 -03:00
|
|
|
/*
|
|
|
|
test the sonar
|
|
|
|
*/
|
|
|
|
static int8_t
|
|
|
|
test_sonar(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
|
|
|
print_hit_enter();
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
Serial.printf_P(PSTR("%d cm\n"), sonar.read());
|
|
|
|
delay(100);
|
|
|
|
if(Serial.available() > 0){
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-26 03:35:52 -03:00
|
|
|
static int8_t
|
|
|
|
test_mission(uint8_t argc, const Menu::arg *argv)
|
|
|
|
{
|
2011-04-03 18:11:14 -03:00
|
|
|
//print_hit_enter();
|
|
|
|
//delay(1000);
|
2011-03-26 03:35:52 -03:00
|
|
|
//write out a basic mission to the EEPROM
|
|
|
|
Location t;
|
|
|
|
/*{
|
|
|
|
uint8_t id; ///< command id
|
|
|
|
uint8_t options; ///< options bitmask (1<<0 = relative altitude)
|
|
|
|
uint8_t p1; ///< param 1
|
|
|
|
int32_t alt; ///< param 2 - Altitude in centimeters (meters * 100)
|
|
|
|
int32_t lat; ///< param 3 - Lattitude * 10**7
|
|
|
|
int32_t lng; ///< param 4 - Longitude * 10**7
|
|
|
|
}*/
|
|
|
|
|
2011-03-27 18:26:34 -03:00
|
|
|
// clear home
|
|
|
|
{Location t = {0, 0, 0, 0, 0, 0};
|
|
|
|
set_wp_with_index(t,0);}
|
2011-03-26 03:35:52 -03:00
|
|
|
|
2011-03-27 18:26:34 -03:00
|
|
|
// CMD opt pitch alt/cm
|
|
|
|
{Location t = {MAV_CMD_NAV_TAKEOFF, 0, 0, 300, 0, 0};
|
|
|
|
set_wp_with_index(t,1);}
|
|
|
|
|
2011-04-08 16:13:31 -03:00
|
|
|
if (!strcmp_P(argv[1].str, PSTR("wp"))) {
|
|
|
|
|
|
|
|
// CMD opt
|
|
|
|
{Location t = {MAV_CMD_NAV_WAYPOINT, WP_OPTION_RELATIVE, 15, 0, 0, 0};
|
|
|
|
set_wp_with_index(t,2);}
|
|
|
|
// CMD opt
|
|
|
|
{Location t = {MAV_CMD_NAV_RETURN_TO_LAUNCH, WP_OPTION_YAW, 0, 0, 0, 0};
|
|
|
|
set_wp_with_index(t,3);}
|
|
|
|
|
|
|
|
// CMD opt
|
|
|
|
{Location t = {MAV_CMD_NAV_LAND, 0, 0, 0, 0, 0};
|
|
|
|
set_wp_with_index(t,4);}
|
2011-03-27 18:26:34 -03:00
|
|
|
|
2011-04-08 16:13:31 -03:00
|
|
|
} else {
|
|
|
|
//2250 = 25 meteres
|
|
|
|
// CMD opt p1 //alt //NS //WE
|
|
|
|
{Location t = {MAV_CMD_NAV_LOITER_TIME, 0, 0, 300, 1100, 0};
|
|
|
|
set_wp_with_index(t,2);}
|
2011-03-27 18:26:34 -03:00
|
|
|
|
2011-04-08 16:13:31 -03:00
|
|
|
// CMD opt dir angle/deg deg/s relative
|
|
|
|
{Location t = {MAV_CMD_CONDITION_YAW, 0, 1, 360, 60, 1};
|
|
|
|
set_wp_with_index(t,3);}
|
2011-03-26 03:35:52 -03:00
|
|
|
|
2011-04-08 16:13:31 -03:00
|
|
|
// CMD opt
|
|
|
|
{Location t = {MAV_CMD_NAV_LAND, 0, 0, 0, 0, 0};
|
|
|
|
set_wp_with_index(t,4);}
|
|
|
|
|
|
|
|
}
|
2011-03-26 03:35:52 -03:00
|
|
|
|
|
|
|
g.RTL_altitude.set_and_save(300);
|
|
|
|
g.waypoint_total.set_and_save(4);
|
|
|
|
g.waypoint_radius.set_and_save(3);
|
|
|
|
|
|
|
|
test_wp(NULL, NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-12-19 12:40:33 -04:00
|
|
|
void print_hit_enter()
|
|
|
|
{
|
|
|
|
Serial.printf_P(PSTR("Hit Enter to exit.\n\n"));
|
|
|
|
}
|
2011-01-22 22:07:21 -04:00
|
|
|
|
2011-02-10 03:10:24 -04:00
|
|
|
void fake_out_gps()
|
|
|
|
{
|
|
|
|
static float rads;
|
2011-02-17 05:36:33 -04:00
|
|
|
g_gps->new_data = true;
|
|
|
|
g_gps->fix = true;
|
|
|
|
|
2011-02-17 03:09:13 -04:00
|
|
|
int length = g.rc_6.control_in;
|
2011-02-10 03:10:24 -04:00
|
|
|
rads += .05;
|
2011-02-17 05:36:33 -04:00
|
|
|
|
2011-02-10 03:10:24 -04:00
|
|
|
if (rads > 6.28){
|
|
|
|
rads = 0;
|
|
|
|
}
|
2011-02-17 05:36:33 -04:00
|
|
|
|
|
|
|
g_gps->latitude = 377696000; // Y
|
|
|
|
g_gps->longitude = -1224319000; // X
|
|
|
|
g_gps->altitude = 9000; // meters * 100
|
|
|
|
|
2011-02-10 03:10:24 -04:00
|
|
|
//next_WP.lng = home.lng - length * sin(rads); // X
|
|
|
|
//next_WP.lat = home.lat + length * cos(rads); // Y
|
|
|
|
}
|
|
|
|
|
2011-01-22 22:07:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
void print_motor_out(){
|
2011-02-17 05:36:33 -04:00
|
|
|
Serial.printf("out: R: %d, L: %d F: %d B: %d\n",
|
2011-02-17 03:09:13 -04:00
|
|
|
(motor_out[RIGHT] - g.rc_3.radio_min),
|
|
|
|
(motor_out[LEFT] - g.rc_3.radio_min),
|
|
|
|
(motor_out[FRONT] - g.rc_3.radio_min),
|
|
|
|
(motor_out[BACK] - g.rc_3.radio_min));
|
2011-02-17 05:36:33 -04:00
|
|
|
}
|