2012-02-11 07:59:56 -04:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
|
|
|
|
/*
|
|
|
|
new variable scheme
|
|
|
|
Andrew Tridgell February 2012
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <FastSerial.h>
|
|
|
|
#include <AP_Common.h>
|
2012-02-12 18:55:39 -04:00
|
|
|
#include <Arduino_Mega_ISR_Registry.h>
|
2012-02-11 07:59:56 -04:00
|
|
|
#include <PID.h> // PID library
|
|
|
|
#include <APM_RC.h> // ArduPilot Mega RC Library
|
|
|
|
#include <RC_Channel.h> // RC Channel Library
|
|
|
|
#include <AP_Compass.h> // ArduPilot Mega Magnetometer Library
|
2012-02-12 18:55:39 -04:00
|
|
|
#include <SPI.h> // Arduino SPI lib
|
2012-02-11 07:59:56 -04:00
|
|
|
#include <I2C.h>
|
2012-02-12 18:55:39 -04:00
|
|
|
#include <DataFlash.h>
|
2012-03-11 05:36:25 -03:00
|
|
|
#include <AP_AHRS.h>
|
2012-02-12 18:55:39 -04:00
|
|
|
#include <AP_ADC.h>
|
|
|
|
#include <AP_Baro.h>
|
2012-03-17 23:33:09 -03:00
|
|
|
#include <Filter.h>
|
|
|
|
#include <GCS_MAVLink.h>
|
2012-02-12 18:55:39 -04:00
|
|
|
#include <AP_PeriodicProcess.h>
|
|
|
|
#include <AP_InertialSensor.h> // Inertial Sensor (uncalibated IMU) Library
|
|
|
|
#include <AP_IMU.h> // ArduPilot Mega IMU Library
|
|
|
|
#include <AP_GPS.h>
|
2012-02-11 07:59:56 -04:00
|
|
|
#include <AP_Math.h>
|
2012-08-06 22:02:48 -03:00
|
|
|
#include <SITL.h>
|
2012-03-11 05:36:25 -03:00
|
|
|
#include <GCS_MAVLink.h>
|
2012-02-11 07:59:56 -04:00
|
|
|
#include <config.h>
|
|
|
|
#include <Parameters.h>
|
2012-03-17 23:33:09 -03:00
|
|
|
#include <AP_Declination.h>
|
|
|
|
|
2012-08-06 22:02:48 -03:00
|
|
|
// this sets up the parameter table, and sets the default values. This
|
|
|
|
// must be the first AP_Param variable declared to ensure its
|
|
|
|
// constructor runs before the constructors of the other AP_Param
|
|
|
|
// variables
|
|
|
|
AP_Param param_loader(var_info, WP_START_BYTE);
|
|
|
|
|
2012-02-11 07:59:56 -04:00
|
|
|
static Parameters g;
|
2012-02-12 18:55:39 -04:00
|
|
|
|
|
|
|
static AP_ADC_ADS7844 adc;
|
|
|
|
static GPS *g_gps;
|
|
|
|
AP_GPS_Auto g_gps_driver(&Serial1, &g_gps);
|
|
|
|
# if CONFIG_IMU_TYPE == CONFIG_IMU_MPU6000
|
|
|
|
AP_InertialSensor_MPU6000 ins( CONFIG_MPU6000_CHIP_SELECT_PIN );
|
|
|
|
# else
|
|
|
|
AP_InertialSensor_Oilpan ins( &adc );
|
|
|
|
#endif // CONFIG_IMU_TYPE
|
|
|
|
AP_IMU_INS imu( &ins );
|
2012-03-11 05:36:25 -03:00
|
|
|
AP_AHRS_DCM ahrs(&imu, g_gps);
|
2012-02-12 18:55:39 -04:00
|
|
|
|
|
|
|
Arduino_Mega_ISR_Registry isr_registry;
|
|
|
|
#ifdef DESKTOP_BUILD
|
|
|
|
AP_Compass_HIL compass;
|
|
|
|
#else
|
2012-02-11 07:59:56 -04:00
|
|
|
static AP_Compass_HMC5843 compass;
|
2012-02-12 18:55:39 -04:00
|
|
|
#endif
|
|
|
|
AP_Baro_BMP085_HIL barometer;
|
2012-02-11 07:59:56 -04:00
|
|
|
|
2012-08-06 22:02:48 -03:00
|
|
|
SITL sitl;
|
|
|
|
|
2012-02-11 07:59:56 -04:00
|
|
|
FastSerialPort0(Serial);
|
2012-02-12 18:55:39 -04:00
|
|
|
FastSerialPort1(Serial1); // GPS port
|
2012-02-11 07:59:56 -04:00
|
|
|
|
|
|
|
#define SERIAL0_BAUD 115200
|
|
|
|
|
2012-02-12 03:23:39 -04:00
|
|
|
#define Debug(fmt, args...) Serial.printf("%s:%d: " fmt "\n", __FUNCTION__, __LINE__ , ##args)
|
|
|
|
|
|
|
|
|
2012-02-11 07:59:56 -04:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(SERIAL0_BAUD, 128, 128);
|
|
|
|
|
|
|
|
load_parameters();
|
|
|
|
|
2012-02-12 03:23:39 -04:00
|
|
|
// show some sizes
|
2012-02-11 07:59:56 -04:00
|
|
|
Serial.printf_P(PSTR("sizeof(RC_Channel)=%u\n"), (unsigned)sizeof(RC_Channel));
|
|
|
|
Serial.printf_P(PSTR("sizeof(g)=%u\n"), (unsigned)sizeof(g));
|
|
|
|
Serial.printf_P(PSTR("sizeof(g.throttle_min)=%u\n"), (unsigned)sizeof(g.throttle_min));
|
|
|
|
Serial.printf_P(PSTR("sizeof(g.channel_roll)=%u\n"), (unsigned)sizeof(g.channel_roll));
|
|
|
|
Serial.printf_P(PSTR("throttle_max now: %u\n"), (unsigned)g.throttle_max);
|
|
|
|
|
2012-02-12 03:23:39 -04:00
|
|
|
// some ad-hoc testing
|
|
|
|
|
2012-02-11 07:59:56 -04:00
|
|
|
// try set interfaces
|
|
|
|
g.throttle_min.set(g.throttle_min+1);
|
|
|
|
g.throttle_min.save();
|
|
|
|
g.throttle_min.set_and_save(g.throttle_min+1);
|
|
|
|
|
|
|
|
Serial.printf_P(PSTR("throttle_min now: %u\n"), (unsigned)g.throttle_min);
|
|
|
|
|
|
|
|
// find a variable by name
|
|
|
|
AP_Param *vp;
|
2012-02-12 03:23:39 -04:00
|
|
|
enum ap_var_type type;
|
|
|
|
vp = AP_Param::find("RLL2SRV_P", &type);
|
2012-02-11 07:59:56 -04:00
|
|
|
((AP_Float *)vp)->set(23);
|
|
|
|
|
|
|
|
Serial.printf_P(PSTR("RLL2SRV_P=%f\n"),
|
|
|
|
g.pidServoRoll.kP());
|
|
|
|
|
|
|
|
char s[AP_MAX_NAME_SIZE+1];
|
|
|
|
|
|
|
|
g.throttle_min.copy_name(s, sizeof(s));
|
|
|
|
s[AP_MAX_NAME_SIZE] = 0;
|
|
|
|
Serial.printf_P(PSTR("THROTTLE_MIN.copy_name()->%s\n"), s);
|
|
|
|
|
|
|
|
g.channel_roll.radio_min.copy_name(s, sizeof(s));
|
|
|
|
s[AP_MAX_NAME_SIZE] = 0;
|
|
|
|
Serial.printf_P(PSTR("RC1_MIN.copy_name()->%s %p\n"), s, &g.channel_roll.radio_min);
|
2012-02-12 03:23:39 -04:00
|
|
|
|
2012-02-13 17:34:25 -04:00
|
|
|
Vector3f ofs;
|
|
|
|
ofs = compass.get_offsets();
|
|
|
|
Serial.printf_P(PSTR("Compass: %f %f %f\n"),
|
|
|
|
ofs.x, ofs.y, ofs.z);
|
|
|
|
ofs.x += 1.1;
|
|
|
|
ofs.y += 1.2;
|
|
|
|
ofs.z += 1.3;
|
|
|
|
compass.set_offsets(ofs);
|
|
|
|
compass.save_offsets();
|
2012-02-24 02:23:47 -04:00
|
|
|
Serial.printf_P(PSTR("Compass: %f %f %f\n"),
|
|
|
|
ofs.x, ofs.y, ofs.z);
|
|
|
|
|
|
|
|
test_vector3f();
|
2012-02-13 17:34:25 -04:00
|
|
|
|
2012-02-12 03:23:39 -04:00
|
|
|
// full testing of all variables
|
2012-02-19 01:58:08 -04:00
|
|
|
AP_Param::ParamToken token;
|
2012-02-12 03:23:39 -04:00
|
|
|
for (AP_Param *ap = AP_Param::first(&token, &type);
|
|
|
|
ap;
|
|
|
|
ap=AP_Param::next(&token, &type)) {
|
2012-08-06 22:02:48 -03:00
|
|
|
//test_variable(ap, type);
|
2012-02-12 03:23:39 -04:00
|
|
|
}
|
2012-02-12 19:16:55 -04:00
|
|
|
|
|
|
|
AP_Param::show_all();
|
|
|
|
|
2012-02-12 03:23:39 -04:00
|
|
|
Serial.println_P(PSTR("All done."));
|
2012-02-11 07:59:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
}
|
2012-02-12 03:23:39 -04:00
|
|
|
|
2012-02-24 02:23:47 -04:00
|
|
|
// test vector3f handling
|
|
|
|
void test_vector3f(void)
|
|
|
|
{
|
|
|
|
enum ap_var_type type;
|
|
|
|
|
|
|
|
AP_Float *f;
|
|
|
|
AP_Vector3f *v;
|
|
|
|
Vector3f vec;
|
|
|
|
|
|
|
|
v = (AP_Vector3f *)AP_Param::find("COMPASS_OFS", &type);
|
|
|
|
|
|
|
|
f = (AP_Float *)AP_Param::find("COMPASS_OFS_X", &type);
|
|
|
|
f->set_and_save(10);
|
|
|
|
f = (AP_Float *)AP_Param::find("COMPASS_OFS_Y", &type);
|
|
|
|
f->set_and_save(11);
|
|
|
|
f = (AP_Float *)AP_Param::find("COMPASS_OFS_Z", &type);
|
|
|
|
f->set_and_save(12);
|
|
|
|
|
|
|
|
v->load();
|
|
|
|
|
|
|
|
vec = *v;
|
|
|
|
Serial.printf_P(PSTR("vec %f %f %f\n"),
|
|
|
|
vec.x, vec.y, vec.z);
|
|
|
|
|
|
|
|
if (vec.x != 10 ||
|
|
|
|
vec.y != 11 ||
|
|
|
|
vec.z != 12) {
|
|
|
|
Serial.printf_P(PSTR("wrong value for compass vector\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-12 03:23:39 -04:00
|
|
|
// test all interfaces for a variable
|
|
|
|
void test_variable(AP_Param *ap, enum ap_var_type type)
|
|
|
|
{
|
2012-02-24 02:23:47 -04:00
|
|
|
static int8_t value;
|
2012-02-12 03:23:39 -04:00
|
|
|
char s[AP_MAX_NAME_SIZE+1];
|
|
|
|
|
|
|
|
value++;
|
|
|
|
|
2012-02-24 02:23:47 -04:00
|
|
|
ap->copy_name(s, sizeof(s), type==AP_PARAM_FLOAT);
|
2012-02-12 03:23:39 -04:00
|
|
|
Serial.printf_P(PSTR("Testing variable '%s' of type %u\n"),
|
|
|
|
s, type);
|
|
|
|
enum ap_var_type type2;
|
|
|
|
if (AP_Param::find(s, &type2) != ap ||
|
|
|
|
type2 != type) {
|
|
|
|
Debug("find failed");
|
|
|
|
}
|
2012-02-12 18:55:39 -04:00
|
|
|
if (strcmp(s, "FORMAT_VERSION") == 0) {
|
|
|
|
// don't wipe the version
|
|
|
|
return;
|
|
|
|
}
|
2012-02-12 03:23:39 -04:00
|
|
|
switch (type) {
|
|
|
|
case AP_PARAM_INT8: {
|
|
|
|
AP_Int8 *v = (AP_Int8 *)ap;
|
2012-02-12 19:26:21 -04:00
|
|
|
if (sizeof(*v) != 1) {
|
|
|
|
Debug("incorrect size %u", (unsigned)sizeof(*v));
|
|
|
|
}
|
2012-02-12 03:23:39 -04:00
|
|
|
v->set(value);
|
|
|
|
if (!v->save()) {
|
|
|
|
Debug("failed set_and_save");
|
|
|
|
}
|
|
|
|
if (!v->load()) {
|
|
|
|
Debug("failed load");
|
|
|
|
}
|
|
|
|
if (v->get() != value) {
|
2012-02-24 02:23:47 -04:00
|
|
|
Debug("wrong value %d %d", (int)v->get(), (int)value);
|
2012-02-12 03:23:39 -04:00
|
|
|
}
|
|
|
|
if (!v->set_and_save(value+1)) {
|
|
|
|
Debug("failed set_and_save");
|
|
|
|
}
|
|
|
|
if (!v->load()) {
|
|
|
|
Debug("failed load");
|
|
|
|
}
|
|
|
|
if (v->vtype != type) {
|
|
|
|
Debug("wrong type");
|
|
|
|
}
|
|
|
|
if (v->get() != value+1) {
|
|
|
|
Debug("wrong value %u %u", (unsigned)v->get(), value+1);
|
|
|
|
}
|
|
|
|
if (*v != value+1) {
|
|
|
|
Debug("wrong direct value %u %u", (unsigned)v->get(), value+1);
|
|
|
|
}
|
|
|
|
*v = value+2;
|
|
|
|
if (v->get() != value+2) {
|
|
|
|
Debug("wrong copy assignment value %u %u", (unsigned)v->get(), value+2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AP_PARAM_INT16: {
|
|
|
|
AP_Int16 *v = (AP_Int16 *)ap;
|
2012-02-12 19:26:21 -04:00
|
|
|
if (sizeof(*v) != 2) {
|
|
|
|
Debug("incorrect size %u", (unsigned)sizeof(*v));
|
|
|
|
}
|
2012-02-12 03:23:39 -04:00
|
|
|
v->set(value);
|
|
|
|
if (!v->save()) {
|
|
|
|
Debug("failed set_and_save");
|
|
|
|
}
|
|
|
|
if (!v->load()) {
|
|
|
|
Debug("failed load");
|
|
|
|
}
|
|
|
|
if (v->get() != value) {
|
|
|
|
Debug("wrong value %u %u", (unsigned)v->get(), value);
|
|
|
|
}
|
|
|
|
if (!v->set_and_save(value+1)) {
|
|
|
|
Debug("failed set_and_save");
|
|
|
|
}
|
|
|
|
if (!v->load()) {
|
|
|
|
Debug("failed load");
|
|
|
|
}
|
|
|
|
if (v->vtype != type) {
|
|
|
|
Debug("wrong type");
|
|
|
|
}
|
|
|
|
if (v->get() != value+1) {
|
|
|
|
Debug("wrong value %u %u", (unsigned)v->get(), value+1);
|
|
|
|
}
|
|
|
|
if (*v != value+1) {
|
|
|
|
Debug("wrong direct value %u %u", (unsigned)v->get(), value+1);
|
|
|
|
}
|
|
|
|
*v = value+2;
|
|
|
|
if (v->get() != value+2) {
|
|
|
|
Debug("wrong copy assignment value %u %u", (unsigned)v->get(), value+2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AP_PARAM_INT32: {
|
|
|
|
AP_Int32 *v = (AP_Int32 *)ap;
|
2012-02-12 19:26:21 -04:00
|
|
|
if (sizeof(*v) != 4) {
|
|
|
|
Debug("incorrect size %u", (unsigned)sizeof(*v));
|
|
|
|
}
|
2012-02-12 03:23:39 -04:00
|
|
|
v->set(value);
|
|
|
|
if (!v->save()) {
|
|
|
|
Debug("failed set_and_save");
|
|
|
|
}
|
|
|
|
if (!v->load()) {
|
|
|
|
Debug("failed load");
|
|
|
|
}
|
|
|
|
if (v->get() != value) {
|
|
|
|
Debug("wrong value %u %u", (unsigned)v->get(), value);
|
|
|
|
}
|
|
|
|
if (!v->set_and_save(value+1)) {
|
|
|
|
Debug("failed set_and_save");
|
|
|
|
}
|
|
|
|
if (!v->load()) {
|
|
|
|
Debug("failed load");
|
|
|
|
}
|
|
|
|
if (v->vtype != type) {
|
|
|
|
Debug("wrong type");
|
|
|
|
}
|
|
|
|
if (v->get() != value+1) {
|
|
|
|
Debug("wrong value %u %u", (unsigned)v->get(), value+1);
|
|
|
|
}
|
|
|
|
if (*v != value+1) {
|
|
|
|
Debug("wrong direct value %u %u", (unsigned)v->get(), value+1);
|
|
|
|
}
|
|
|
|
*v = value+2;
|
|
|
|
if (v->get() != value+2) {
|
|
|
|
Debug("wrong copy assignment value %u %u", (unsigned)v->get(), value+2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AP_PARAM_FLOAT: {
|
|
|
|
AP_Float *v = (AP_Float *)ap;
|
2012-02-12 19:26:21 -04:00
|
|
|
if (sizeof(*v) != 4) {
|
|
|
|
Debug("incorrect size %u", (unsigned)sizeof(*v));
|
|
|
|
}
|
2012-02-12 03:23:39 -04:00
|
|
|
v->set(value);
|
|
|
|
if (!v->save()) {
|
|
|
|
Debug("failed set_and_save");
|
|
|
|
}
|
|
|
|
if (!v->load()) {
|
|
|
|
Debug("failed load");
|
|
|
|
}
|
|
|
|
if (v->get() != value) {
|
|
|
|
Debug("wrong value %u %u", (unsigned)v->get(), value);
|
|
|
|
}
|
|
|
|
if (!v->set_and_save(value+1)) {
|
|
|
|
Debug("failed set_and_save");
|
|
|
|
}
|
|
|
|
if (!v->load()) {
|
|
|
|
Debug("failed load");
|
|
|
|
}
|
|
|
|
if (v->vtype != type) {
|
|
|
|
Debug("wrong type");
|
|
|
|
}
|
|
|
|
if (v->get() != value+1) {
|
|
|
|
Debug("wrong value %u %u", (unsigned)v->get(), value+1);
|
|
|
|
}
|
|
|
|
if (*v != value+1) {
|
|
|
|
Debug("wrong direct value %u %u", (unsigned)v->get(), value+1);
|
|
|
|
}
|
|
|
|
*v = value+2;
|
|
|
|
if (v->get() != value+2) {
|
|
|
|
Debug("wrong copy assignment value %u %u", (unsigned)v->get(), value+2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-02-12 19:26:21 -04:00
|
|
|
case AP_PARAM_VECTOR3F: {
|
|
|
|
AP_Vector3f *v = (AP_Vector3f *)ap;
|
|
|
|
if (sizeof(*v) != 12) {
|
|
|
|
Debug("incorrect size %u", (unsigned)sizeof(*v));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AP_PARAM_VECTOR6F: {
|
|
|
|
AP_Vector6f *v = (AP_Vector6f *)ap;
|
|
|
|
if (sizeof(*v) != 24) {
|
|
|
|
Debug("incorrect size %u", (unsigned)sizeof(*v));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AP_PARAM_MATRIX3F: {
|
|
|
|
AP_Matrix3f *v = (AP_Matrix3f *)ap;
|
|
|
|
if (sizeof(*v) != 36) {
|
|
|
|
Debug("incorrect size %u", (unsigned)sizeof(*v));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-02-12 03:23:39 -04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|