Hi I am new here.
Current I have the issue on import library into mbed.
I have generate c++ library from MATLAB as you can see from below
But how can I use this library in mbed cli?
normally I will import library with
mbed add https://github.com/ARMmbed/mbed-cloud-client
But this time it is local library from MATLAB code generator.
I have no idea how to import this library.
looking at the help:
mbed add --help
usage: mbed add [-h] [-I] [--depth [DEPTH]] [--protocol [PROTOCOL]]
[--insecure] [--offline] [--no-requirements] [-v] [-vv]
Adds mbed library and its dependencies from a source control based URL
(GitHub, Bitbucket, mbed.org) into an existing program.
Use "mbed import <URL>" to import as a program
url URL of the library
path Destination name or path. Default: current folder.
-h, --help show this help message and exit
-I, --ignore Ignore errors related to cloning and updating.
--depth [DEPTH] Number of revisions to fetch from the remote
repository. Default: all revisions.
Transport protocol for the source control management.
Supported: https, http, ssh, git. Default: inferred
--insecure Allow insecure repository URLs. By default mbed CLI
imports only "safe" URLs, e.g. based on standard ports
- 80, 443 and 22. This option enables the use of
--offline Offline mode will force the use of locally cached
repositories and prevent requests to remote
--no-requirements Disables checking for and installing any requirements.
-v, --verbose Verbose diagnostic output
-vv, --very_verbose Very verbose diagnostic output
Would the --offline work for your case ?
Oh hi, I’ve also worked with some MATLAB/Simulink generated stuff. To import the generated code, all you need to do is drop the generated cpp and h files into your project folder. Then you can use Mbed CLI to compile like normal and things will work.
That said, make sure that you’re using MATLAB Embedded Coder, not the desktop version. The desktop code needs to link with MATLAB itself to work, while the embedded code is totally standalone. Also, don’t forget to configure Embedded Coder for an ARM architecture, or it might generate code that doesn’t quite compile.
Thank you so much!!
For now I can import and compile the MATLAB generated cpp library.
Can you help me more with some issue
As you can see my library is a simple trajectory generation function which have 4input(double 1 * 1 ) and 2output[one is trajectory(1 * 500) and one is sampling time(1 * 500)].
But after I generate it into cpp code. from my library the function is “void” which will not return output. How can I use the output(trajectory and sampling time)
P.S. I have install embedded coder. But where is it in MATLAB? Is it an add-on in MATLAB coder like this?
That settings screen you posted looks right.
It looks to me like the C++ function that it generated uses pass-by-reference parameters to return data. This is of course required in embedded C++ if you want to want to return lots of data from a function without expensive copy operation.
You need to first declare the arrays (globally, to avoid overflowing the stack), then you can pass them as parameters. It would look like this:
coder::array<double, 2U> vel_trajectory;
coder::array<double, 2U> t;
cubi2_tra_func(inputQ0, inputQ1, vel_trajectory, t);
// data is now available in vel_trajectory and t
Also I’m assuming that
2U is defined as 500 somewhere? It has to be, right?
Actually I can’t find variable ‘2U’ anywhere??!
I have tried your suggestion but the function only accept 6 argument (4 inputs and 2 outputs)
because from the cubi2_tra_func.cpp the function is defind like this
From your suggestion I have built code look like this
So now I want to tried print out the value of ‘vel_trajectory’ with below code
After compile eveything look just fine no error anywhere, But the output is like this …
I am not sure why this happen. I don’t think the data type is wrong. cause the element of ‘vel_trajectory’ should be double, and the compiler don’t have any ‘warning’ or ‘error’ too.
Ah, the classic error. This is because the Mbed OS devs decided to make their size numbers look better by breaking standard C printf() functionality.
Thankfully you can restore normal printf() operation by creating a file called
mbed_app.json in your project root folder with this content:
that is a constant value with type ‘unsigned’. A variable would be U2
Thank so much.
Everything is working now =)