256 views
in System Integration by

Hello EW Team,

I am plotting a Sine Wave graph using Stroked Path, which scales to 50% as soon as cycles gets complete at a particular value. The project gives exactly what I am expecting but I am unable to understand a few sections of code. About values of graph:

Step 1: One cycle has 80 values. X axis starts from 0 and increments by 4.5, which ends at 360(80*4.5). Y has Sine values multiplied by 50, just a random scaling number. Initially plotting graph on Path1_Subpath0.

Step 2: At 81th value, I am scaling the X values to half and copying the graph from Path1_Subpath0 to Path1_Subpath1. Now the Cycle1 ends at 180 which is half of 360.

Step 3: Continuing the same up to 160values, so as to get 1 more cycle till 360 at X axis. Now I have 2 cycles till 360 at X axis.

Step 4: At 161th value, I am copying the data to (after clearing the initial values) to Path1_Subpath0. Now I have 2 cycles in my plot. 

This process continues till 1000 values to plot.

QUERY:

1. In project, I have used trace "posX= ",posX, "Value of posX= ",Path1.GetNodeX( 0,noOfEdge); at many places. I don't understand why these values are different.

2. 80th value ends at 180 and 81th starts at 180 at X axis. 81 value which is logically half (182.25) of what usually would have been (without scaling- 364.5). This is well understood and perfect up to 160 values. After that I have to use posX/2 or posX/4 or posX/8 to restart the plotting at the last saved X position. Why is that so?

3. Is there any way to make a plot in which, I plot upto 360 values first and then with every next value, graph re-scales to add that new value.

Please note that I observed the concept of plotting in SolarDemo Example project. In that, with every new value, graph shifts from left end to plot value at right end. I don't want scrolling effect. 

I am attaching the Project and log for reference.

Thanks & Regards,

Vandana Matai

1 Answer

0 votes
by

Hello Vandana Matai,

I'm not sure whether the implementation is built that way on purpose or whether it is an error, so I'm not sure whether I can help you. Let me address your questions:

1. In project, I have used trace "posX= ",posX, "Value of posX= ",Path1.GetNodeX( 0,noOfEdge); at many places. I don't understand why these values are different.

So far I don't see any error in the logged numbers. Let us analyze the code section at the end of the method onUpdatePath:

else if (noOfEdge <= 1001)			
{
  Path1.AddLine(0,posX/8,newValue);
  trace "posX= ",posX,"posX/4= ",posX/8,"Value of posX= ",Path1.GetNodeX( 0,noOfEdge);
}

... and the corresponding logged values:

(1) trace: "posX= ", 4495.5, "posX/4= ", 561.9375, "Value of posX= ", 280.6875.

(2) trace: "posX= ", 4500.0, "posX/4= ", 562.5, "Value of posX= ", 280.96875.

(3) trace: "posX= ", 4504.5, "posX/4= ", 563.0625, "Value of posX= ", 280.96875.

...

(N) trace: "posX= ", 4581.0, "posX/4= ", 572.625, "Value of posX= ", 280.96875.

The logged value posX ist o.k. With each step it increments by 4.5. The trace value posX/4 is incorrectly logged. In fact the implementation calculates with posX/8. Nevertheless with 1/8 my calculator produces the same results accordingly. The last traced value GetNodeX( 0, noOfEdges ) is confusing a little bit. GetNodeX() queries the value stored at position noOfEdges. This corresponds to last position in the path. However, in your implementation you perform shortly before an AddLine() operation. The value provided in AddLine() is thus stored at position noOfEdges+1. Querying the value at noOfEdges returns thus the value from the preceding iteration. This explains why "Value of posX" does correspond to the calculation from the line above.

Also important is that values returned by GetNodeX() are half of what you stored there in advance. This is correct, since at step 81 you have configured the path to scale the X coordinates by 0.5. This configuration remains active and affects the coordinates passed in all subsequent AddLine() and other AddXXX() invocations.

Interesting is that once posX assumed the value 4500, there is no change in "Value of posX". It is always 280.96875. The explanation is clear, the path is configured with capacity of 1000 edges. With the value 4500 you have added 1000 edges to the path (1000 * 4.5 = 4500). From this moment the AddLine() operation have no effect anymore. 

2. 80th value ends at 180 and 81th starts at 180 at X axis. 81 value which is logically half (182.25) of what usually would have been (without scaling- 364.5). This is well understood and perfect up to 160 values. After that I have to use posX/2 or posX/4 or posX/8 to restart the plotting at the last saved X position. Why is that so?

I think this is because with step 81 the path has been configured to scale all values by factor 0.5. This configuration is still active and affects all AddLine() operations.

3. Is there any way to make a plot in which, I plot upto 360 values first and then with every next value, graph re-scales to add that new value.

The simplest would be to:

Step 1: use two path objects path1 and path2.

Step 2: The Stroke Path view is connected primarily to the path1.

Step 3: All new data is stored always in path1. For the moment the changes in path1 are displayed in Stroke Path view.

Step 4: When new data is stored in path1 track the number of the already stored entries or the value range of the entries.

Step 5: When the number of entries (or the value range) exceeds a predetermined threshold, assign path2 to the Stroke Path view. 

