Sign in

username:

password:



Not a member?

Search basicx



Search tips

Subscribe to basicx



basicx by Keywords

Accelerometer | ADC | ADXL | Adxl20 | AVR | BasicStamp | BX-35 | BX28 | BX35 | COM3 | Compiler | Downloader | EEPROM | Electromagnet | GetADC | GP2D1 | GPS | I2C | IDE | Keypad | LCD | LCD+ | MIDI | Motors | Multitasking | Netmedia | Networking | PCB | PID | PlaySound | PWM | Relays | RTC | Servo | ShiftOut | SitePlayer | SPI | Stack | Timer | USB

Ads

Discussion Groups

Discussion Groups | BasicX | C Translation help.

Discussion forum for the BasicX family of microcontroller chips.

Re: C Translation help. - Kevin Quinn - Jan 6 15:04:00 2004

Francisco -

Have you read this:
http://home.earthlink.net/~david.schultz/rnd/2002/KalmanApogee.pdf

It discusses the underlying algorithms, and may make the code you're
working with easier to understand (and to port).

Kevin Quinn





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )


Re: C Translation help. - Don Kinzer - Jan 6 20:58:00 2004

--- In , Francisco Lobo <francisco@f...> wrote:

Replies are interspersed with questions below.

> 1st) Does basicX support two dimensional arrays? Yes. According to the Basic Express Language Reference (q.v., p. 24)
it supports up to 8 dimension arrays. > 2nd )
>
> I see in C++ two type of const declarations, once that says
> (Static Const Float X = 0.01 -- And another one that says
> Const Float X). Would the latter be a variable declaration
> or a constant declaration without initialization?

In C and C++, the const qualifier is a hint to the compiler that the
data element is supposed to be constant, i.e. assignments to it
aren't allowed (except for compile-time initialization). The
compiler may choose to place the data element in ROM if that is
supported or in RAM along with variables. The first instance that
you cited is a constant data definition - meaning that the type is
defined and its value is specified. The compiler reserves storage
for a data element when it sees its definition.

The second instance is a constant data declaration. This simply
notifies the compiler that the data element of the given type exists
somewhere. No storage is reserved by a declaration so there must be
at least one definition (and if there are multiple definitions they
must all agree in all respects) but there may be many declarations. >
> 3d) Can someone actually help me translate this lines from C++:
>
> A)
> ----------------
> static float P[2][2] = {
> { 1, 0 },
> { 0, 1 },
> }; This declares a 2x2 array and specifies the value of all of its
elements. N.B. In C and C++, arrays are indexed beginning with
zero. The first initialization gives the values for P[0][0] and P[0]
[1], the second line gives the values for P[1][0] and P[1][1].

The 'static' storage class specifier in C and C++ means that the data
element is private to the compilation module containing it. If it
occurs inside of a function definition, it also means that the data
element is allocated storage in RAM instead of on the stack. This
means that the initialization is only done once (at load time) and if
the data element is changed during execution, the changed value will
persist across function invocations. > const float Pdot[2 * 2] = {
> Q_angle - P[0][1] - P[1][0], /* 0,0 */
> - P[1][1], /* 0,1 */
> - P[1][1], /* 1,0 */
> Q_gyro /* 1,1 */
> };

This declares a single dimension array with 4 elements. However, the
comments suggest that it is going to be references as if it were a
2x2 array. The compiler won't allow such references but it is likely
that the code takes one index and multiplies it by two and then adds
a second index to compute the index into this single dimension
array. This might or might not be clever coding - there's not enough
information provided to know why it might be done this way.
>
> ----------
>
> B)
> ---------
> /* Update the covariance matrix */
> P[0][0] += Pdot[0] * dt;
> P[0][1] += Pdot[1] * dt;
> P[1][0] += Pdot[2] * dt;
> P[1][1] += Pdot[3] * dt;
> --------------- > 4th) What does P[2][2] means --> P(2,2) ????

