maartenvervelde Posted October 9, 2015 Share Posted October 9, 2015 Hi, I have a servo loop in which I use S functions. S Functions from C files are no problem, because you can include the .c and .h file in the realtime routines folder. Now I have a .cpp file in which I have code. I made a function in the file which is extern "C" so it could be called from the C code of the servo loop. But the problem I have now, is that I can't add the .cpp file to the folder. Is there a way to include the code from cpp file, because the compiler in the ide is a GNU C/C++ crosscompiler and I would suspect it would be possible to compile it? Maarten Link to comment Share on other sites More sharing options...
dro Posted October 9, 2015 Share Posted October 9, 2015 Realtime Routines only works with C because it runs in kernel space. C++ is not going to work. Link to comment Share on other sites More sharing options...
steve.milici Posted October 9, 2015 Share Posted October 9, 2015 The “Realtime Routines” folder can have only one “.c” file. You add routines to this file through the IDE. See the section in the IDE manual under “ASSOCIATING MOTORS WITH USER-WRITTEN SERVO AND PHASE ALGORITHMS” starting on page 213 (219 electronic). Basically you will add the code you have in your “.cpp” files to your newly added routines. "http://forums.deltatau.com/filedepot/download.php?f=Power PMAC/Manuals/Power PMAC IDE.pdf" Link to comment Share on other sites More sharing options...
steve.milici Posted October 9, 2015 Share Posted October 9, 2015 Also make certain to follow the safe programming rules for realtime routines in Power PMAC. Link to comment Share on other sites More sharing options...
maartenvervelde Posted October 12, 2015 Author Share Posted October 12, 2015 The “Realtime Routines” folder can have only one “.c” file. You add routines to this file through the IDE. See the section in the IDE manual under “ASSOCIATING MOTORS WITH USER-WRITTEN SERVO AND PHASE ALGORITHMS” starting on page 213 (219 electronic). Basically you will add the code you have in your “.cpp” files to your newly added routines. "http://forums.deltatau.com/filedepot/download.php?f=Power PMAC/Manuals/Power PMAC IDE.pdf" I already have a working user servo algorithm, but the problem is that I want to use S-Functions created from C++ in the servo algorithm. I have done it with C code, and you need to add the C file and the header file to the realtime routines. Is there a different way to use C++ S functions that are not fully inlined? Link to comment Share on other sites More sharing options...
dro Posted October 12, 2015 Share Posted October 12, 2015 Within the IDE, we only support C code across the board, but you can compile c++ code outside of the IDE for the background C Programs. The user servo algorithms are strictly C, since they are running in kernel space so you can not use c++ for the servo algorithms. we also use Matlab and embedded coder to generate c files for custom servo algorithms. Can you generate c instead of c++? Link to comment Share on other sites More sharing options...
maartenvervelde Posted October 13, 2015 Author Share Posted October 13, 2015 Within the IDE, we only support C code across the board, but you can compile c++ code outside of the IDE for the background C Programs. The user servo algorithms are strictly C, since they are running in kernel space so you can not use c++ for the servo algorithms. we also use Matlab and embedded coder to generate c files for custom servo algorithms. Can you generate c instead of c++? I have a servo loop in C code, and I have it working. The problem is the S Functions. We already have a lot of code written in C++ which we want to implement in the model. In the generated code the are called as functions which they get from the .c file and the .h file I added to the realtime routine folder. What you're saying is that you cant use c++ functions in that way? Link to comment Share on other sites More sharing options...
Omron Forums Support Posted October 13, 2015 Share Posted October 13, 2015 Right, you cannot use C++ in any form for servo loops in PPMAC. This is because servo code is in the "kernel." You have to convert to C syntax and bring the code into the Realtime Routines folder. This should not be too hard if you are familiar with the differences between C and C++. Link to comment Share on other sites More sharing options...
KEJR Posted October 22, 2015 Share Posted October 22, 2015 What you're saying is that you cant use c++ functions in that way? This is a bit confusing because C++ is a superset of C. Does your existing c++ code make use of a lot of "C++ ONLY" features such as objects/classes and function/operator overloading, passing by reference, etc? If so then you will have to port it to straight C. Link to comment Share on other sites More sharing options...
maartenvervelde Posted October 23, 2015 Author Share Posted October 23, 2015 This is a bit confusing because C++ is a superset of C. Does your existing c++ code make use of a lot of "C++ ONLY" features such as objects/classes and function/operator overloading, passing by reference, etc? If so then you will have to port it to straight C. The file I was trying it with was using a class in which almost everything happend so I have to rewrite it to C. I just made a struct with all the variables the class had and passed a pointer to that to al the functions so they could use the variables and change them, and the changes would be also changed within the other functions. In the S function I put the struct pointer in a PWork vector to use it between the update and the output function and so I could save it between steps. Link to comment Share on other sites More sharing options...
Omron Forums Support Posted October 23, 2015 Share Posted October 23, 2015 That will do. A class is just a "fancy" structure anyway. Link to comment Share on other sites More sharing options...
Recommended Posts