GithubHelp home page GithubHelp logo

Comments (11)

robertobucher avatar robertobucher commented on July 20, 2024

Hi

sorry for late replay, but I'm involved in an important presentation for tomorrow.

I'll send you the files in a couple of days.

Roberto

from pysimcoder.

protfor avatar protfor commented on July 20, 2024

Dear Roberto-san,

Thank you very much.
Nice to meet you, my name is protfor.

Thank you for replying politely, even though I made an inquiry online on GitHub, and in addition, while you have a job right now.

I think there may be some points that I have not studied, but I will be saved little by little, so please teach me.

from pysimcoder.

robertobucher avatar robertobucher commented on July 20, 2024

I've added your block to the repository.
I did a little description about creating new blocks. The example generates this specific block and gives (I hope) all the required steps to generate new blocks in the future.

NewBlock.pdf

from pysimcoder.

protfor avatar protfor commented on July 20, 2024

Dear Roberto-san,

Thanks very much to your sincere description,

  • I, who is a fan of pysimCoder,
    was able to accomplish it like the attached file.

  • I would like introduce myself, 20 years ago,
    I majored in control at university and used MATLAB (I never had the chance to use Simulink..).

    On the other hand, recently, when I asked children and students what they were doing,
    I learned that they were having fun with Simulink and GitHub.

  • From the above, for me, Simulink, which is an extension of MATLAB,
    does not lead to my growth,
    so I would like to relearn this opportunity with pysimCoder.

Sincerely^V

K|u|^v.pdf

from pysimcoder.

protfor avatar protfor commented on July 20, 2024

Dear Roberto-san,

Long time no see.
I want to create a block only with the Python program without c program.

I have summarized the situation that I am specifically thinking about in the attached file.
20230518.docx

I would appreciate it if you could reply when you have time.

from pysimcoder.

robertobucher avatar robertobucher commented on July 20, 2024

I can't open your docx file. Can you send a PDF?

from pysimcoder.

protfor avatar protfor commented on July 20, 2024

Dear Roberto-san,

Good morning. Thank you for your prompt reply.

I will send "20230518.pdf". In addition, the relevant files are:
"UPOW3.xblk"
"upowBlk3.py"
"upowBlk3.c"
"untitled_test.dgm"

20230518.pdf
upowBlk3.zip

from pysimcoder.

robertobucher avatar robertobucher commented on July 20, 2024

I hope that I have correctly understand your problem.

You can't implement code in python in the .py file (in this case upowBlk3.py file). This file is only used to generate a specific class element which contains all the information required to generate the code. It doesn't perform any action to the block.

from pysimcoder.

protfor avatar protfor commented on July 20, 2024

Dear Roberto-san,

My question was poorly (I asked based on my trial process). Nonetheless, thanks for your reply.

Rearranged the question to 20230522.pdf. I would appreciate if you could check it when you have time.
20230522.pdf
mathsqrt.zip

Best regard.

from pysimcoder.

robertobucher avatar robertobucher commented on July 20, 2024

It is possible but it is a bad idea! pysimCoder generates C-Code in order to have a very short execution time and give the possibility to execute tasks in realtime. If you want to program some blocks as python code, you have to generate a wrapper from C to python. It is possible, not so difficult to be implemented, but it will incease the execution time of the RT task...
You can program your C block with something like this example:

#include <Python.h>

int main()
{
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n");
PyRun_SimpleString("print('Today is', ctime(time()))\n");

if (Py_FinalizeEx() < 0) {
exit(1);
}
return 0;
}

or something like

pyMath.py

import numpy as np

def determinant(a):
print(a)
return(np.linalg.det(a))

def inverse(a):
b = np.linalg.inv(a)
print(b)
return b

and this C-Code

#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION

#include <Python.h>
#include <numpy/arrayobject.h>

int main()
{
PyObject *pName;
PyObject *pModule;
PyObject *pFun1, *pFun2;
PyObject *pVal;
PyObject *pArgs;
PyObject *pArray;

double matin[3][3];
double *matout;
int i,j;

npy_intp dims[2];
double det;
void * ret;

Py_Initialize();

pName = PyUnicode_FromString("myMath");
pModule = PyImport_Import(pName);
Py_DECREF(pName);

if(!pModule) {
Py_DECREF(pModule);
exit(1);
}

pFun1 = PyObject_GetAttrString(pModule, "determinant");
if(!pFun1) {
Py_DECREF(pFun1);
exit(1);
}

pFun2 = PyObject_GetAttrString(pModule, "inverse");
if(!pFun2) {
Py_DECREF(pFun2);
exit(1);
}

/* Matrix dimensions */
dims[0] = 3;
dims[1] = 3;

/* Fill the matrix /
for(i=0;i<3;i++){
for(j=0;j<3;j++){
matin[i][j] = 3
i+j;
}
}
/* Change one value to have determinant <> 0 */
matin[2][2] = 0.0;

import_array();

/* Create pArray using PyArray_SimpleNewFromData */
.....

/* Set the array as function args */
pArgs = PyTuple_New(1);
PyTuple_SetItem(pArgs,0, (PyObject *) pArray);

pVal = PyObject_CallObject(pFun1, pArgs);

/* Get the return value using PyFloat_AsDouble */
..................

pVal = PyObject_CallObject(pFun2, pArgs);

/* Get the array Data using matout = PyArray_Data(.....) */
.........

/* Print the inverse matrix */

for(i=0;i<3;i++){
printf("| ");
for(j=0;j<3;j++){
printf("%10.4lf",matout[3*i+j]);
}
printf(" |\n");
}

Py_Finalize();
}

As you can see it is more simple to implement all the functions directly in C-Code!

from pysimcoder.

protfor avatar protfor commented on July 20, 2024

Dear Roberto-san,

Good morning.
Thank you for your sincere response to my poor idea.
In addition, I would like to thank the professor for giving me a concrete idea.

I will try to implement the professor's teachings in my environment. (My current environment is Ubuntu 22.04lts !)
(If it does not work well in my implementing, please let me ask you a question again.)

Best regard.

from pysimcoder.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.