1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

heading: Add HeadingActual UAVobject

This object currently holds only the raw magnetometer readings and
an instantaneous heading calculation which are only really useful
for debugging.  The contents of this object will change often as
development progresses.

Note: The magnetometer values are often garbage due to a problem
with i2c software on the AHRS.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1007 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
stac 2010-07-04 02:21:31 +00:00 committed by stac
parent 0e6294ca27
commit 1bbc8381c0
10 changed files with 508 additions and 0 deletions

View File

@ -163,6 +163,7 @@ SRC += $(OPUAVOBJ)/altitudeactual.c
SRC += $(OPUAVOBJ)/attitudeactual.c
SRC += $(OPUAVOBJ)/attitudesettings.c
SRC += $(OPUAVOBJ)/flightbatterystate.c
SRC += $(OPUAVOBJ)/headingactual.c
endif
## PIOS Hardware (STM32F10x)

View File

@ -0,0 +1,102 @@
/**
******************************************************************************
*
* @file headingactual.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Implementation of the HeadingActual object. This file has been
* automatically generated by the UAVObjectGenerator.
*
* @note Object definition file: headingactual.xml.
* This is an automatically generated file.
* DO NOT modify manually.
*
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "headingactual.h"
// Private variables
static UAVObjHandle handle;
// Private functions
static void setDefaults(UAVObjHandle obj, uint16_t instId);
/**
* Initialize object.
* \return 0 Success
* \return -1 Failure
*/
int32_t HeadingActualInitialize()
{
// Register object with the object manager
handle = UAVObjRegister(HEADINGACTUAL_OBJID, HEADINGACTUAL_NAME, HEADINGACTUAL_METANAME, 0,
HEADINGACTUAL_ISSINGLEINST, HEADINGACTUAL_ISSETTINGS, HEADINGACTUAL_NUMBYTES, &setDefaults);
// Done
if (handle != 0)
{
return 0;
}
else
{
return -1;
}
}
/**
* Initialize object fields and metadata with the default values.
* If a default value is not specified the object fields
* will be initialized to zero.
*/
static void setDefaults(UAVObjHandle obj, uint16_t instId)
{
HeadingActualData data;
UAVObjMetadata metadata;
// Initialize object fields to their default values
UAVObjGetInstanceData(obj, instId, &data);
memset(&data, 0, sizeof(HeadingActualData));
UAVObjSetInstanceData(obj, instId, &data);
// Initialize object metadata to their default values
metadata.access = ACCESS_READWRITE;
metadata.gcsAccess = ACCESS_READWRITE;
metadata.telemetryAcked = 0;
metadata.telemetryUpdateMode = UPDATEMODE_PERIODIC;
metadata.telemetryUpdatePeriod = 500;
metadata.gcsTelemetryAcked = 0;
metadata.gcsTelemetryUpdateMode = UPDATEMODE_MANUAL;
metadata.gcsTelemetryUpdatePeriod = 0;
metadata.loggingUpdateMode = UPDATEMODE_NEVER;
metadata.loggingUpdatePeriod = 0;
UAVObjSetMetadata(obj, &metadata);
}
/**
* Get object handle
*/
UAVObjHandle HeadingActualHandle()
{
return handle;
}

View File

@ -0,0 +1,78 @@
/**
******************************************************************************
*
* @file headingactual.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Implementation of the HeadingActual object. This file has been
* automatically generated by the UAVObjectGenerator.
*
* @note Object definition file: headingactual.xml.
* This is an automatically generated file.
* DO NOT modify manually.
*
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HEADINGACTUAL_H
#define HEADINGACTUAL_H
// Object constants
#define HEADINGACTUAL_OBJID 2921442332U
#define HEADINGACTUAL_NAME "HeadingActual"
#define HEADINGACTUAL_METANAME "HeadingActualMeta"
#define HEADINGACTUAL_ISSINGLEINST 1
#define HEADINGACTUAL_ISSETTINGS 0
#define HEADINGACTUAL_NUMBYTES sizeof(HeadingActualData)
// Object access macros
#define HeadingActualGet(dataOut) UAVObjGetData(HeadingActualHandle(), dataOut)
#define HeadingActualSet(dataIn) UAVObjSetData(HeadingActualHandle(), dataIn)
#define HeadingActualInstGet(instId, dataOut) UAVObjGetInstanceData(HeadingActualHandle(), instId, dataOut)
#define HeadingActualInstSet(instId, dataIn) UAVObjSetInstanceData(HeadingActualHandle(), instId, dataIn)
#define HeadingActualConnectQueue(queue) UAVObjConnectQueue(HeadingActualHandle(), queue, EV_MASK_ALL_UPDATES)
#define HeadingActualConnectCallback(cb) UAVObjConnectCallback(HeadingActualHandle(), cb, EV_MASK_ALL_UPDATES)
#define HeadingActualCreateInstance() UAVObjCreateInstance(HeadingActualHandle())
#define HeadingActualRequestUpdate() UAVObjRequestUpdate(HeadingActualHandle())
#define HeadingActualRequestInstUpdate(instId) UAVObjRequestInstanceUpdate(HeadingActualHandle(), instId)
#define HeadingActualUpdated() UAVObjUpdated(HeadingActualHandle())
#define HeadingActualInstUpdated(instId) UAVObjUpdated(HeadingActualHandle(), instId)
#define HeadingActualGetMetadata(dataOut) UAVObjGetMetadata(HeadingActualHandle(), dataOut)
#define HeadingActualSetMetadata(dataIn) UAVObjSetMetadata(HeadingActualHandle(), dataIn)
// Object data
typedef struct {
int16_t raw[3];
float heading;
} __attribute__((packed)) HeadingActualData;
// Field information
// Field raw information
/* Array element names for field raw */
typedef enum { HEADINGACTUAL_RAW_X=0, HEADINGACTUAL_RAW_Y=1, HEADINGACTUAL_RAW_Z=2, } HeadingActualrawElem;
/* Number of elements for field raw */
#define HEADINGACTUAL_RAW_NUMELEM 3
// Field heading information
// Generic interface functions
int32_t HeadingActualInitialize();
UAVObjHandle HeadingActualHandle();
#endif // HEADINGACTUAL_H