Precisely.

> 5th) What does P[2 * 2] Means ???? P(2,2) or actually P(4) ???. Is
this
> a one dimensional array???

It is a one dimensional array but, apparently, thought of as a 2x2.

> 6th) Does :
> C++> angle += angle_dot * dt
> BX > Angle = Angle + (Angle_dot * dt)

You are correct. The op= operators are one of the many ways that C
and C++ allow efficient expression of concepts. Some argue that it
needlessly complicates things. My view is that it is a very
efficient shorthand notation for operations that are done very
frequently in programming and it is handy to have succinct idioms for
them.

By the way, none of the constructs that you have enumerated here are
specific to C++ - it's just plain C (well, plain ANSI C anyway).
There may be C++ constructs used in your program but it also may well
be all C code. If you want to learn to read C code you may want to
locate the book written by the creators of C namely Brian Kernighan
and Dennis Ritchie. The title of the very readable book is "The C
Programming Language". Be sure that you get the second edition which
was updated to match the ANSI C standard. You can likely find a used
one for a few dollars.

Don





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Re: C Translation help. - Frank Manning - Jan 7 15:57:00 2004

> Francisco Lobo <francisco@f...> wrote:

> [...] i am trying to implement a two state kalman
> filter that is used to remove noice from a tilt
> sensor. It uses inputs from an accelerometer and
> a gyro (angle input and angle rate). [...]

You might also check out message 14351 (22 Sep 2003), also related
to Kalman filtering:

> If any of you have ever considered building a two
> wheel balancing robot, here is some code that I
> have written.
>
> http://home.everestkc.net/cvogt/New%20Kalman%20Code.zip
>
> It samples an angular rate gyroscope about 150
> times per second, [...]

-- Frank Manning
-- NetMedia, Inc.





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Re: C Translation help. - Francisco Lobo - Jan 7 22:49:00 2004

THANKS THANKS ALOT!!! It really helped. I got it working.... Its just
the little things i mention that got me stock. I am getting that book,
and i agree that op= is a great way of doing things. It will be great
to see this implementations one day in Basicx, although is not standard
basic :) Thanks Alot.

On Jan 6, 2004, at 7:58 PM, Don Kinzer wrote:

> --- In , Francisco Lobo <francisco@f...> wrote:
>
> Replies are interspersed with questions below.
>
>> 1st) Does basicX support two dimensional arrays?
>>
>
> Yes. According to the Basic Express Language Reference (q.v., p. 24)
> it supports up to 8 dimension arrays.
>
>>
>> 2nd )
>>
>> I see in C++ two type of const declarations, once that says
>> (Static Const Float X = 0.01 -- And another one that says
>> Const Float X). Would the latter be a variable declaration
>> or a constant declaration without initialization?
>
> In C and C++, the const qualifier is a hint to the compiler that the
> data element is supposed to be constant, i.e. assignments to it
> aren't allowed (except for compile-time initialization). The
> compiler may choose to place the data element in ROM if that is
> supported or in RAM along with variables. The first instance that
> you cited is a constant data definition - meaning that the type is
> defined and its value is specified. The compiler reserves storage
> for a data element when it sees its definition.
>
> The second instance is a constant data declaration. This simply
> notifies the compiler that the data element of the given type exists
> somewhere. No storage is reserved by a declaration so there must be
> at least one definition (and if there are multiple definitions they
> must all agree in all respects) but there may be many declarations.
>
>>
>>
>> 3d) Can someone actually help me translate this lines from C++:
>>
>> A)
>> ----------------
>> static float P[2][2] = {
>> { 1, 0 },
>> { 0, 1 },
>> };
>>
>
> This declares a 2x2 array and specifies the value of all of its
> elements. N.B. In C and C++, arrays are indexed beginning with
> zero. The first initialization gives the values for P[0][0] and P[0]
> [1], the second line gives the values for P[1][0] and P[1][1].
>
> The 'static' storage class specifier in C and C++ means that the data
> element is private to the compilation module containing it. If it
> occurs inside of a function definition, it also means that the data
> element is allocated storage in RAM instead of on the stack. This
> means that the initialization is only done once (at load time) and if
> the data element is changed during execution, the changed value will
> persist across function invocations.
>
>>
>> const float Pdot[2 * 2] = {
>> Q_angle - P[0][1] - P[1][0], /* 0,0 */
>> - P[1][1], /* 0,1 */
>> - P[1][1], /* 1,0 */
>> Q_gyro /* 1,1 */
>> };
>
> This declares a single dimension array with 4 elements. However, the
> comments suggest that it is going to be references as if it were a
> 2x2 array. The compiler won't allow such references but it is likely
> that the code takes one index and multiplies it by two and then adds
> a second index to compute the index into this single dimension
> array. This might or might not be clever coding - there's not enough
> information provided to know why it might be done this way.
>>
>> ----------
>>
>> B)
>> ---------
>> /* Update the covariance matrix */
>> P[0][0] += Pdot[0] * dt;
>> P[0][1] += Pdot[1] * dt;
>> P[1][0] += Pdot[2] * dt;
>> P[1][1] += Pdot[3] * dt;
>> ---------------
>>
>>
>> 4th) What does P[2][2] means --> P(2,2) ????
>
> Precisely.
>
>> 5th) What does P[2 * 2] Means ???? P(2,2) or actually P(4) ???. Is
> this
>> a one dimensional array???
>
> It is a one dimensional array but, apparently, thought of as a 2x2.
>
>> 6th) Does :
>> C++> angle += angle_dot * dt
>> BX > Angle = Angle + (Angle_dot * dt)
>
> You are correct. The op= operators are one of the many ways that C
> and C++ allow efficient expression of concepts. Some argue that it
> needlessly complicates things. My view is that it is a very
> efficient shorthand notation for operations that are done very
> frequently in programming and it is handy to have succinct idioms for
> them.
>
> By the way, none of the constructs that you have enumerated here are
> specific to C++ - it's just plain C (well, plain ANSI C anyway).
> There may be C++ constructs used in your program but it also may well
> be all C code. If you want to learn to read C code you may want to
> locate the book written by the creators of C namely Brian Kernighan
> and Dennis Ritchie. The title of the very readable book is "The C
> Programming Language". Be sure that you get the second edition which
> was updated to match the ANSI C standard. You can likely find a used
> one for a few dollars.
>
> Don
---------------------------------------------
Francisco Lobo de la Garza
CEO/Director General
movic Records
elcielo Recording Studio
Garza Garcia N.L Mexico
---------------------------------------------
Grupo Fusion Global
Copyright(c) 2003-2004
---------------------------------------------------
POR FAVOR no incluyas este mail en
listas de correo ni en sistemas
automatizados de mensajes.
PLEASE do not include this email
address in any mailing list or
newsletters.





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Re: C Translation help. - Francisco Lobo - Jan 7 22:51:00 2004

WOW... This is great code!!! its really somthing. Who wrote it? I need to get in touch with him.... THanks
Bye

On Jan 7, 2004, at 2:57 PM, Frank Manning wrote:

>> Francisco Lobo <francisco@f...> wrote:
>
>> [...] i am trying to implement a two state kalman
>> filter that is used to remove noice from a tilt
>> sensor. It uses inputs from an accelerometer and
>> a gyro (angle input and angle rate). [...]
>
> You might also check out message 14351 (22 Sep 2003), also related
> to Kalman filtering:
>
>> If any of you have ever considered building a two
>> wheel balancing robot, here is some code that I
>> have written.
>>
>> http://home.everestkc.net/cvogt/New%20Kalman%20Code.zip
>>
>> It samples an angular rate gyroscope about 150
>> times per second, [...]
>
> -- Frank Manning
> -- NetMedia, Inc.
---------------------------------------------
Francisco Lobo de la Garza
CEO/Director General
movic Records
elcielo Recording Studio
Garza Garcia N.L Mexico
---------------------------------------------
Grupo Fusion Global
Copyright(c) 2003-2004
---------------------------------------------------
POR FAVOR no incluyas este mail en
listas de correo ni en sistemas
automatizados de mensajes.
PLEASE do not include this email
address in any mailing list or
newsletters.





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Re: C Translation help. - Frank Manning - Jan 8 13:32:00 2004

