Forum Replies Created
-
AuthorPosts
-
MadaniBlocked
Hey Hugo!
My problem is solved and thanks again for your assistance!
Regards,
Mehdi
MadaniBlockedHi Hugo,
Thank you for your follow up I really appreciate how much effort SOFA support team puts in solving users’ issues.
Yes it is solved. Apparently the problem rose from my own code. I had a for loop which elongated processing time of SOFA, by decreasing the number of iterations and also adjusting the serial port (dcb) parameters the problem was not there anymore.Regards,
Mehdi
MadaniBlockedThank you @dilthoms and @Hugo for your answers
I solved the issue of crashing not the problem is that Sofa runs fast in the beginning of simulation (for about 1s) and then runs somehow in slowmotion. I think as well that the problem is from buffer. The thing is that interestingly when I change the refresh interval DT in SOFA GUI there is no change in my loop duration and no matter how I assign it it always takes 200 ms to finish one loop. I also tried modifying timeout intervals of my serial port but it did not give me any result as well. However when I run the simulation with NI force sensor everything runs smoothly and in real time manner.
thanks again for your time!
Mehdi,
MadaniBlockedagain me! the usual annoying question person 🙂
I managed to solve that problem now I just open the COM port just once by putting it in the MyBehaviorModel(). Now the problem is that simulation runs normally(fast) but after like half a second it becomes slow. Here is my PlugIn code:
#include "MyBehaviorModel.h" #include <sofa/core/ObjectFactory.h> #include <sofa/core/behavior/MechanicalState.h> #include <sofa/core/VecId.h> #include <sofa/defaulttype/VecTypes.h> #include <SofaUserInteraction/MechanicalStateController.h> #include <sofa/core/visual/VisualParams.h> #include <sofa/core/behavior/MechanicalState.h> #include <sofa/core/objectmodel/MouseEvent.h> #include <sofa/defaulttype/VecTypes.h> #include <sofa/defaulttype/RigidTypes.h> #include <sofa/defaulttype/Quat.h> #include <sofa/simulation/common/Node.h> #include <sofa/simulation/common/MechanicalVisitor.h> #include <sofa/simulation/common/UpdateMappingVisitor.h> #include <sofa/defaulttype/RigidTypes.h> #include <sofa/defaulttype/VecTypes.h> #include <stdio.h> #include <tchar.h> #include <string> #include<cstdlib> #include<iostream> #include <time.h> #include <tinyxml.h> #include <math.h> #include "NIDAQmx.h" #if defined(__linux__) || defined(__APPLE__) #define __CFUNC #define __CFUNC_C #define __CFUNCPTRVAR #define CVICDECL #define CVICALLBACK CVICDECL #else #define __CFUNC __stdcall #define __CFUNC_C __cdecl #define __CFUNCPTRVAR __cdecl #define CVICDECL __cdecl #define CVICALLBACK CVICDECL #endif HANDLE m_hFile; HANDLE m_hFile2; // Current Values unsigned char hibyte; unsigned char lowbyte; unsigned char hibyte2; unsigned char lowbyte2; long int pos; long int pos2; double x; double y; double ydummy; double xdummy; double prx=0; double curx; double avx=0; long int count; double sumprx; double theta; #define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error;} } HANDLE OpenComPort(int nPortNo,int BaudRate,int ByteSize,int Parity,int StopBits) { LPCSTR strPort="\\\\.\\COM3"; BOOL fSuccess; COMMTIMEOUTS timeout; DCB dcb; //Create the handle for read the COM port m_hFile = CreateFileA( strPort, GENERIC_READ, (DWORD)NULL, // exclusive access NULL, // no security OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL // hTemplate ); if (INVALID_HANDLE_VALUE == m_hFile) {//Check whether the handle is valid or not. printf("Error: Arduino Port Connection Not Established!"); return NULL; } SetupComm(m_hFile,(DWORD)2048, (DWORD)2048);// setup the com parameters now that we have a handle // Set up the DCB with our settings fSuccess = GetCommState(m_hFile,&dcb);// Get it first so we fill all members if (!fSuccess) {// Handle the error. printf("Error: Failed to Get the System Communication Settings."); return NULL; } dcb.BaudRate = BaudRate; // baud rate dcb.ByteSize = ByteSize; // data size dcb.Parity = Parity; // No Parity Bit dcb.StopBits = StopBits; // stop bits fSuccess = SetCommState(m_hFile, &dcb); // assign it if ( fSuccess == 0 ) {//Now check the configuration of the communication device is valid or not after assign the com parameters printf("Error: In Control Setting for a Serial Communications Device."); return ("success!!!!"); } // Set up the timeouts to use, they are quite short, since we will loop anyway. // Do not make them zero, else we will have a CPU load problem. Too large a value, // and we have to wait for comms to time out when shutting down. GetCommTimeouts(m_hFile, &timeout); // fill timeout structure timeout.ReadIntervalTimeout = 50; // 50ms between incomming chars. timeout.ReadTotalTimeoutConstant = 50; timeout.ReadTotalTimeoutMultiplier = 10; timeout.WriteTotalTimeoutConstant = 50; timeout.WriteTotalTimeoutMultiplier = 10; // 60ms per char sent SetCommTimeouts(m_hFile, &timeout); return m_hFile; } //=========================================================================== HANDLE OpenComPort2(int nPortNo,int BaudRate,int ByteSize,int Parity,int StopBits) { LPCSTR strPort2="\\\\.\\COM10"; BOOL fSuccess; COMMTIMEOUTS timeout; DCB dcb; //sprintf(strPort, "COM%d", nPortNo) ; //Create the handle for read the COM port m_hFile2 = CreateFileA( strPort2, GENERIC_READ, (DWORD)NULL, // exclusive access NULL, // no security OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL // hTemplate ); if (INVALID_HANDLE_VALUE == m_hFile2) {//Check whether the handle is valid or not. printf("Error: Prolific Port Connection Not Established!"); return NULL; } SetupComm(m_hFile2,(DWORD)2048, (DWORD)2048);// setup the com parameters now that we have a handle // Set up the DCB with our settings fSuccess = GetCommState(m_hFile2,&dcb);// Get it first so we fill all members if (!fSuccess) {// Handle the error. printf("Error: Failed to Get the System Communication Settings."); return NULL; } dcb.BaudRate = BaudRate; // baud rate dcb.ByteSize = ByteSize; // data size dcb.Parity = Parity; // No Parity Bit dcb.StopBits = StopBits; // stop bits fSuccess = SetCommState(m_hFile2, &dcb); // assign it if ( fSuccess == 0 ) {//Now check the configuration of the communication device is valid or not after assign the com parameters printf("Error: In Control Setting for a Serial Communications Device."); return ("success!!!!"); } // Set up the timeouts to use, they are quite short, since we will loop anyway. // Do not make them zero, else we will have a CPU load problem. Too large a value, // and we have to wait for comms to time out when shutting down. GetCommTimeouts(m_hFile2, &timeout); // fill timeout structure timeout.ReadIntervalTimeout = 50; // 50ms between incomming chars. timeout.ReadTotalTimeoutConstant = 0; timeout.ReadTotalTimeoutMultiplier = 0; timeout.WriteTotalTimeoutConstant = 0; timeout.WriteTotalTimeoutMultiplier = 60; // 60ms per char sent SetCommTimeouts(m_hFile2, &timeout); return m_hFile2; } //========================================================================= // Task parameters int32 error = 0; TaskHandle taskHandle = 0; char errBuff[2048]={'\0'}; int32 i; // Channel parameters char chan[] = "Dev1/ai2:3"; float64 min = -10.0; float64 max = 10.0; // Timing parameters char source[] = "OnboardClock"; uInt64 samplesPerChan = 2; float64 sampleRate = 1000.0; // Data read parameters #define bufferSize (uInt32)1000 float64 data[bufferSize]; int32 pointsToRead = -1; int32 pointsRead; float64 timeout = 10.0; double forcez; double tx; //********************************************************************* namespace sofa { namespace component { namespace behaviormodel { MyBehaviorModel::MyBehaviorModel(): customUnsignedData(initData(&customUnsignedData, (unsigned)1,"Custom Unsigned Data","Example of unsigned data with custom widget")), regularUnsignedData(initData(®ularUnsignedData, (unsigned)1,"Unsigned Data","Example of unsigned data with standard widget")) {HANDLE OpenComPort(int nPortNo=3,int BaudRate = CBR_57600,int ByteSize = 8,int Parity = NOPARITY,int StopBits = ONESTOPBIT); HANDLE OpenComPort2(int nPortNo=10,int BaudRate = CBR_57600,int ByteSize = 8,int Parity = NOPARITY,int StopBits = ONESTOPBIT); customUnsignedData.setWidget("widget_myData"); m_hFile=OpenComPort(3,CBR_57600,8,NOPARITY,ONESTOPBIT); m_hFile2=OpenComPort2(10,CBR_57600,8,NOPARITY,ONESTOPBIT); } MyBehaviorModel::~MyBehaviorModel() { } void MyBehaviorModel::init() { } void MyBehaviorModel::reinit() { } void MyBehaviorModel::updatePosition(SReal dt) { HINSTANCE hinstLib = LoadLibraryA(_T("C:\\nicaiu.dll")); if(m_hFile!=NULL) {//read 100 lines from serial port for (int i = 0; i < 300; i++) { char ch = 0; DWORD read = 0; while(!read) { ReadFile(m_hFile, &ch, 1, &read, NULL); if (read) { if (ch==1 | ch==0 ){ hibyte=ch; } else{ lowbyte=ch; } pos=(255*hibyte)+lowbyte; ydummy=(double)(pos); y=(-ydummy/600)-1.05; if(y>-0.90){ y=-1.05; } } } } } //CloseHandle(m_hFile); //================================================================== if(m_hFile2!=NULL) {//read 100 lines from serial port for (int j = 0; j < 300; j++) { char ch2 = 0; DWORD read2 = 0; while(!read2) { ReadFile(m_hFile2, &ch2, 1, &read2, NULL); if (read2) { if (ch2==1 | ch2==2){ hibyte2=ch2; } else{ lowbyte2=ch2; } pos2=((255*hibyte2)+lowbyte2)-450; xdummy=(double)(pos2); x=((xdummy)/200); count++; avx=(x+sumprx)/count; if(abs(x)<abs((5*avx)) | abs(x)<0.8){ curx=x; } if(abs(x)>abs((5*avx)) ){ curx=prx; } } } } } //*************************************************************************** //CloseHandle(m_hFile2); /*DAQmxErrChk (DAQmxCreateTask ("", &taskHandle)); DAQmxErrChk (DAQmxCreateAIVoltageChan (taskHandle, chan, "", DAQmx_Val_Cfg_Default, min, max, DAQmx_Val_Volts, NULL)); DAQmxErrChk (DAQmxCfgSampClkTiming (taskHandle, source, sampleRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, samplesPerChan)); DAQmxErrChk (DAQmxStartTask (taskHandle)); DAQmxErrChk (DAQmxReadAnalogF64 (taskHandle, pointsToRead, timeout, 0, data, bufferSize, &pointsRead, NULL)); printf ("Acquired %ld samples\n", pointsRead); // Just print out the first 10 points // for (i = 0; i < 16; ++i) Error: if( DAQmxFailed(error) ) DAQmxGetExtendedErrorInfo(errBuff,2048); if(taskHandle != 0) { DAQmxStopTask (taskHandle); DAQmxClearTask (taskHandle); } if( DAQmxFailed(error) ) printf ("DAQmxBase Error %ld: %s\n", error, errBuff); */ //********************************************************************* dy=0.00; /*forcez=((double)data[1]-0.121); forcez=forcez-1.05; tx=((double)data[2])-0.325; if(tx<0){ tx=tx*10; //forcez=-forcez; } if(tx>0){ tx=tx*16; //forcez=-forcez; } theta=((atan(tx/forcez))-1.54)/4; printf ("data[%ld] = %f\n", 1, forcez); printf ("data[%ld] = %f\n", 1, tx);*/ using core::behavior::MechanicalState; mState1 = dynamic_cast<MechanicalState<sofa::defaulttype::Rigid3dTypes> *>(this->getContext()->getMechanicalState()); helper::WriteAccessor<sofa::core::objectmodel:: Data<sofa::defaulttype::Rigid3dTypes::VecCoord> > xp = *mState1->write(core::VecCoordId::position()); xp[0].getCenter()=sofa::defaulttype::Vec<3,Real>((Real)((x)),(Real)dy,(Real)((y))); sumprx=sumprx+x; prx=x; } SOFA_DECL_CLASS(MyBehaviorModel) int MyBehaviorModelClass = core::RegisterObject("Dummy component with a custom widget.").add< MyBehaviorModel >(); } // namespace behaviormodel } // namespace component } // namespace sofa
Sorry for making you read this long code but just wanted to make sure you will see all the detail. by the way the commented parts are for the mode that I am using force input as my haptic device uses both position and force input.
Thank you again,
Mehdi
MadaniBlockedThe problem is that when I place OpenComPort() in MyBehaviorModel() the program compiles and it opens the port but it crashes. To say it more clearly, my question is that “Is there any part of PluginExample where I can place OpenComPort() that initiates it once and there won’t be any need to open and close port on every simulation loop?
MadaniBlockedsorry for the long delay but I was working on another part of SOFA and now I am back to serial communication part.
Here is the Updates position() function:
m_hFile=OpenComPort(3,CBR_57600); m_hFile2=OpenComPort2(10,CBR_57600); if(m_hFile!=NULL) {//read 100 lines from serial port for (int i = 0; i < 300; i++) { char ch = 0; DWORD read = 0; while(!read) { ReadFile(m_hFile, &ch, 1, &read, NULL); if (read) { if (ch==1 | ch==0 ){ hibyte=ch; } else{ lowbyte=ch; } pos=(255*hibyte)+lowbyte; ydummy=(double)(pos); y=(-ydummy/800)-1; if(y>-0.90){ y=-0.95; } } } } } CloseHandle(m_hFile); //================================================================== if(m_hFile2!=NULL) {//read 100 lines from serial port for (int j = 0; j < 300; j++) { char ch2 = 0; DWORD read2 = 0; while(!read2) { ReadFile(m_hFile2, &ch2, 1, &read2, NULL); if (read2) { if (ch2==1 | ch2==2){ hibyte2=ch2; } else{ lowbyte2=ch2; } pos2=((255*hibyte2)+lowbyte2)-450; xdummy=(double)(pos2); x=((xdummy)/200); } } } } CloseHandle(m_hFile2); //********************************************************************* dy=0.00; using core::behavior::MechanicalState; mState1 = dynamic_cast<MechanicalState<sofa::defaulttype::Rigid3dTypes> *>(this->getContext()->getMechanicalState()); helper::WriteAccessor<sofa::core::objectmodel:: Data<sofa::defaulttype::Rigid3dTypes::VecCoord> > xp = *mState1->write(core::VecCoordId::position()); xp[0].getCenter()=sofa::defaulttype::Vec<3,Real>((Real)((x)),(Real)dy,(Real)((y)));
As you can see I have to open and close the serial port each time I run a graphical loop which is the worst optimized option and is causing delay in my simulation.
Thank you beforehand,
Mehdi
MadaniBlockedThank you so much Hugo!
I guessed that you might have been busy. I have another question which is not related to this topic but I first just wanted to make sure if it is possible or not and then ask the detail in another post.
Is it possible to have text or simulation data on SOFA screen while simulating a scene?Thanks again,
Mehdi
MadaniBlockedFinally the problem is solved!!!
It turned out that NI has two versions of NIDAQmx.lib files one for 32bit operationg systems and another one for 64bit ones. and apparently I was using 32bit version although my project was compiled on 64bit operating system and 64bit mode in VS2012.
For others who might wonder where it is located, if you had installed NIDAQmx correctly you should be able to find it in the following directory:<Program Files>\NationalInstruments\Shared\ExternalCompilerSupport\C\lib64\msvc
Good Luck,
Mehdi
MadaniBlockedMy last discovery is this: Now I am sure that I am adding NIDAQmx.lib to my project when I build it with CMake. I think the problem is in this part of NIDAQmx.h :
#if defined(__linux__) || defined(__APPLE__) #define __CFUNC #define __CFUNC_C #define __CFUNCPTRVAR #define CVICDECL #define CVICALLBACK CVICDECL #else #define __CFUNC __stdcall #define __CFUNC_C __cdecl #define __CFUNCPTRVAR __cdecl #define CVICDECL __cdecl #define CVICALLBACK CVICDECL #endif
and now the errors are like these:
Error 4135 error LNK2019: unresolved external symbol DAQmxCreateTask referenced in function "public: virtual void __cdecl sofa::component::behaviormodel::MyBehaviorModel::updatePosition(double)" (?updatePosition@MyBehaviorModel@behaviormodel@component@sofa@@UEAAXN@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 4136 error LNK2019: unresolved external symbol DAQmxStartTask referenced in function "public: virtual void __cdecl sofa::component::behaviormodel::MyBehaviorModel::updatePosition(double)" (?updatePosition@MyBehaviorModel@behaviormodel@component@sofa@@UEAAXN@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 4137 error LNK2019: unresolved external symbol DAQmxStopTask referenced in function "public: virtual void __cdecl sofa::component::behaviormodel::MyBehaviorModel::updatePosition(double)" (?updatePosition@MyBehaviorModel@behaviormodel@component@sofa@@UEAAXN@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 4138 error LNK2019: unresolved external symbol DAQmxClearTask referenced in function "public: virtual void __cdecl sofa::component::behaviormodel::MyBehaviorModel::updatePosition(double)" (?updatePosition@MyBehaviorModel@behaviormodel@component@sofa@@UEAAXN@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 4139 error LNK2019: unresolved external symbol DAQmxCreateAIVoltageChan referenced in function "public: virtual void __cdecl sofa::component::behaviormodel::MyBehaviorModel::updatePosition(double)" (?updatePosition@MyBehaviorModel@behaviormodel@component@sofa@@UEAAXN@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 4140 error LNK2019: unresolved external symbol DAQmxCfgSampClkTiming referenced in function "public: virtual void __cdecl sofa::component::behaviormodel::MyBehaviorModel::updatePosition(double)" (?updatePosition@MyBehaviorModel@behaviormodel@component@sofa@@UEAAXN@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 4141 error LNK2019: unresolved external symbol DAQmxReadAnalogF64 referenced in function "public: virtual void __cdecl sofa::component::behaviormodel::MyBehaviorModel::updatePosition(double)" (?updatePosition@MyBehaviorModel@behaviormodel@component@sofa@@UEAAXN@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 4142 error LNK2019: unresolved external symbol DAQmxCfgInputBuffer referenced in function "public: virtual void __cdecl sofa::component::behaviormodel::MyBehaviorModel::updatePosition(double)" (?updatePosition@MyBehaviorModel@behaviormodel@component@sofa@@UEAAXN@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 4143 error LNK2019: unresolved external symbol DAQmxGetExtendedErrorInfo referenced in function "public: virtual void __cdecl sofa::component::behaviormodel::MyBehaviorModel::updatePosition(double)" (?updatePosition@MyBehaviorModel@behaviormodel@component@sofa@@UEAAXN@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 4144 error LNK1120: 9 unresolved externals C:\Sofa\bin\Debug\NIPlugin_d.dll NIPlugin
As you see there is a __cdecl prefix before sofa class definition in NIDAQmx.h which prevents it to match the definition I have in the source file.and if I remove this part of NI code I receive multiple other errors which indicate I have not declared the functions and lots of syntax errors.
As an example here is the definition of DAQmxCreateTask in NIDAQmx.h:
int32 __CFUNC DAQmxCreateTask (const char taskName[], TaskHandle *taskHandle);
which has a __cdecl at the beginning because of the first definition in windows environment.and another problem is that I don’t know what is inside NIDAQmx.lib and how it is defined so I can match my definition to that.
after all I don’t have that much knowledge of C++ coding concept to find out where the problem lies. My thesis will be finished if I can remove these errors and make the code work 🙂
Thank you again.
MadaniBlockedI checked it with mine and it seems fine. I think Cmake has problem finding your SofaGUI. Try to follow the compilation steps in https://www.sofa-framework.org/community/doc/getting-started/build/build-on-windows/
let me know if it works or not.
Regards,
Mehdi
MadaniBlockedI can guess that you might be busy. Just to keep you updated I managed to remove all the errors and added NIDAQmx.lib in the CmakeList.txt using the following link https://mplab-ros-pkg.googlecode.com/svn-history/r48/trunk/nidaqIO/CMakeLists.txt but it seems I still could not link the library because I get LNK2019 errors.here are the errors:
Error 3 error LNK2019: unresolved external symbol DAQmxStopTask referenced in function "int __cdecl nidaq(int,char * * const)" (?nidaq@@YAHHQEAPEAD@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 2 error LNK2019: unresolved external symbol DAQmxStartTask referenced in function "int __cdecl nidaq(int,char * * const)" (?nidaq@@YAHHQEAPEAD@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 7 error LNK2019: unresolved external symbol DAQmxReadAnalogF64 referenced in function "int __cdecl nidaq(int,char * * const)" (?nidaq@@YAHHQEAPEAD@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 9 error LNK2019: unresolved external symbol DAQmxGetExtendedErrorInfo referenced in function "int __cdecl nidaq(int,char * * const)" (?nidaq@@YAHHQEAPEAD@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 1 error LNK2019: unresolved external symbol DAQmxCreateTask referenced in function "int __cdecl nidaq(int,char * * const)" (?nidaq@@YAHHQEAPEAD@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 5 error LNK2019: unresolved external symbol DAQmxCreateAIVoltageChan referenced in function "int __cdecl nidaq(int,char * * const)" (?nidaq@@YAHHQEAPEAD@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 4 error LNK2019: unresolved external symbol DAQmxClearTask referenced in function "int __cdecl nidaq(int,char * * const)" (?nidaq@@YAHHQEAPEAD@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 6 error LNK2019: unresolved external symbol DAQmxCfgSampClkTiming referenced in function "int __cdecl nidaq(int,char * * const)" (?nidaq@@YAHHQEAPEAD@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 8 error LNK2019: unresolved external symbol DAQmxCfgInputBuffer referenced in function "int __cdecl nidaq(int,char * * const)" (?nidaq@@YAHHQEAPEAD@Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin Error 10 error LNK1120: 9 unresolved externals C:\Sofa\bin\Debug\NIPlugin_d.dll 1 NIPlugin 1
I even added the NIDAQmx.lib to external dependecy of the plugin properties in VisualStudio but it does not seem to work.
Regards,
Mehdi
MadaniBlockedcan you post your CMAKELists.txt in PluginExample?
and do you want to add anything else to Plugin or just want to see the default plugin?MadaniBlockedI started following the steps you mentioned and built a new plugin named NIPlugin and moved my codes there. and changed the main CMakeLists.txt so NIPlugin appears in the CMake menu. but I still get the same error.
CMake Error at applications/plugins/NIPlugin/CMakeLists.txt:39 (TARGET_LINK_LIBRARIES):
Cannot specify link libraries for target “NIPlugin” which is not built by
this project.and here is my CMakeLists.txt now:
cmake_minimum_required(VERSION 2.8.12) project(NIPlugin) # For NIDAQ IF(WIN32) INCLUDE_DIRECTORIES("C:\\Program Files (x86)\\National Instruments\\NI-DAQ\\DAQmx ANSI C Dev\\include") LINK_DIRECTORIES("C:\\Program Files (x86)\\National Instruments\\NI-DAQ\\DAQmx ANSI C Dev\\lib\\msvc") ENDIF (WIN32) set(HEADER_FILES MyBehaviorModel.h MyMappingPendulumInPlane.h MyMappingPendulumInPlane.inl MyProjectiveConstraintSet.h MyProjectiveConstraintSet.inl NIDAQmx.h config.h ) set(HEADER_FILES_TO_MOC MyDataWidgetUnsigned.h ) set(SOURCE_FILES MyBehaviorModel.cpp MyDataWidgetUnsigned.cpp MyMappingPendulumInPlane.cpp MyProjectiveConstraintSet.cpp initPlugin.cpp ) set(README_FILES NIPlugin.txt) find_package(SofaGui REQUIRED) find_package(Qt4 REQUIRED) qt4_wrap_cpp(MOCCED_HEADER_FILES ${HEADER_FILES_TO_MOC}) IF(WIN32) TARGET_LINK_LIBRARIES(${PROJECT_NAME} NIDAQmx.lib ${QT_LIBRARIES} NIDAQmx ) ENDIF (WIN32) add_library(${PROJECT_NAME} SHARED ${HEADER_FILES_TO_MOC} ${MOCCED_HEADER_FILES} ${HEADER_FILES} ${SOURCE_FILES} ${README_FILES}) set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-DSOFA_BUILD_NIPlugin") target_link_libraries(${PROJECT_NAME} SofaGuiQt NIDAQmx.lib) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/.. git/sofa/application/plugins/NIPlugin") install(TARGETS ${PROJECT_NAME} COMPONENT NIPlugin_libraries EXPORT NIPluginTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
thanks again
Regards,
Mehdi
MadaniBlockedgood news! I managed to compile it with CMake 3.3 but when I wan to build SOFA I encounter these kinds of error:
error C1083: Cannot open include file: ‘PluginExample/config.h’: No such file or directory (C:\git\sofa\applications\plugins\PluginExample\MyDataWidgetUnsigned.cpp) c:\git\sofa\applications\plugins\pluginexample\MyDataWidgetUnsigned.h
this happens for the files included in CMake. So I think CMake does not really include them when compiles SOFA. I also tried to copy them to the destination of SOFA built code but it did not work.
The other error is this:Error 3399 error C2491: ‘getModuleDescription’ : definition of dllimport function not allowed C:\git\sofa\applications\plugins\PluginExample\initPlugin.cpp
which I checked for the reason but I do not have _cdlcde which I want to delet.
By the way here is my current version of CMakeList.xt that I use:
cmake_minimum_required(VERSION 2.8.12) project(PluginExample) # For NIDAQ IF(WIN32) INCLUDE_DIRECTORIES("C:\\Program Files (x86)\\National Instruments\\NI-DAQ\\DAQmx ANSI C Dev\\include") LINK_DIRECTORIES("C:\\Program Files (x86)\\National Instruments\\NI-DAQ\\DAQmx ANSI C Dev\\lib\\msvc") ENDIF (WIN32) set(HEADER_FILES MyBehaviorModel.h MyMappingPendulumInPlane.h MyMappingPendulumInPlane.inl MyProjectiveConstraintSet.h MyProjectiveConstraintSet.inl NIDAQmx.h config.h ) set(HEADER_FILES_TO_MOC MyDataWidgetUnsigned.h ) set(SOURCE_FILES MyBehaviorModel.cpp MyDataWidgetUnsigned.cpp MyMappingPendulumInPlane.cpp MyProjectiveConstraintSet.cpp initPlugin.cpp ) set(README_FILES PluginExample.txt) find_package(SofaGui REQUIRED) find_package(Qt4 REQUIRED) qt4_wrap_cpp(MOCCED_HEADER_FILES ${HEADER_FILES_TO_MOC}) add_library(${PROJECT_NAME} SHARED ${HEADER_FILES_TO_MOC} ${MOCCED_HEADER_FILES} ${HEADER_FILES} ${SOURCE_FILES} ${README_FILES}) set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-DSOFA_BUILD_PluginExample") target_link_libraries(${PROJECT_NAME} SofaGuiQt NIDAQmx.lib) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/.. git/sofa/application/plugins/PluginExample") IF(WIN32) TARGET_LINK_LIBRARIES(${PROJECT_NAME} NIDAQmx.lib ${QT_LIBRARIES} NIDAQmx ) ENDIF (WIN32) install(TARGETS ${PROJECT_NAME} COMPONENT PluginExample_libraries EXPORT PluginExampleTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
thanks beforehand.
Regards,
Mehdi
MadaniBlockedIt’s named PluginExample (I just modified existing plugin example of SOFA and put my own code inside it).
I did these steps still no progress (the same error occurs just the name changed from PluginExample to NIPlugin). Sorry if my problem seems so elementary and I bother you. A part is because I’m a mechanical engineer and not that much professional in C++.
Best,
Mehdi
MadaniBlockedThanks
I did what you said and now I get this error:(TARGET_LINK_LIBRARIES):
Cannot specify link libraries for target “PluginExample” which is not built
by this project.and my CmaleLists is like this now:
cmake_minimum_required(VERSION 2.8.12) project(PluginExample) # For NIDAQ IF(WIN32) INCLUDE_DIRECTORIES("C:\\Program Files (x86)\\National Instruments\\NI-DAQ\\DAQmx ANSI C Dev\\include") LINK_DIRECTORIES("C:\\Program Files (x86)\\National Instruments\\NI-DAQ\\DAQmx ANSI C Dev\\lib\\msvc") ENDIF (WIN32) set(HEADER_FILES MyBehaviorModel.h MyMappingPendulumInPlane.h MyMappingPendulumInPlane.inl MyProjectiveConstraintSet.h MyProjectiveConstraintSet.inl NIDAQmx.h config.h ) set(HEADER_FILES_TO_MOC MyDataWidgetUnsigned.h ) set(SOURCE_FILES MyBehaviorModel.cpp MyDataWidgetUnsigned.cpp MyMappingPendulumInPlane.cpp MyProjectiveConstraintSet.cpp initPlugin.cpp ) set(README_FILES PluginExample.txt) find_package(SofaGui REQUIRED) find_package(Qt4 REQUIRED) qt4_wrap_cpp(MOCCED_HEADER_FILES ${HEADER_FILES_TO_MOC}) IF(WIN32) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${QT_LIBRARIES} NIDAQmx ) ENDIF (WIN32) add_library(${PROJECT_NAME} SHARED ${HEADER_FILES_TO_MOC} ${MOCCED_HEADER_FILES} ${HEADER_FILES} ${SOURCE_FILES} ${README_FILES}) set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-DSOFA_BUILD_PLUGINEXAMPLE") target_link_libraries(${PROJECT_NAME} SofaGuiQt NIDAQmx.lib) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/.. git/sofa/application/plugins/PluginExample") install(TARGETS ${PROJECT_NAME} COMPONENT PluginExample_libraries EXPORT PluginExampleTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
Regards,
MadaniBlockedThank you so much Hugo
I can imagine how busy you are and sorry for my late reply as well, I was out of office last week.My problem still exists but I get different error (LK2019). I think that’s because I do not include NIDAQ library correctly. Thanks for your suggestion, it would be a great help if you can take a look at it.Here is my CMakeList file content:
cmake_minimum_required(VERSION 2.8.12) project(PluginExample) set(HEADER_FILES MyBehaviorModel.h MyMappingPendulumInPlane.h MyMappingPendulumInPlane.inl MyProjectiveConstraintSet.h MyProjectiveConstraintSet.inl NIDAQmx.h config.h ) set(HEADER_FILES_TO_MOC MyDataWidgetUnsigned.h ) set(SOURCE_FILES MyBehaviorModel.cpp MyDataWidgetUnsigned.cpp MyMappingPendulumInPlane.cpp MyProjectiveConstraintSet.cpp initPlugin.cpp ) set(README_FILES PluginExample.txt) find_package(SofaGui REQUIRED) find_package(Qt4 REQUIRED) qt4_wrap_cpp(MOCCED_HEADER_FILES ${HEADER_FILES_TO_MOC}) add_library(${PROJECT_NAME} SHARED ${HEADER_FILES_TO_MOC} ${MOCCED_HEADER_FILES} ${HEADER_FILES} ${SOURCE_FILES} ${README_FILES}) set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-DSOFA_BUILD_PLUGINEXAMPLE") target_link_libraries(${PROJECT_NAME} SofaGuiQt NIDAQmx.lib) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/.. git/sofa/application/plugins/PluginExample") install(TARGETS ${PROJECT_NAME} COMPONENT PluginExample_libraries EXPORT PluginExampleTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
Regards,
Mehdi
MadaniBlockedThanks for your reply Hugo. My code for data reading from NI acquisition board is this:
*******************************************************************************************
#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } } int main(int argc, char *argv[]) { printf("Example will halt automatically.\n"); DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle)); DAQmxErrChk (DAQmxBaseCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL)); DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,clockSource,sampleRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,samplesPerChan)); DAQmxErrChk (DAQmxBaseCfgInputBuffer(taskHandle,200000)); //use a 100,000 sample DMA buffer DAQmxErrChk (DAQmxBaseStartTask(taskHandle)); // The loop will quit after 10 seconds startTime = time(NULL); while( time(NULL)<startTime+10 ) { DAQmxErrChk (DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByScanNumber,data,bufferSize*2,&pointsRead,NULL)); totalRead += pointsRead; printf("Acquired %ld samples. Total %ld\n",pointsRead,totalRead); // Just print out the first 10 points of the last data read for (i = 0; i < 10; ++i) printf ("data0[%ld] = %f\tdata1[%ld] = %f\n",i,data[2*i],i,data[2*i+1]); } printf("\nAcquired %ld total samples.\n",totalRead); Error: if( DAQmxFailed(error) ) DAQmxBaseGetExtendedErrorInfo(errBuff,2048); if(taskHandle != 0) { DAQmxBaseStopTask (taskHandle); DAQmxBaseClearTask (taskHandle); } if( DAQmxFailed(error) ) printf ("DAQmxBase Error %ld: %s\n", error, errBuff); }
***********************************************************************************
The error I get is that DAQmxBaseStartTask identifier not found although I have attached NI library header to my plugin header and defined the functions in the public section of MyBehaviorModel.h .this is one of the functions the same applies to other functions as well. I will go through what you suggested and will let you know.
MadaniBlockedThe last step has come finally!
I managed to connect it to the COM port in visual studio.I have plugged my code into the MyBehaviorModel::updatePosition. The problem is that sofa just reads the port values once when simulation starts and does not iterate the procedure on every loop. The annoying thing is that if I assign an incremental value to (for example dz as dz-=0.1) it works fine but it just does not work with COM port code.Any idea about the problem?
MadaniBlockedHello Froy
thank you so much for your time and attention!
You are right I forgot to include pluginexample.dll in the RunSofa.exe file that was why it gave me the error I fixed it and now plugin loads.however the problem still seems to be the handle to COM port. the irritating thing is that the same code works out of SOFA but it does not inside MyBehaviorModel.cpp!!MadaniBlockedI managed to step even further I just gave it a try and opened RunSofa in administration mode and opned my file in administrative mode and the problem changed.Now I get the error that MyBehaviorModel creation failed. I have no clue where the problem is originated from.any help would be appreciated.
MadaniBlockedI have managed to make my own plugin (actually it is not my own it is the plugin example of SOFA that I modified) and can control the position of the mechanical object by assigning increments to each coordination axis of my scene. The issue is that I want to connect it to my own encoders.I have the code which can read the serial port in VS c++ 11 and it works as a separate solution but when I plug it into the MyBehaviourModel in plugin example it seems that SOFA does not let me to allocate a handle to my COM port and give the error of INVALID_HANDLE_VALUE- ERROR_FILE_NOT_FOUND.do you have any idea where the problem might lie? I mean is there any security policy designed in SOFA for not letting me access the COM port?
-
AuthorPosts