View File

@ -41,6 +41,7 @@
#include "flightbatterystate.h"
#include "flighttelemetrystats.h"
#include "gcstelemetrystats.h"
#include "headingactual.h"
#include "manualcontrolcommand.h"
#include "manualcontrolsettings.h"
#include "objectpersistence.h"
@ -71,6 +72,7 @@ void UAVObjectsInitializeAll()
FlightBatteryStateInitialize();
FlightTelemetryStatsInitialize();
GCSTelemetryStatsInitialize();
HeadingActualInitialize();
ManualControlCommandInitialize();
ManualControlSettingsInitialize();
ObjectPersistenceInitialize();

View File

@ -0,0 +1,131 @@
/**
******************************************************************************
*
* @file headingactual.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Implementation of the HeadingActual object. This file has been
* automatically generated by the UAVObjectGenerator.
*
* @note Object definition file: headingactual.xml.
* This is an automatically generated file.
* DO NOT modify manually.
*
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "headingactual.h"
#include "uavobjectfield.h"
const QString HeadingActual::NAME = QString("HeadingActual");
/**
* Constructor
*/
HeadingActual::HeadingActual(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, NAME)
{
// Create fields
QList<UAVObjectField*> fields;
QStringList rawElemNames;
rawElemNames.append("X");
rawElemNames.append("Y");
rawElemNames.append("Z");
fields.append( new UAVObjectField(QString("raw"), QString("mGa"), UAVObjectField::INT16, rawElemNames, QStringList()) );
QStringList headingElemNames;
headingElemNames.append("0");
fields.append( new UAVObjectField(QString("heading"), QString("degrees"), UAVObjectField::FLOAT32, headingElemNames, QStringList()) );
// Initialize object
initializeFields(fields, (quint8*)&data, NUMBYTES);
// Set the default field values
setDefaultFieldValues();
}
/**
* Get the default metadata for this object
*/
UAVObject::Metadata HeadingActual::getDefaultMetadata()
{
UAVObject::Metadata metadata;
metadata.flightAccess = ACCESS_READWRITE;
metadata.gcsAccess = ACCESS_READWRITE;
metadata.gcsTelemetryAcked = 0;
metadata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_MANUAL;
metadata.gcsTelemetryUpdatePeriod = 0;
metadata.flightTelemetryAcked = 0;
metadata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC;
metadata.flightTelemetryUpdatePeriod = 500;
metadata.loggingUpdateMode = UAVObject::UPDATEMODE_NEVER;
metadata.loggingUpdatePeriod = 0;
return metadata;
}
/**
* Initialize object fields with the default values.
* If a default value is not specified the object fields
* will be initialized to zero.
*/
void HeadingActual::setDefaultFieldValues()
{
}
/**
* Get the object data fields
*/
HeadingActual::DataFields HeadingActual::getData()
{
QMutexLocker locker(mutex);
return data;
}
/**
* Set the object data fields
*/
void HeadingActual::setData(const DataFields& data)
{
QMutexLocker locker(mutex);
// Get metadata
Metadata mdata = getMetadata();
// Update object if the access mode permits
if ( mdata.gcsAccess == ACCESS_READWRITE )
{
this->data = data;
emit objectUpdatedAuto(this); // trigger object updated event
emit objectUpdated(this);
}
}
/**
* Create a clone of this object, a new instance ID must be specified.
* Do not use this function directly to create new instances, the
* UAVObjectManager should be used instead.
*/
UAVDataObject* HeadingActual::clone(quint32 instID)
{
HeadingActual* obj = new HeadingActual();
obj->initialize(instID, this->getMetaObject());
return obj;
}
/**
* Static function to retrieve an instance of the object.
*/
HeadingActual* HeadingActual::GetInstance(UAVObjectManager* objMngr, quint32 instID)
{
return dynamic_cast<HeadingActual*>(objMngr->getObject(HeadingActual::OBJID, instID));
}

View File

