Clock's, paralel, unusual approach or how to unleash the beast (tentative version). 50 fps ;)

Hi,

This is my first subject posted here on this wonderful community, so please don't shut me down, I'm weak of heart. If I make some errors with where is the place of this subject, please make the appropriate changes.

First, I want to mention that I started a small project and a big part of that project I made in a week due to the simplicity and the power of AI2. Thank you for the chance that it can be possible to make an application with less than 10 mega, that on another platform have more than 200 mega. So far so good.

Well unlike that my first week, a week that all went well, read documentation/examples and implemented them very easily on my project, the last two weeks were horrible, a real nightmare. Two weeks that I read/test all that I'll find about charts/graphs and so on. Nothing is close enough from a speed point of view for my purpose.

My goal is to display 1000 points that have 0 or 1 state on a graph, that graph must be dynamic, and I want to display a variable frequency. As I didn't find what I needed I was on the border to let I'm down.

But...

As I understand, AI2 it is thought to work in a "serial" mode, nothing bad here the only speed is bad. So... I think that it is possible to convince AI2 to work in parallel mode, the advantage... you name it.

For God's name please don't laugh, don't cry to death, don't shut me down, I work at this experiment like a tractor on a field. I know... it can be used "any element" and "any block" as well, well... for the moment I don't have any idea how can I implement that, it is not a priority. As you can see... I implemented 966 blocks with 41 clock that works almost in parallel to generate 10 rectangular pulses with a 20 msec period or 50Hz refresh rate (can be defined as chart fps refresh rate).

IT WORKS! - it has some flickering when I change the sliders (I think that is not the best implement the clear of the canvas...) but for the moment it is not important (and I have no idea for the moment how to implement the clear of canvas from the best practice point of view...), in the future will be. By the way... The flickering is equal to 5 clocks as 41 clocks.

Canvas_graph_clocks_test.aia (23.7 KB)

Until now only good news for me. But... Now the bad news... I need 10 times more impulses - that means - 9660 blocks - and 410 timers. I'm able to do that!

But it is impossible to not exist another way to do that! But I don't know it.

Please save my mental health, my soul, and the days and nights that will come.

Thank you in advance for your time, best regards, Dan.

PS - That approach has huge potential in the real world, from cameras to Arduino-like open source. So... it deserves at least an extension if not an AI2 implementation, if I'm correct, that parallel implementation of the clocks opens a huge new potential for AI2.

Do you really need all those clocks?

Here is a cut down version with just one clock....

Canvas_graph_clocks_test_revised.aia (16.0 KB)

Thank you, thank you, thank you very much @TIMAI2 . BTW... where are you coming from?! Andromeda?! This is the purest example that can be of "KISS" of my all times. Question... " when Clock2.Timer do call..."... what is that?! Where I can find what is insight?! because in that part is the sugar of all that.

Thank you, thank you a thousand times for your time spent.

PS - you just create an... extension!

First of all, I understand how and where you hide all goodies.

Well... In this version with one clock, what you do, saves about 30% of my mental health and time, thank you very much for that. The question of which version has more speed remains.

But...

In the future, on another version of this program, I must display about 20 lines. Let's take this simplified example with 10 pulses - one line.

Your version has in one clock 40 tasks in one clock.

In my version, with one task/clock, I have 1 task/clock and 40 clocks.

The essential question is... which takes less time?! More tasks - one clock or more clocks one task?!

The above example with 10 pulses is the simplified version. Let's complicate a little that example.

For 100 pulses, I must have 400 tasks in one clock or... 400 clocks with one task.

Let's complicate more that example... I need 20 lines to be displayed. 8000 tasks in one clock or... 20 tasks/in one clock and 400 clocks?!

So... do I really need all those clocks?!

Thank you for your time, best regards, Dan.

PS... Somebody volunteer to copy/paste 8000 canvas with all those parameters?! :rofl: Will crash the program with that 8000 tasks?! And by the way... Why does it have that annoying flickering in both versions?!

A loop procedure is required to avoid having a draw line block for each line segment.

The flashing may be unavoidable.

Well... I can leave with the flashing, it happens only when the parameters change.

At loop procedure, I think/look also, more exactly at for each number from ... to... by. But for the moment I have no idea how to implement it.

I don't need the second slider (values for amplitude, the amplitude will be fixed). That simplifies a little the logic but... I need the PWM factor to be variable, so, the same complication.

