How to share one math function with many subsets?

I am programming a navigation method that is similar as in Flight Management Computer as in year 2000 but in '50s method, one of them is in Ilyushin Il-62 that was built in Soviet Union. More explanation how it works is in internet; there you can download flightdocuments, which I found roughly 2000 pages manual how the Il-62 airplane works in aerodynamics and technical that explaining how instruments works but not the computer built by relays.

Link please? Are the documents in English or Russian?

The documents are in russian language. You will find in Files, Aviadokumentatsiya, in www.avsim.su. Search with word "il62" in standard alphabet that you writing in this forum; so, you do not need to write in cyrillic.

I see that I cannot make array in float; only byte and integer is supported.. Why do Atmel prevent? And, I see that I cannot store float, 32-bit, in PROGMEM... Integer has up to 16-bit in MEGA2560 Why do Atmel prevent this opportunity for they who care and want to save SRAM to avoid unneccessary lot usage while they run Critical apps that require much SRAM; for example, run 3-4 different programs from SD card in an Arduino Uno. I thought that Arduino is open-sourced????? Or is it really?

I wondering why byte, char, float have different meanings even they are just binary? I understand the necessary 8-bit, 16-bit, 32-bit to save speed. But I do not understand why that byte, char, float, integer, unsigned integer can't share same memory address through malloc method that is a great opportunity to programming special algorithm by pure binary value such opportunity to build advanced smallest possible program size for my hobby home cockpit. I know about overflow and a program can crash, but I will learn so long I become older.

:)

I submit for evidence...

float FloatArray[2];
const float PROGMEM PMFloat = -3.456;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while(!Serial);
  
  FloatArray[1] = 1.234 + PMFloat;
  
  Serial.println(FloatArray[1]);
  Serial.println(PMFloat);
}

void loop() {
  // put your main code here, to run repeatedly:

}

Compiled and tested on an Arduino Mini. (Results may be different on other Arduinos but I would be surprised.)

I don't think you understand what open-source means.

Yes, you can overlap different-sized variables in memory. This is useful only in certain situations so it's not taught very often. 99% of the time this would be an exceedingly bad idea.

I see that I cannot make array in float;

You are wrong

Qwseyvnd: Fourth thought:

void trigonometry(){

float result1 = pointx * pointx; float result2 = pointy * pointy; double result3 = result1 + result2; double result4 = result3 ^ 0.5; But the function ^ is not supported in Arduino? Or restriction in Atmel AVR-GCC?

}

The pointx and pointy share with many subset in { and } to save bytes. Maybe using goto function? Pointer function to share pointx and pointy ?

I am responding to this because there seems to have been little progress in all the subsequent posts.

If pointx and pointy are global variables this type of code can work perfectly well.

Rather than using ^ to calculate a power C/C++ uses ** As @AWOL has pointed out, this is wrong. I was mixing up Python and C/C++. The correct way is to use the pow() function. Sorry for the confusion.

The big problem with this piece of code is that its results arent available outside it because the calculated values goe into local variables which are lost as soon as the function completes. Make all the variables global.

...R

Rather than using ^ to calculate a power C/C++ uses **

?

Robin2:
I am responding to this because there seems to have been little progress in all the subsequent posts.

If pointx and pointy are global variables this type of code can work perfectly well.

Rather than using ^ to calculate a power C/C++ uses **

The big problem with this piece of code is that its results arent available outside it because the calculated values goe into local variables which are lost as soon as the function completes. Make all the variables global.

…R

Yes I know that the local variables become lost so I think each local variable x and y copy to pointx and pointy then copy back to local variable then the next variable copy to pointx and pointy to recalculate, and so on; so, no variables are actually lost.

Well, I know copy memory address cost a little bit of performance.

I tried to program: int heading = 0; float katet = 0; float pointx = 0; float pointy = 0; float coordinatex = 0; float coordinatey = 0; float coordinatexy = 0;

included void setup and void loop with the option that is not shown here.

float trigonometry() = { float coordinatex = pointx * pointx; float coordinatey = pointy * pointy; float coordinatexy = coordinatex + coordinatey; float katet = coordinatexy ** 0.5; }

I got those error while I am trying to confirm: pseudo.ino: In function 'void loop()': pseudo:62: error: invalid pure specifier (only '= 0' is allowed) before 'float' pseudo:62: error: function 'float trigonometry()' is initialized like a variable pseudo:65: error: invalid type argument of unary '*' (have 'double') invalid pure specifier (only '= 0' is allowed) before 'float'

Are you trying to create a class with a pure virtual method? Have you got the class it is supposed to go in? What's wrong with a simple function?

I'm really confused - is this supposed to be some sort of coroutine?

This thread is a mess of mixed messages (and ego)...

As for my 2cents, maybe he simply wants/needs to pass variables to functions by reference?

AWOL:

Rather than using ^ to calculate a power C/C++ uses **

?

Oh dear ... I fear I have been mixing up Python and C.

C/C++ needs the pow() function

I will edit my earlier post

...R

I think it should be like this

int heading = 0;
float katet = 0;
float pointx = 0;
float pointy = 0;
float coordinatex = 0;
float coordinatey = 0;
float coordinatexy = 0;

//included void setup and void loop with the option that is not shown here.

float trigonometry() = {
 coordinatex = pointx * pointx;
 coordinatey = pointy * pointy;
 coordinatexy = coordinatex + coordinatey;
 katet = pow(coordinatexy, 0.5);
}

