updating code from Flying Laptop
This is the framework of Flying Laptop OBSW version A.13.0.
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
|
||||
class AsciiConverter: public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = ASCII_CONVERTER;
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::ASCII_CONVERTER;
|
||||
static const ReturnValue_t TOO_LONG_FOR_TARGET_TYPE = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t INVALID_CHARACTERS = MAKE_RETURN_CODE(2);
|
||||
static const ReturnValue_t BUFFER_TOO_SMALL = MAKE_RETURN_CODE(0x3);
|
||||
|
@ -1,24 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# OSAL makefile
|
||||
#
|
||||
# Created on: Mar 04, 2010
|
||||
# Author: ziemke
|
||||
# Author: Claas Ziemke
|
||||
# Copyright 2010, Claas Ziemke <claas.ziemke@gmx.net>
|
||||
#
|
||||
|
||||
BASEDIR=../../
|
||||
include $(BASEDIR)options.mk
|
||||
|
||||
OBJ = $(BUILDDIR)/crc_ccitt.o\
|
||||
$(BUILDDIR)/conversion.o\
|
||||
$(BUILDDIR)/math_custom.o\
|
||||
|
||||
all: $(OBJ)
|
||||
|
||||
$(BUILDDIR)/%.o: %.cpp %.h
|
||||
$(CPP) $(CFLAGS) $(DEFINES) $(CCOPT) ${INCLUDE} -c $< -o $@
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.gcno *.gcda
|
@ -8,7 +8,8 @@ static const double PI = 3.1415926535897932384626433;
|
||||
namespace Earth {
|
||||
static const double OMEGA = 7.2921158553E-5;
|
||||
static const double GRAVITATIONAL_CONSTANT = 3.987095392E14;
|
||||
static const double MEAN_RADIUS = 6371000;
|
||||
static const double MEAN_RADIUS = 6371008.8;
|
||||
static const double STANDARD_GRAVITATIONAL_PARAMETER = 3.9860044189e14;
|
||||
}
|
||||
|
||||
#endif /* CONSTANTS_H_ */
|
||||
|
@ -1,12 +1,11 @@
|
||||
/*
|
||||
* conversion.cpp
|
||||
*
|
||||
* Created on: 07.05.2012
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/globalfunctions/conversion.h>
|
||||
//TODO: This shall be optimized (later)!
|
||||
//TODO REMOVE. Needed because of BYTE_ORDER
|
||||
#include <framework/osal/Endiness.h>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
|
||||
//SHOULDDO: This shall be optimized (later)!
|
||||
void convertToByteStream( uint16_t value, uint8_t* buffer, uint32_t* size ) {
|
||||
buffer[0] = (value & 0xFF00) >> 8;
|
||||
buffer[1] = (value & 0x00FF);
|
||||
|
@ -1,15 +1,8 @@
|
||||
/*
|
||||
* conversion.h
|
||||
*
|
||||
* Created on: 07.05.2012
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef CONVERSION_H_
|
||||
#define CONVERSION_H_
|
||||
|
||||
|
||||
#include <framework/osal/OSAL.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
void convertToByteStream( uint16_t value, uint8_t* buffer, uint32_t* size );
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* crc.cpp
|
||||
*
|
||||
* Created on: 03.04.2012
|
||||
* Author: bucher
|
||||
*/
|
||||
|
||||
#include <framework/globalfunctions/crc_ccitt.h>
|
||||
#include <math.h>
|
||||
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* crc.h
|
||||
*
|
||||
* Created on: 03.04.2012
|
||||
* Author: bucher
|
||||
*/
|
||||
|
||||
#ifndef CRC_CCITT_H_
|
||||
#define CRC_CCITT_H_
|
||||
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* MatchTree.h
|
||||
*
|
||||
* Created on: 09.03.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_GLOBALFUNCTIONS_MATCHING_MATCHTREE_H_
|
||||
#define FRAMEWORK_GLOBALFUNCTIONS_MATCHING_MATCHTREE_H_
|
||||
|
||||
@ -17,11 +10,12 @@ class MatchTree: public SerializeableMatcherIF<T>, public BinaryTree<
|
||||
SerializeableMatcherIF<T>> {
|
||||
public:
|
||||
|
||||
static const uint8_t INTERFACE_ID = MATCH_TREE_CLASS;
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MATCH_TREE_CLASS;
|
||||
static const ReturnValue_t TOO_DETAILED_REQUEST = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t TOO_GENERAL_REQUEST = MAKE_RETURN_CODE(2);
|
||||
static const ReturnValue_t NO_MATCH = MAKE_RETURN_CODE(3);
|
||||
static const ReturnValue_t FULL = MAKE_RETURN_CODE(4);
|
||||
static const ReturnValue_t NEW_NODE_CREATED = MAKE_RETURN_CODE(5);
|
||||
|
||||
typedef typename BinaryTree<SerializeableMatcherIF<T>>::iterator iterator;
|
||||
typedef BinaryNode<SerializeableMatcherIF<T>> Node;
|
||||
@ -41,26 +35,14 @@ public:
|
||||
virtual ~MatchTree() {
|
||||
}
|
||||
virtual bool match(T number) {
|
||||
return matchesTree(number, NULL, NULL);
|
||||
return matchesTree(number);
|
||||
}
|
||||
bool matchesTree(T number, iterator* lastTest, uint8_t* hierarchyLevel) {
|
||||
bool match = false;
|
||||
bool matchesTree(T number) {
|
||||
iterator iter = this->begin();
|
||||
while (iter != this->end()) {
|
||||
if (lastTest != NULL) {
|
||||
*lastTest = iter;
|
||||
}
|
||||
match = iter->match(number);
|
||||
if (match) {
|
||||
iter = iter.left();
|
||||
if (hierarchyLevel != NULL) {
|
||||
(*hierarchyLevel)++;
|
||||
}
|
||||
} else {
|
||||
iter = iter.right();
|
||||
}
|
||||
if (iter == this->end()) {
|
||||
return false;
|
||||
}
|
||||
return match;
|
||||
return matchSubtree(iter, number);
|
||||
}
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
|
||||
@ -134,7 +116,7 @@ public:
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian) {
|
||||
bool bigEndian) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -151,16 +133,22 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: What to do if insertion/deletion fails. Throw event?
|
||||
//SHOULDDO: What to do if insertion/deletion fails. Throw event?
|
||||
ReturnValue_t removeElementAndAllChildren(iterator position) {
|
||||
auto children = erase(position);
|
||||
auto children = this->erase(position);
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
if (children.first != this->end()) {
|
||||
result = removeElementAndAllChildren(children.first);
|
||||
}
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
if (children.second != this->end()) {
|
||||
result = removeElementAndAllChildren(children.second);
|
||||
}
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
//Delete element itself.
|
||||
return cleanUpElement(position);
|
||||
}
|
||||
@ -173,15 +161,19 @@ protected:
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
if (position.left() != this->end()) {
|
||||
result = removeElementAndAllChildren(position.left());
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (position.right() != this->end()) {
|
||||
//There's something at the OR branch, reconnect to parent.
|
||||
if (isOnAndBranch(position)) {
|
||||
//Either one hierarchy up AND branch...
|
||||
insert(AND, position.up(), position.right().element);
|
||||
this->insert(AND, position.up(), position.right().element);
|
||||
} else {
|
||||
//or on another OR'ed element (or install new root node).
|
||||
insert(OR, position.up(), position.right().element);
|
||||
this->insert(OR, position.up(), position.right().element);
|
||||
}
|
||||
} else {
|
||||
if (isOnAndBranch(position)) {
|
||||
@ -189,7 +181,7 @@ protected:
|
||||
return removeElementAndReconnectChildren(position.up());
|
||||
} else {
|
||||
//simply delete self.
|
||||
erase(position);
|
||||
this->erase(position);
|
||||
}
|
||||
|
||||
}
|
||||
@ -201,6 +193,22 @@ protected:
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
bool matchSubtree(iterator iter, T number) {
|
||||
bool isMatch = iter->match(number);
|
||||
if (isMatch) {
|
||||
if (iter.left() == this->end()) {
|
||||
return true;
|
||||
}
|
||||
isMatch = matchSubtree(iter.left(), number);
|
||||
if (isMatch) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (iter.right() == this->end()) {
|
||||
return false;
|
||||
}
|
||||
return matchSubtree(iter.right(), number);
|
||||
}
|
||||
private:
|
||||
uint8_t maxDepth;
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
|
||||
bool match(T input) {
|
||||
if (inverted) {
|
||||
return ~doMatch(input);
|
||||
return !doMatch(input);
|
||||
} else {
|
||||
return doMatch(input);
|
||||
}
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* SerializeableMatcherIF.h
|
||||
*
|
||||
* Created on: 09.03.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_GLOBALFUNCTIONS_MATCHING_SERIALIZEABLEMATCHERIF_H_
|
||||
#define FRAMEWORK_GLOBALFUNCTIONS_MATCHING_SERIALIZEABLEMATCHERIF_H_
|
||||
|
||||
|
@ -4,15 +4,16 @@
|
||||
#include <cmath>
|
||||
#include <stdint.h>
|
||||
|
||||
template<typename T>
|
||||
template<typename T1, typename T2=T1, typename T3=T2>
|
||||
class MatrixOperations {
|
||||
public:
|
||||
virtual ~MatrixOperations() {
|
||||
}
|
||||
|
||||
//do not use with result == matrix1 or matrix2 //TODO?
|
||||
static void multiply(const T *matrix1, const T *matrix2, T *result,
|
||||
//do not use with result == matrix1 or matrix2
|
||||
static void multiply(const T1 *matrix1, const T2 *matrix2, T3 *result,
|
||||
uint8_t rows1, uint8_t columns1, uint8_t columns2) {
|
||||
if ((matrix1 == (T1*)result) || (matrix2 == (T2*)result)){
|
||||
//SHOULDDO find an implementation that is tolerant to this
|
||||
return;
|
||||
}
|
||||
for (uint8_t resultColumn = 0; resultColumn < columns2;
|
||||
resultColumn++) {
|
||||
for (uint8_t resultRow = 0; resultRow < rows1; resultRow++) {
|
||||
@ -26,21 +27,89 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static void transpose(const T *matrix, T *transposed, uint8_t size) {
|
||||
static void transpose(const T1 *matrix, T2 *transposed, uint8_t size) {
|
||||
uint8_t row, column;
|
||||
transposed[0] = matrix[0];
|
||||
for (column = 1; column < size; column++) {
|
||||
transposed[column + size * column] = matrix[column + size * column];
|
||||
for (row = 0; row < column; row++) {
|
||||
T temp = matrix[column + size * row];
|
||||
T1 temp = matrix[column + size * row];
|
||||
transposed[column + size * row] = matrix[row + size * column];
|
||||
transposed[row + size * column] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
MatrixOperations();
|
||||
// Overload transpose to support non symmetrical matrices
|
||||
//do not use with transposed == matrix && columns != rows
|
||||
static void transpose(const T1 *matrix, T2 *transposed, uint8_t rows, uint8_t columns) {
|
||||
uint8_t row, column;
|
||||
transposed[0] = matrix[0];
|
||||
if (matrix == transposed && columns == rows)
|
||||
{
|
||||
transpose(matrix, transposed, rows);
|
||||
}
|
||||
else if (matrix == transposed && columns != rows)
|
||||
{
|
||||
// not permitted
|
||||
return;
|
||||
}
|
||||
for (column = 0; column < columns; column++) {
|
||||
for (row = 0; row < rows; row++) {
|
||||
transposed[row + column * rows] = matrix[column + row * columns];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void add(const T1 *matrix1, const T2 *matrix2, T3 *result,
|
||||
uint8_t rows, uint8_t columns)
|
||||
{
|
||||
for (uint8_t resultColumn = 0; resultColumn < columns; resultColumn++)
|
||||
{
|
||||
for (uint8_t resultRow = 0; resultRow < rows; resultRow++)
|
||||
{
|
||||
result[resultColumn + columns * resultRow] = matrix1[resultColumn + columns * resultRow]+
|
||||
matrix2[resultColumn + columns * resultRow];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void subtract(const T1 *matrix1, const T2 *matrix2, T3 *result,
|
||||
uint8_t rows, uint8_t columns)
|
||||
{
|
||||
for (uint8_t resultColumn = 0; resultColumn < columns; resultColumn++)
|
||||
{
|
||||
for (uint8_t resultRow = 0; resultRow < rows; resultRow++)
|
||||
{
|
||||
result[resultColumn + columns * resultRow] = matrix1[resultColumn + columns * resultRow]-
|
||||
matrix2[resultColumn + columns * resultRow];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void addScalar(const T1 *matrix1, const T2 scalar, T3 *result,
|
||||
uint8_t rows, uint8_t columns)
|
||||
{
|
||||
for (uint8_t resultColumn = 0; resultColumn < columns; resultColumn++)
|
||||
{
|
||||
for (uint8_t resultRow = 0; resultRow < rows; resultRow++)
|
||||
{
|
||||
result[resultColumn + columns * resultRow] = matrix1[resultColumn + columns * resultRow]+scalar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void multiplyScalar(const T1 *matrix1, const T2 scalar, T3 *result,
|
||||
uint8_t rows, uint8_t columns)
|
||||
{
|
||||
for (uint8_t resultColumn = 0; resultColumn < columns; resultColumn++)
|
||||
{
|
||||
for (uint8_t resultRow = 0; resultRow < rows; resultRow++)
|
||||
{
|
||||
result[resultColumn + columns * resultRow] = matrix1[resultColumn + columns * resultRow]*scalar;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* MATRIXOPERATIONS_H_ */
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <framework/globalfunctions/math/QuaternionOperations.h>
|
||||
#include "QuaternionOperations.h"
|
||||
#include <framework/globalfunctions/math/VectorOperations.h>
|
||||
#include "VectorOperations.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
@ -79,7 +78,7 @@ void QuaternionOperations::fromDcm(const double dcm[][3], double* quaternion,
|
||||
|
||||
uint8_t maxAIndex = 0;
|
||||
|
||||
VectorOperations<double>::maxAbsValue(a, 4, &maxAIndex);
|
||||
VectorOperations<double>::maxValue(a, 4, &maxAIndex);
|
||||
|
||||
if (index != 0) {
|
||||
*index = maxAIndex;
|
||||
|
@ -9,8 +9,9 @@ public:
|
||||
|
||||
static void multiply(const double *q1, const double *q2, double *q);
|
||||
|
||||
static void fromDcm(const double dcm[][3],double *quaternion, uint8_t *index = 0);
|
||||
|
||||
static void fromDcm(const double dcm[][3], double *quaternion,
|
||||
uint8_t *index = 0);
|
||||
|
||||
static void toDcm(const double *quaternion, double dcm[][3]);
|
||||
|
||||
static void toDcm(const double *quaternion, float dcm[][3]);
|
||||
@ -28,6 +29,51 @@ public:
|
||||
*/
|
||||
static double getAngle(const double *quaternion, bool abs = false);
|
||||
|
||||
//multiplies 3d vector with dcm derived from quaternion
|
||||
template<typename T>
|
||||
static void multiplyVector(const double *quaternion, const T *vector,
|
||||
T * result) {
|
||||
result[0] =
|
||||
(2.
|
||||
* (quaternion[0] * quaternion[0]
|
||||
+ quaternion[3] * quaternion[3]) - 1.)
|
||||
* vector[0]
|
||||
+ 2.
|
||||
* (quaternion[0] * quaternion[1]
|
||||
+ quaternion[2] * quaternion[3])
|
||||
* vector[1]
|
||||
+ 2.
|
||||
* (quaternion[0] * quaternion[2]
|
||||
- quaternion[1] * quaternion[3])
|
||||
* vector[2];
|
||||
|
||||
result[1] =
|
||||
2.
|
||||
* (quaternion[0] * quaternion[1]
|
||||
- quaternion[2] * quaternion[3]) * vector[0]
|
||||
+ (2.
|
||||
* (quaternion[1] * quaternion[1]
|
||||
+ quaternion[3] * quaternion[3]) - 1.)
|
||||
* vector[1]
|
||||
+ 2.
|
||||
* (quaternion[1] * quaternion[2]
|
||||
+ quaternion[0] * quaternion[3])
|
||||
* vector[2];
|
||||
|
||||
result[2] =
|
||||
2.
|
||||
* (quaternion[0] * quaternion[2]
|
||||
+ quaternion[1] * quaternion[3]) * vector[0]
|
||||
+ 2.
|
||||
* (quaternion[1] * quaternion[2]
|
||||
- quaternion[0] * quaternion[3])
|
||||
* vector[1]
|
||||
+ (2.
|
||||
* (quaternion[2] * quaternion[2]
|
||||
+ quaternion[3] * quaternion[3]) - 1.)
|
||||
* vector[2];
|
||||
}
|
||||
|
||||
private:
|
||||
QuaternionOperations();
|
||||
};
|
||||
|
@ -38,11 +38,11 @@ public:
|
||||
}
|
||||
|
||||
static void subtract(const T vector1[], const T vector2[], T sum[],
|
||||
uint8_t size = 3) {
|
||||
for (; size > 0; size--) {
|
||||
sum[size - 1] = vector1[size - 1] - vector2[size - 1];
|
||||
}
|
||||
uint8_t size = 3) {
|
||||
for (; size > 0; size--) {
|
||||
sum[size - 1] = vector1[size - 1] - vector2[size - 1];
|
||||
}
|
||||
}
|
||||
|
||||
static T norm(const T *vector, uint8_t size) {
|
||||
T result = 0;
|
||||
@ -76,6 +76,26 @@ public:
|
||||
return max;
|
||||
}
|
||||
|
||||
static T maxValue(const T *vector, uint8_t size, uint8_t *index = 0) {
|
||||
|
||||
T max = -1;
|
||||
|
||||
for (; size > 0; size--) {
|
||||
if (vector[size - 1] > max) {
|
||||
max = vector[size - 1];
|
||||
if (index != 0) {
|
||||
*index = size - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
|
||||
static void copy(const T *in, T *out, uint8_t size) {
|
||||
mulScalar(in, 1, out, size);
|
||||
}
|
||||
|
||||
private:
|
||||
VectorOperations();
|
||||
};
|
||||
|
@ -1,8 +1,4 @@
|
||||
#include <framework/globalfunctions/timevalOperations.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdint.h>
|
||||
|
||||
//TODO test with large numbers
|
||||
|
||||
timeval& operator+=(timeval& lhs, const timeval& rhs) {
|
||||
int64_t sum = lhs.tv_sec * 1000000. + lhs.tv_usec;
|
||||
|
@ -32,6 +32,14 @@ bool operator<=(const timeval& lhs, const timeval& rhs);
|
||||
bool operator>=(const timeval& lhs, const timeval& rhs);
|
||||
|
||||
namespace timevalOperations {
|
||||
/**
|
||||
* returns the seconds and subseconds stored in the timeval
|
||||
* as double [s]
|
||||
*
|
||||
*
|
||||
* @param timeval
|
||||
* @return seconds
|
||||
*/
|
||||
double toDouble(const timeval timeval);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user