How I must think? One loop for one canvas? Or one loop for four canvas (four canvas draw an impulse)?

Don't know why using four canvases would help. I would focus on the loop procedure for generating the curve.

Well... Until here I came, I didn't like very much the speed but in that approach best speed can't be. Unfortunately, I'll use 3 canvas because with only one canvas I don't know how to make them (and only one clock :rofl:).

If somebody knows/can/wants to make it best are more than welcome. I'm sure that would be made best by somebody professional in AI2. For somebody with a month ago even don't know that AI2 exists... I'm happy.

Canvas_Loop_Test.aia (3.9 KB)

I meant to say, you are unlikely to get a refresh time less than 50ms (this is based on our years of experience with the clock timer), this is even if you put 20ms.

I have no knowledge/experience in AI2 but I do some tests. First of all, I want to say that my project is not a project for phones or all devices, it will be made for a specific manufacturer/model tablet (I think that will be a Lenovo Tab P12). For that reason first of all I test some things. When I followed your first advice with this post by Kevinkun, I was impressed by the speed that chart shift in the left side if I put 1 at the clock. I want to know how big is that speed. I clean the chart for labels and I start a chronometer and the chart, I let I'm go for 10 minutes (to have some accuracy). It gives me 16.5 ms on my test tablet (I don't have a Lenovo Tab P12 now, it is on the way, I have a less performant tablet, a DOOGEE T30 Pro) for a point generated, so that was interpreted by me as clock speed. My problem with speed is not a real problem, what I want is to have an ergonomic refresh rate, which can be 15 fps, 30 fps... any ergonomic speed. If I'll want real time I'll go to LabView. I understand the fact that AI2 is not a real champion in speed/real-time, I can leave with that. Being so simple and generating so little data... makes me happy. :smiling_face_with_three_hearts: I love AI2. And please do not forget this wonderful community...


:smiling_face_with_three_hearts:

Well... my presence in this wonderful community seems to end (or I hope that...), I think that nobody will cry for that reason... :rofl:. I'm very glad that I met AI2, a month ago... An impressive simple/powerful platform. Unfortunately, I'm too ****** old to learn AI2 as deserve it and I have unfortunately only one life. Programming is not my job. It is... your job. :wink: If I can do that... For you, it is a child's game.

Final test, all works like a charm, of course, somebody who knows what are doing can make it best.

The PCB is on the way, a Lenovo Tab P12 is on the way...

The goal of this project was purely didactic for me, I wanted to demonstrate that I can take control from a tablet, over Bluetooth on some of ESP32 pins. All working like a charm. So it is perfectly achievable as a part of my project.

This project is a small part of a project that I started in 2012 that has the "iESN project" (International Electronic Service Network) as its name.

In special I want to thank to MIT App Inventor team and his community for making it possible to (too... :rofl: :frowning_face: ) easily control the real world from a tablet. Same a special thanks to @TIMAI2 for his time to put some attention here. Of course thanks to all that read this subject I hope that you learn that is possible that a guy without knowledge of programming, who makes some effort to read some... (thousands) of pages of documentation and examples, can make interesting things.

Thank you very much for your time and best regards, Dan.

PS - Now... let's make some greens...! I'll go... here https://community.appinventor.mit.edu/c/work-for-hire/21

I had a think about generating square waves on a canvas, and wondered why you had not turned to Maths for a solution?

Here is one, the aia project can be used to generate square waves and sine waves (thanks @ABG for help with the square wave maths). These small procedures must be more condusive than the many many little procedures you have in your previous offering, no flashing, either:

BLOCKS

SCREENS

AIA

SquareAndSineWavesCanvas.aia (5.7 KB)

1 Like

The answer is simple to your above question, read here, please....

I know math, but I don't know math at the level of @ABG, I know AI2 but I don't know AI2 at your level, I know physics but I'm not Einstein, I know electronics in the electronic service field, and reverse engineering that nor you, ABG or Einstein can know ever. In this life one person can't know all things, I learned enough parts from all that was interesting/mandatory for me to explain (to be the man in the middle) the connection between my real-life projects and the future programming questions. Somebody must be the interface between these two worlds.

It is not the dream of my life programming and as I specify, already I have a job that doesn't imply programming skills.

Anyway, I want to thank you and ABG in the name of the future readers, they can learn some best practices here in this subject.