From now (when the number entries is too large) following steps are to be done:

Step 6: With each new data calculate the desired scaling factors from either the number of entries in path1 or the range of the values you tracked.

Step 7: With each new data initialize path2 using InitSubPath() so path2 is empty.

Step 8: Use the calculated scaling factors (from step 6) to Scale() subsequent operations on path2.

Step 9: Then copy path1 content to path2 using the method path2.AddCopy().

Step 10: Reset the scaling of path2 by using the method InitMatrix(). See also Apply 2D transformations during the path creation.

Please note also that floating point values have limited precision. Especially, the larger a value, the less precise it is represented by floating point. This 'in-precision' may accumulate (grow) with each calculation step. This is the nature of floating points. With posX growing the calculation with this value may become less precise. It is thus recommended to not let posX increment endlessly.

I hope it helps you further.

Best regards

Paul Banach

by

Hello Paul Banach,

Thank you for the response. I think I didn't make the question clear. Let me re-frame it. 

Line 9:

trace "posX= ",posX, "Value of posX= ",Path1.GetNodeX( 0,noOfEdge);

I understand the difference of single preceding point. So, let's say, this logs the same values:

[26.12.2022 10:37:27] Trace Application::Application.onUpdatePath (9:3) : trace: "posX= ", 360.0, "Value of posX= ", 355.5. 

Line 25,26:

Path1.AddLine(1,posX,newValue);                            //graph in Path1 Subpath 1

trace "posX= ",posX, "Value of posX= ",Path1.GetNodeX( 1,noOfEdge);

This logs as:

[26.12.2022 10:37:27] Trace Application::Application.onUpdatePath (26:3) : trace: "posX= ", 369.0, "Value of posX= ", 182.25.

QUERY 1: I understand that I have scaled it. But while plotting at Line 25, AddLine() uses posX as X point, which is 369.0 but actual plotting is at 182.25, why are these values different? (Keeping the matter of single preceding value aside, posX should be 182.25)

Lastly, Line 75 to 79: 
else if (noOfEdge <= 1001)			
{
  Path1.AddLine(0,posX/8,newValue);
  trace "posX= ",posX,"posX/4= ",posX/8,"Value of posX= ",Path1.GetNodeX( 0,noOfEdge);
}

This gives log:

[26.12.2022 10:38:15] Trace Application::Application.onUpdatePath (78:3) : trace: "posX= ", 4500.0, "posX/4= ", 562.5, "Value of posX= ", 280.96875. 

"posX/4" as text ouput should be "posX/8". Nevertheless, value is posX/8, which is correct. My apologies for this.

So by Line 77, AddLine() is plotting at posX/8 and corresponding value is also correct as per log (Value of posX= 280.96875). But posX/8 displays 562.5 which is twice of X point. Why?

QUERY 2: Now I understood, thank you.

QUERY 3: This is why I used Subpaths 0 and 1, to copy and plot the scaled values. I have own customized hardware which is giving X and Y values @50 ms. I have used the above concept to plot but it doesn't copy the values. Here also, timer is 50 ms which works well. Am I doing something wrong? I will use two Path Objects instead of two Sub path in same path and update the result. Is there anything else that has to be checked?

Thank you for the support. Appreciate the quick response and patience of handling such queries.

Regards,

Vandana Matai

by

Hello Vandana Matai,

QUERY 1: I understand that I have scaled it. But while plotting at Line 25, AddLine() uses posX as X point, which is 369.0 but actual plotting is at 182.25, why are these values different? (Keeping the matter of single preceding value aside, posX should be 182.25)

This is because the path is still configured to scale all new added coordinates. See line 14 and also the explanation in my answer above. See also the description of the AddLine() and Scale() methods. Just in the moment when AddLine( 369.0, ... ) is performed, the value 369.0 is subjected to scale operation by 0.5. The resulting value is 184.5. The path stores thus not 369.0 but 184.5. However, your log displays 182.25. This is because you access the value for the node noOfEdges. This corresponds to the preceding entry 364.5.  (364.5 * 0.5 = 182.25).

So by Line 77, AddLine() is plotting at posX/8 and corresponding value is also correct as per log (Value of posX= 280.96875). But posX/8 displays 562.5 which is twice of X point. Why?

It is twice because the values are scaled by 0.5AddLine() is invoked with 562.5 which is 1/8 of 4500. Since scaling is still active, the path stores 281.25 for the corresponding edge (562.5 *0.5 = 281.25). Later when you query the value by GetNodeX(), you will always get the value stored in path. This means the value already scaled. So far everything is o.k.

This is why I used Subpaths 0 and 1, to copy and plot the scaled values. I have own customized hardware which is giving X and Y values @50 ms. I have used the above concept to plot but it doesn't copy the values. Here also, timer is 50 ms which works well. Am I doing something wrong? I will use two Path Objects instead of two Sub path in same path and update the result. Is there anything else that has to be checked?

Try to use two separate path objects. When you copy between two sub-paths of one and the same path object, you will finally get a combination of both sub paths unless you carefully reset one of the sub-paths in the meantime.

Best regards

Paul Banach

by
Hello Paul,

Thank you for the support. Creating two Path Objects, worked for me.

Best Regards,

Vandana Matai

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...