Hi Ben
How to make a Matrix calculation in Flowcode?
We would like to use a Matrix to calculate better 3D positions from our objects. We can support with more info's.
But i think, actually the company is already called Matrix
regards
Stefan
How to make a Matrix calculation in Flowcode
-
- Valued Contributor
- Posts: 771
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 151 times
- Been thanked: 173 times
-
- Matrix Staff
- Posts: 1763
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 448 times
- Been thanked: 607 times
Re: How to make a Matrix calculation in Flowcode
I have recently done a matrix multiply routine as part of this component which may help.
The MatrixMultiple macro multiples the matrix WorkingMatrix with MatrixStep and stores the result into local variable CalcMatrix. CalcMatrix is then copied back into WorkingMatrix once the multiply is complete. All three matrixes in this case are 2D arrays with 4 values in each dimension.
Having something more formal to do matrix maths in a component may be the way forward with this.
The MatrixMultiple macro multiples the matrix WorkingMatrix with MatrixStep and stores the result into local variable CalcMatrix. CalcMatrix is then copied back into WorkingMatrix once the multiply is complete. All three matrixes in this case are 2D arrays with 4 values in each dimension.
Having something more formal to do matrix maths in a component may be the way forward with this.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Valued Contributor
- Posts: 771
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 151 times
- Been thanked: 173 times
Re: How to make a Matrix calculation in Flowcode
Hi Ben, Hi Martin
Thanks for the Info, we will have a look at the matrix.
One more question
Can you also calculate integrals with flowcode?
regards
Stefan
Thanks for the Info, we will have a look at the matrix.
One more question
Can you also calculate integrals with flowcode?
regards
Stefan
-
- Valued Contributor
- Posts: 1008
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 520 times
Re: How to make a Matrix calculation in Flowcode
Hi Stefan,
I had a little play with a matrix type last night - basically a struct with width, height and data. Create Matrix allocated memory - with set, get and Delete functions - didn't quite get as far as multiplication.
So the 'matrix' is an integer which is really a pointer.
Will play a little more tonight
Martin
I had a little play with a matrix type last night - basically a struct with width, height and data. Create Matrix allocated memory - with set, get and Delete functions - didn't quite get as far as multiplication.
So the 'matrix' is an integer which is really a pointer.
Will play a little more tonight
Martin
-
- Valued Contributor
- Posts: 1008
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 520 times
Re: How to make a Matrix calculation in Flowcode
Didn't get much time to play last night.
So - if anyone would like to play along. Any thoughts/comments/ideas/help...
This is some simple code to create / delete / set values in / get values / display a matrix.
There is a multiply - but it just creates the result matrix (and I'm not sure I have the dimensions right (h2 by w1 which are equal) - I haven't done any of the multiply code. (Multiply rows by columns and sum) There is no error checking - so if you do setvalue(matrix, 0, 10000) on a 3x3 matrix it will overwrite something.
Multiply returns 0 if width1 != height2 (which is a requirement for a multiply)
Create also returns 0 if can't create (no memory) - everywhere needs to check...
I've used an Arduino - but esp32 would be better (much more memory)
Note it should work on Arduino or esp32 - but won't work on small PICs which don't support malloc.
I've used 16 bit integers as values in the matrix. Could change to float easily.
Martin
So - if anyone would like to play along. Any thoughts/comments/ideas/help...
This is some simple code to create / delete / set values in / get values / display a matrix.
There is a multiply - but it just creates the result matrix (and I'm not sure I have the dimensions right (h2 by w1 which are equal) - I haven't done any of the multiply code. (Multiply rows by columns and sum) There is no error checking - so if you do setvalue(matrix, 0, 10000) on a 3x3 matrix it will overwrite something.
Multiply returns 0 if width1 != height2 (which is a requirement for a multiply)
Create also returns 0 if can't create (no memory) - everywhere needs to check...
I've used an Arduino - but esp32 would be better (much more memory)
Note it should work on Arduino or esp32 - but won't work on small PICs which don't support malloc.
I've used 16 bit integers as values in the matrix. Could change to float easily.
Martin
-
- Valued Contributor
- Posts: 1008
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 520 times
Re: How to make a Matrix calculation in Flowcode
And with a multiply....
I added a utility function - LoadMatrix (again no checks )
Here it creates /loads two matrices (3x2 and 2x3) multiplies and then deletes all 3 matrices - output is sent to UART... Then repeats (checking for memory leaks!)
Martin
I added a utility function - LoadMatrix (again no checks )
Here it creates /loads two matrices (3x2 and 2x3) multiplies and then deletes all 3 matrices - output is sent to UART... Then repeats (checking for memory leaks!)
Martin
-
- Valued Contributor
- Posts: 771
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 151 times
- Been thanked: 173 times
Re: How to make a Matrix calculation in Flowcode
Hi Martin
Thank you very much.
We will try to use this in the app developer next week.
We just need to move one or two 3D objects and I will let you know if it works.
regards
Stefan
Thank you very much.
We will try to use this in the app developer next week.
We just need to move one or two 3D objects and I will let you know if it works.
regards
Stefan
-
- Valued Contributor
- Posts: 1008
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 520 times
Re: How to make a Matrix calculation in Flowcode
Hi Stefan,
Hopefully it will work OK. It works fine on the Arduino - but I'd recommend adding some error checking. Not sure what data you need - but it would be straightforward to change to longs or floats.
I've used long ints as pointers - which works in the limited address space of a MCU but if app-developer is 64 bit then some more fiddling might be needed (using an index to a lookup table of addresses for example)
Maybe a plea for pointer support in FC?
Do you need any other functions - scalar multiplication is straight forward
One complication - having written some code - I found most examples use M*N to define the matrix - where M is rows and N columns. I used x, y - so it's generally the unexpected way round.. Multiply took a bit more time as a result...
Martin
Hopefully it will work OK. It works fine on the Arduino - but I'd recommend adding some error checking. Not sure what data you need - but it would be straightforward to change to longs or floats.
I've used long ints as pointers - which works in the limited address space of a MCU but if app-developer is 64 bit then some more fiddling might be needed (using an index to a lookup table of addresses for example)
Maybe a plea for pointer support in FC?
Do you need any other functions - scalar multiplication is straight forward
One complication - having written some code - I found most examples use M*N to define the matrix - where M is rows and N columns. I used x, y - so it's generally the unexpected way round.. Multiply took a bit more time as a result...
Martin
-
- Valued Contributor
- Posts: 771
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 151 times
- Been thanked: 173 times
Re: How to make a Matrix calculation in Flowcode
Hi Martin
We try with Flowcode to create an IMU Sensor Fusion.
acceleration (Accelerometer), angular velocity(Gyroscope) and maybe orientation (Magnetometer).
for this a matrix and integral would be useful.
We are aware that this means some effort for us.
regards
Stefan
We try with Flowcode to create an IMU Sensor Fusion.
acceleration (Accelerometer), angular velocity(Gyroscope) and maybe orientation (Magnetometer).
for this a matrix and integral would be useful.
We are aware that this means some effort for us.
regards
Stefan
- Attachments
-
- Snag_9789d2.png (33.62 KiB) Viewed 1218 times