Difference between revisions of "DevGuide/StateInterface"

From PaparazziUAV
Jump to navigation Jump to search
Line 33: Line 33:
extern struct Int32Vect3 airspeed;
extern struct Int32Vect3 airspeed;
extern struct Int32Vect3 windspeed;
extern struct Int32Vect3 windspeed;
</pre>
Some other possible states:
<pre>
UTM position
Speed norm/dir
Airspeed norm
Heading ?
AGL ?
+ all the previous states available in float
</pre>
Everything should be in a "state" structure.
=== How to set/get the state ? ===
== On time computation ==
With this solution, the state can be updated and read with any format with a little overhead (do some tests on a status).
The conversion is done only if needed and is not done again until the state is updated.
The following structure has to be done for the different "groups" of states: position, speed, attitude,...
<pre>
#define XXX 1<<0
#define YYY 1<<1
#define ZZZ 1<<2
uint XYZ_status;
// set the new value and reset the status to tell that other format are not up to date anymore
#define STATE_SET_XXX(_v) {
state.XXX = _v;
pos_status = XXX;
}
--> do the same for YYY and ZZZ, and even for XXX_YYY, XXX_ZZZ, ... if needed
// get the value and transformation if needed
#define STATE_GET_XXX(_r) {
if (status bit XXX is not set) {
  transform_XXX();
  set bit XXX in status;
}
_r = XXX;
}
--> do the same for the other states
// conversion function
// the order the "if _ else if _" is chosen to begin with the less cpu consuming conversions
void transform_XXX() {
if (status bit YYY is set) {
  compute XXX_of_YYY;
} else
if (status bit ZZZ is set) {
  compute XXX_of_ZZZ;
} else
{ // default, no data available
  XXX = ZERO ?
  set UNINIT flag somewhere ?
}
}
--> do the same for the other states
--> maybe a part of this could be generated ?
--> we can use functions instead of macros
</pre>
</pre>

Revision as of 03:24, 13 January 2011

The idea is to create a general state interface that holds the most important vehicle states like attitude, position, speed, acceleration.

state.h

/* Earth Centered Earth Fixed in centimeters */
extern struct EcefCoor_i ecef_pos;

/* lon, lat in radians*1e7  */
/* alt in centimeters       */
extern struct LlaCoor_i lla_pos;

/* definition of the local (flat earth) coordinate system */
extern struct LtpDef_i ltp_def;
extern bool_t ltp_initialised;

/* North East Down local tangent plane */
extern struct NedCoor_i ltp_pos;
extern struct NedCoor_i ltp_speed;
extern struct NedCoor_i ltp_accel;

/* East North Up local tangent plane */
extern struct EnuCoor_i enu_pos;
extern struct EnuCoor_i enu_speed;
extern struct EnuCoor_i enu_accel;

/* vehicle attitude */
extern struct Int32Quat   body_quat;
extern struct Int32Eulers body_euler;
extern struct Int32RMat   body_rmat;
extern struct Int32Rates  body_rate;

/* wind and airspeed*/
extern struct Int32Vect3 airspeed;
extern struct Int32Vect3 windspeed;

Some other possible states:

UTM position
Speed norm/dir
Airspeed norm
Heading ?
AGL ?
+ all the previous states available in float

Everything should be in a "state" structure.

How to set/get the state ?

On time computation

With this solution, the state can be updated and read with any format with a little overhead (do some tests on a status).

The conversion is done only if needed and is not done again until the state is updated.

The following structure has to be done for the different "groups" of states: position, speed, attitude,...

#define XXX 1<<0
#define YYY 1<<1
#define ZZZ 1<<2
uint XYZ_status;

// set the new value and reset the status to tell that other format are not up to date anymore
#define STATE_SET_XXX(_v) {
 state.XXX = _v;
 pos_status = XXX;
}
--> do the same for YYY and ZZZ, and even for XXX_YYY, XXX_ZZZ, ... if needed

// get the value and transformation if needed
#define STATE_GET_XXX(_r) {
 if (status bit XXX is not set) {
  transform_XXX();
  set bit XXX in status;
 }
 _r = XXX;
}
--> do the same for the other states

// conversion function
// the order the "if _ else if _" is chosen to begin with the less cpu consuming conversions
void transform_XXX() {
 if (status bit YYY is set) {
  compute XXX_of_YYY;
 } else
 if (status bit ZZZ is set) {
  compute XXX_of_ZZZ;
 } else
 { // default, no data available
  XXX = ZERO ?
  set UNINIT flag somewhere ?
 }
}
--> do the same for the other states

--> maybe a part of this could be generated ?
--> we can use functions instead of macros