As well as the error about ** which was all my fault (apologies), the important thing to note is the absence of "float" within the function. When you place "float" before the variable in a function the compiler creates a new local variable that just happens to have the same name as the global variable - but they are quite different - the local variable is lost as soon as the function completes and nothing will have happened to the global variable.

...R

Robin2: I think it should be like this

int heading = 0;
float katet = 0;
float pointx = 0;
float pointy = 0;
float coordinatex = 0;
float coordinatey = 0;
float coordinatexy = 0;

//included void setup and void loop with the option that is not shown here.

float trigonometry() = { coordinatex = pointx * pointx; coordinatey = pointy * pointy; coordinatexy = coordinatex + coordinatey; katet = pow(coordinatexy, 0.5); }



As well as the error about ** which was all my fault (*apologies*), the important thing to note is the absence of "float" within the function. When you place "float" before the variable in a function the compiler creates a new local variable that just happens to have the same name as the global variable - but they are quite different - the local variable is lost as soon as the function completes and nothing will have happened to the global variable.

...R

I know that the local variable will be lost but it is just to copy to the correct variable for each time; so, therefore I need to call trigonometry(); each point is in use.

Let me explaining the way to use navigation system:

  • The P-13-4 unit is to store russian style SID and STAR waypoints, go-around, approach and take-off, and optional waypoint around the airport which I want to use PROGMEM to store long time value that is not in change usually as the PPM and RSBN units.

If you notice the word go-around, I have stored it as "byte stepper[8]= B10100;" I have four digit binary value in 0 to 7 for in use with the stepper motor. If it is at Y position, it will be B1010 then turn to B10100 then B1010 then B1010; while it is at at left or right pattern. It contains five waypoints in rectangle, X 10 km and Y 20 km with toggle switch to choose left or right. It is calculating at the nearest position of the zero position with RSBN or VOR with two headings which one of them is airplane direction and another heading for the RSBN or VOR station.

  • The X and Y coordinate point is to store the third coordinate for the first PPM unit while the second PPM is in use; first and second is run at each turn automatic or manual, it is just a direction point with heading, if X is null and Y is at minus 1000 km, it is at correct path but if X is at pluss 64 km between at the track position, it is at minus 64km too far at the X path.

  • The Radio system beacon naviation is to use for either correcting continously or indicate if the airplane is flown correct on the fly with channel option from 1 to 40, similar as to VOR which is also accessible to the navigation system if it is in for example in Africa which have just VOR station. ADF can also be in use just to indicate the correct heading but it have just heading direction. Also, it is in use for airport point for use with P-13-4 unit.

Read more at aerodocuments about Il-62 at www.avsim.su.

Qwseyvnd: I know that the local variable will be lost but it is just to copy to the correct variable for each time; so, therefore I need to call trigonometry(); each point is in use.

I don't understand what you are thinking.

The reason I said the local variables will be lost is because you had NOTHING in your version of the code that could possibly do anything useful. It would be like whispering a message in a messenger's ear, telling him to take the message to the King and then shooting the messenger before he leaves your house.

For the moment never mind what your overall navigation system is intended to do. Let's just concentrate on figuring out what you want to do with this function.

I still don't understand what you have in mind when you talk about

share With one same function on some subset With {} that share same calculation trigonometry Method.

(from Reply #5)

Have a look at how the code is laid out in separate functions in Planning and implementing a program and then try to explain how you want your code to work.

And, without meaning to be unkind, I have no intention of taking the time to "Read more at aerodocuments about Il-62 ". I would prefer to use the time to help with another Thread.

...R

I still get the feeling that passing arguments by reference could be the solution.

But yes, I agree the problem remains unclear...

1:1: I still get the feeling that passing arguments by reference could be the solution.

But yes, I agree the problem remains unclear...

Yes, there are many missing functions in the Reference. I do not know why Arduino team do not added them such as: - A bit more arithmetic options such as ^ - More explanations about PIN, PORT, DDR - More explanations about Serial and Stream section - More explanations at void (name)(){} - Support store variables in PROGMEM without just only read-only which to save SRAM when it is necessary (I see that just char is possible in pgmspace.h) But it is possible to convert from float to char. - support 64-bit value in arduino except DUE even it runs slower because it is just 8-bit (or 16-bit?) - And so on...

If I trying to pass the reference/confirmed by Atmel and anyone who making compiler without Atmel's approval, they who are developing the Atmel Compiler will blocking possibilites that is reasoned by bureauracy and maybe also authority by money reason. Write access to PROGMEM was possible before IDE version 1.0.6 I think. I do not want to use unpaid hours to solve so long Atmel do not approved it.

Sqrt() is just limited to a number of bits value. Maybe sometimes I need 64-bit in a specific situation to run at 16 MHz because it does not need faster so I prefer passing arguments in the Reference.

I do not know why Arduino team do not added them such as

So as not to scare off the hobbyists and artists?

More arithmetic options

Like what?

More explanations about PIN, PORT, DDR

See my first response.

  • ----||-------------------- Serial and Stream section
  • -------||----------------- void (name)(){} is possible

I have no idea what that means.

  • Support store variables in PROGMEM without just only read-only which to save SRAM when it is necessary

Store variables in the same space as your program? Risky.

support 32-bit value in arduino except DUE even it runs slower because it is just 8-bit (or 16-bit?)

RTFM

I have one Arduino MEGA2560 and one DUE. I do not know why many functions is not included in Reference; but at least, it could have included Advanced Section with such functions...

Sorry, but I am honest, maybe it is better I find other development board because of restrictions and missing functions in Arduino ????