From: Francisco Lobo <>

> On Jan 7, 2004, at 2:57 PM, Frank Manning wrote:
>>
>> You might also check out message 14351 (22 Sep 2003), also
>> related to Kalman filtering: [...]
>
> WOW... This is great code!!! its really somthing. Who
> wrote it?
>
> I need to get in touch with him....

Kyle Vogt, "camel85kv" <>

Sorry, should have included more information...

-- Frank Manning
-- NetMedia, Inc.




(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

C Translation help. - Francisco Lobo - Dec 6 9:09:00 2004

Hello all. I am doing a conversion from C++ to BasicX, i am trying to
implement a two state kalman filter that is used to remove noice from a
tilt sensor. It uses inputs from an accelerometer and a gyro (angle
input and angle rate). The accelerometer gives the actual angle, but
when the unit is moving forward it will start to report wild values
(actual acceleration) and not actual angle, that's when the gyro kicks
in and the kalman filter uses the gyro instead of the accelerometer,
integrating gyro rate to get real gyro. The gyro also reports a drift
over time, so we need the long term average of the accelerometer. The
goal is to get as real as an angle as possible. So i found a real good
implementation of the kalman filter in C++, but some commands i don't
know how to use them. I guess i could find some help here. We actually
integrate Angle Rate from the gyro to get real angle and derivate the
accelerometer value to get a confirmation of the angle and de-drift the
sensor. Mainly when we get angle_rate and the angle from the accel is
at zeroes, this means we are getting drift from the gyro, and when the
gyro reports a tilt rate and the accel is reading wild values this
means we are actually tilting. THat way we isolate sensor errors. We
actually weight the input values and assign them how much we actually
trust the input and plot it, then get a least squares closes line to
get a linear value. Well too much techie here, i actually got a code
that works OK, but its in C++ and i work with basicX, i dont know if BX
is powerfull enough for this math, but i have to guess yes. So here are
my questions for you C++ hard coders or any one of you who might know
the answer. Thanks in advance!!!!

1st) Does basicX support two dimensional arrays? 2nd )

I see in C++ two type of const declarations, once that says (Static
Const Float X = 0.01 -- And another one that says Const Float X) Would
the latter be a variable declaration or a constant declaration without
initialization? 3d) Can someone actually help me translate this lines from C++:

A)
----------------
static float P[2][2] = {
{ 1, 0 },
{ 0, 1 },
};
const float Pdot[2 * 2] = {
Q_angle - P[0][1] - P[1][0], /* 0,0 */
- P[1][1], /* 0,1 */
- P[1][1], /* 1,0 */
Q_gyro /* 1,1 */
};

----------

B)
---------
/* Update the covariance matrix */
P[0][0] += Pdot[0] * dt;
P[0][1] += Pdot[1] * dt;
P[1][0] += Pdot[2] * dt;
P[1][1] += Pdot[3] * dt;
--------------- 4th) What does P[2][2] means --> P(2,2) ????

5th) What does P[2 * 2] Means ???? P(2,2) or actually P(4) ???. Is this
a one dimensional array???

6th) Does :
C++> angle += angle_dot * dt
BX > Angle = Angle + (Angle_dot * dt)

Is this a correct translation?

I would really really apriciate some help here, i ran into a wall and i
need to climb it. I tried several implementations but without any good
results. Can someone help pls???? Thanks
Bye





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )