Hi Ben
When working with 3D data, it is convenient to work with multidimensional arrays.
For example, in an array data[40 ][6]
I can have 40 positions with two objects x1, y1, z1, x2, y2, z2,
This actually works very well with Flowcode.
And simple arrays can already be sent and received very well with Flowcode by USB or Bluetooth
One question, can I also send this multidimensional arrays with USB as multidimensional arrays?
There is a small problem..
Creating is easy, just press add array dimension twice
Sending multidimensional arrays by USB
-
- Valued Contributor
- Posts: 909
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 181 times
- Been thanked: 208 times
-
- Valued Contributor
- Posts: 1280
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 124 times
- Been thanked: 645 times
Re: Sending multidimensional arrays by USB
Hi stefan,
Iy is easy in a loop:
Alternatively use a 1D array and calculate pos from the two co-ordinates (pos = .y * width + .x where you had data[width][height] and now would have data[width * height)
Martin
Iy is easy in a loop:
Code: Select all
for dimensions using .i // data[dimensions]][length]
sendArray data[.i]
Martin
-
- Valued Contributor
- Posts: 909
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 181 times
- Been thanked: 208 times
Re: Sending multidimensional arrays by USB
Hi Martin
At the moment I am sending and receiving simple arrays with 120 lines.
Here a
I then resolve these in the app to a new array with 40 lines and 3 columns, which works well, I just thought I could send such an array straight away.
example with 3 values:
At the moment I am sending and receiving simple arrays with 120 lines.
Here a
I then resolve these in the app to a new array with 40 lines and 3 columns, which works well, I just thought I could send such an array straight away.
example with 3 values:
- Attachments
-
- 2024-11-27_13-56-22.PNG (181.09 KiB) Viewed 1805 times
-
- Valued Contributor
- Posts: 1280
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 124 times
- Been thanked: 645 times
Re: Sending multidimensional arrays by USB
Plan B. Cheat - a multidimensional array is held in memory as a contiguous block of memory - so data[2][2] will allocate 4 * size of cell (at least in C)
So using a line of C, you could pass the address of the data and the size to SendIntArray - the address is FCV_DATA or FCL_DATA (for a local)
The problem is that the name of SendIntArray will be rather longer and include the component - so you need to get this from viewing the C code...
The receive can work with either receiving a dimension at a time in a loop as above or using a C block and the address in the ReceiveIntArray as per the send...
Martin
So using a line of C, you could pass the address of the data and the size to SendIntArray - the address is FCV_DATA or FCL_DATA (for a local)
The problem is that the name of SendIntArray will be rather longer and include the component - so you need to get this from viewing the C code...
The receive can work with either receiving a dimension at a time in a loop as above or using a C block and the address in the ReceiveIntArray as per the send...
Martin
-
- Valued Contributor
- Posts: 1280
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 124 times
- Been thanked: 645 times
Re: Sending multidimensional arrays by USB
I did a quick '3D' array version. Array with any number of dimensions 1, 2, 3 or more - just alter the parameter to the correct number.
It will take 'any' size of array - but sparse data isn't supported.
Note a couple of things - MSB first is coded to 'true' in send and receive - change this (or add a parameter if needed). The timeout on receive is also hardcoded as 100 - again change as required. Receive should return a bool (true on success?)
There are a couple of disabled macros at the start of main - if you delete these, the code optimiser deletes the SendIntArray and ReceiveIntArray macros - the start of main isn't necessarily the best place (and they could be anywhere - or are not needed if you use either macro elsewhere)
If you look at the Send and Receive macros - the name for Send/ReceiveIntArray is mangled to FCD_047b1_UART1__Send/ReceiveINTArray and this will change if a new version of the component is released
Martin
It will take 'any' size of array - but sparse data isn't supported.
Note a couple of things - MSB first is coded to 'true' in send and receive - change this (or add a parameter if needed). The timeout on receive is also hardcoded as 100 - again change as required. Receive should return a bool (true on success?)
There are a couple of disabled macros at the start of main - if you delete these, the code optimiser deletes the SendIntArray and ReceiveIntArray macros - the start of main isn't necessarily the best place (and they could be anywhere - or are not needed if you use either macro elsewhere)
If you look at the Send and Receive macros - the name for Send/ReceiveIntArray is mangled to FCD_047b1_UART1__Send/ReceiveINTArray and this will change if a new version of the component is released
Martin
- Attachments
-
- Send3D.fcfx
- (12.54 KiB) Downloaded 91 times
-
- Valued Contributor
- Posts: 909
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 181 times
- Been thanked: 208 times
Re: Sending multidimensional arrays by USB
Hi Martin
This is good news with the component. Then it will be easy and comfortable
I have looked at your suggestion and in the APP it is the comport instead of the uart.
I changed that and installed it.
But then the app doesn't understand any C code
This is good news with the component. Then it will be easy and comfortable
I have looked at your suggestion and in the APP it is the comport instead of the uart.
I changed that and installed it.
But then the app doesn't understand any C code
Code: Select all
FCD_047b1_UART1__ReceiveINTArray((void *)FCL_DATA, FCL_ELEMENTS, FCL_ELEMENTS, 1, 100);
-
- Valued Contributor
- Posts: 1280
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 124 times
- Been thanked: 645 times
Re: Sending multidimensional arrays by USB
Yes - sorry forgot you were sending to an App - it doesn't use C. So slightly stymied that end.
So the MCU can send all as one - but the app will need to receive differently - so can either receive as a single dimension array and calculate pos or receive in a loop(s) incrementing x and y (and z in the 3d case) as appropriate
So the MCU can send all as one - but the app will need to receive differently - so can either receive as a single dimension array and calculate pos or receive in a loop(s) incrementing x and y (and z in the 3d case) as appropriate
-
- Valued Contributor
- Posts: 1280
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 124 times
- Been thanked: 645 times
Re: Sending multidimensional arrays by USB
I did a small demo in AppDeveloper.
I modified the above to send a 3 x 3 array (2D) - and running on a trusty Arduino Nano - it waits to receive 'X' from the App. Then it uses Send2DArray (this is identical to Send3DArray, but removed a dimension from the array)
The App receives this - and I just use simulation to check the value received.
Its very basic - the array in the sender is fixed - but it seems to work AOK.
The principle would be the same for 3D (or MoreD) arrays...
Note that the COM port needs to be set in the App properties.
Martin
I modified the above to send a 3 x 3 array (2D) - and running on a trusty Arduino Nano - it waits to receive 'X' from the App. Then it uses Send2DArray (this is identical to Send3DArray, but removed a dimension from the array)
The App receives this - and I just use simulation to check the value received.
Its very basic - the array in the sender is fixed - but it seems to work AOK.
The principle would be the same for 3D (or MoreD) arrays...
Note that the COM port needs to be set in the App properties.
Martin
- Attachments
-
- RcvApp.fcsx
- (10.97 KiB) Downloaded 77 times
-
- Send3D.fcfx
- (16.52 KiB) Downloaded 76 times