@ -0,0 +1,82 @@
/**
******************************************************************************
*
* @file headingactual.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Implementation of the HeadingActual object. This file has been
* automatically generated by the UAVObjectGenerator.
*
* @note Object definition file: headingactual.xml.
* This is an automatically generated file.
* DO NOT modify manually.
*
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HEADINGACTUAL_H
#define HEADINGACTUAL_H
#include "uavdataobject.h"
#include "uavobjectmanager.h"
class UAVOBJECTS_EXPORT HeadingActual: public UAVDataObject
{
Q_OBJECT
public:
// Field structure
typedef struct {
qint16 raw[3];
float heading;
} __attribute__((packed)) DataFields;
// Field information
// Field raw information
/* Array element names for field raw */
typedef enum { RAW_X=0, RAW_Y=1, RAW_Z=2, } rawElem;
/* Number of elements for field raw */
static const quint32 RAW_NUMELEM = 3;
// Field heading information
// Constants
static const quint32 OBJID = 2921442332U;
static const QString NAME;
static const bool ISSINGLEINST = 1;
static const bool ISSETTINGS = 0;
static const quint32 NUMBYTES = sizeof(DataFields);
// Functions
HeadingActual();
DataFields getData();
void setData(const DataFields& data);
Metadata getDefaultMetadata();
UAVDataObject* clone(quint32 instID);
static HeadingActual* GetInstance(UAVObjectManager* objMngr, quint32 instID = 0);
private:
DataFields data;
void setDefaultFieldValues();
};
#endif // HEADINGACTUAL_H

View File

@ -0,0 +1,98 @@
##
##############################################################################
#
# @file headingactual.py
# @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
# @brief Implementation of the HeadingActual object. This file has been
# automatically generated by the UAVObjectGenerator.
#
# @note Object definition file: headingactual.xml.
# This is an automatically generated file.
# DO NOT modify manually.
#
# @see The GNU Public License (GPL) Version 3
#
#############################################################################/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
import uavobject
import struct
from collections import namedtuple
# This is a list of instances of the data fields contained in this object
_fields = [ \
uavobject.UAVObjectField(
'raw',
'h',
3,
[
'X',
'Y',
'Z',
],
{
}
),
uavobject.UAVObjectField(
'heading',
'f',
1,
[
'0',
],
{
}
),
]
class HeadingActual(uavobject.UAVObject):
## Object constants
OBJID = 2921442332
NAME = "HeadingActual"
METANAME = "HeadingActualMeta"
ISSINGLEINST = 1
ISSETTINGS = 0
def __init__(self):
uavobject.UAVObject.__init__(self,
self.OBJID,
self.NAME,
self.METANAME,
0,
self.ISSINGLEINST)
for f in _fields:
self.add_field(f)
def __str__(self):
s = ("0x%08X (%10u) %-30s %3u bytes format '%s'\n"
% (self.OBJID, self.OBJID, self.NAME, self.get_struct().size, self.get_struct().format))
for f in self.get_tuple()._fields:
s += ("\t%s\n" % f)
return (s)
def main():
# Instantiate the object and dump out some interesting info
x = HeadingActual()
print (x)
if __name__ == "__main__":
#import pdb ; pdb.run('main()')
main()

View File

@ -18,6 +18,7 @@ HEADERS += uavobjects_global.h \
exampleobject2.h \
exampleobject1.h \
gcstelemetrystats.h \
headingactual.h \
flighttelemetrystats.h \
systemstats.h \
systemalarms.h \
@ -47,6 +48,7 @@ SOURCES += uavobject.cpp \
exampleobject2.cpp \
exampleobject1.cpp \
gcstelemetrystats.cpp \
headingactual.cpp \
flighttelemetrystats.cpp \
systemstats.cpp \
systemalarms.cpp \

View File

@ -42,6 +42,7 @@
#include "flightbatterystate.h"
#include "flighttelemetrystats.h"
#include "gcstelemetrystats.h"
#include "headingactual.h"
#include "manualcontrolcommand.h"
#include "manualcontrolsettings.h"
#include "objectpersistence.h"
@ -72,6 +73,7 @@ void UAVObjectsInitialize(UAVObjectManager* objMngr)
objMngr->registerObject( new FlightBatteryState() );
objMngr->registerObject( new FlightTelemetryStats() );
objMngr->registerObject( new GCSTelemetryStats() );
objMngr->registerObject( new HeadingActual() );
objMngr->registerObject( new ManualControlCommand() );
objMngr->registerObject( new ManualControlSettings() );
objMngr->registerObject( new ObjectPersistence() );

View File

@ -0,0 +1,10 @@
<xml>
<object name="HeadingActual" singleinstance="true" settings="false">
<field name="raw" units="mGa" type="int16" elementnames="X,Y,Z"/>
<field name="heading" units="degrees" type="float" elements="1"/>
<access gcs="readwrite" flight="readwrite"/>
<telemetrygcs acked="false" updatemode="manual" period="0"/>
<telemetryflight acked="false" updatemode="periodic" period="500"/>
<logging updatemode="never" period="0"/>
</object>
</xml>