RString LoadingWindow_Gtk::Init() { ASSERT( Handle == NULL ); Handle = dlopen( RageFileManagerUtil::sDirOfExecutable + "/" + "GtkModule.so", RTLD_NOW ); if( Handle == NULL ) return ssprintf( "dlopen(): %s", dlerror() ); Module_Init = (INIT) dlsym(Handle, "Init"); if( !Module_Init ) return ModuleError("Init"); Module_Shutdown = (SHUTDOWN) dlsym(Handle, "Shutdown"); if( !Module_Shutdown ) return ModuleError("Shutdown"); Module_SetText = (SETTEXT) dlsym(Handle, "SetText"); if( !Module_SetText ) return ModuleError("SetText"); Module_SetIcon = (SETICON) dlsym(Handle, "SetIcon"); if( !Module_SetIcon ) return ModuleError("SetIcon"); Module_SetSplash = (SETSPLASH) dlsym(Handle, "SetSplash"); if( !Module_SetSplash ) return ModuleError("SetSplash"); Module_SetProgress = (SETPROGRESS) dlsym(Handle, "SetProgress"); if( !Module_SetProgress ) return ModuleError("SetProgress"); Module_SetIndeterminate = (SETINDETERMINATE) dlsym(Handle, "SetIndeterminate"); if( !Module_SetIndeterminate ) return ModuleError("SetIndeterminate"); const char *ret = Module_Init( &g_argc, &g_argv ); if( ret != NULL ) return ret; return ""; }
void iqrcommon::moduleEPuck::init(){ // cout << "moduleEPuck::init()" << endl; ClsBaseKRobot::init(); #ifdef IQRMODULE string strSerialPort = clsStringParameterSerialPort->getValue(); bShowOutput = clsBoolParameterShowOutput->getValue(); bLEDFrontal = clsBoolParameterLEDFrontal->getValue(); bLEDLateral = clsBoolParameterLEDLateral->getValue(); #else string strSerialPort = "/dev/rfcomm0"; bLEDFrontal = true; bLEDLateral = true; bShowOutput = true; #endif string strReply; int iSerialSpeed; iSerialSpeed = B38400; // iSerialSpeed = B115200; serialPort.setDfltTimeOut(3000); serialPort.setDevice(strSerialPort); serialPort.setBaudRate(iSerialSpeed); if (serialPort.openDevice()) { serialPort.flush(); } else { throw ModuleError(string("Module \"") + label() + "\": opening serial port " + strSerialPort); } iCounter = 0; std::stringstream ssSpeed; ssSpeed << robotCmds::setSpeed() << ",0,0"; serialPort.writeLine(ssSpeed.str()); // cout << "+command: " << ssSpeed.str() << endl; strReply=serialPort.readLine(); if (!strReply.find("d")!=std::string::npos) { serialPort.flush(); } std::stringstream ssControler; ssControler << robotCmds::setSpeedControler() << "," << iSCProportional << "," << iSCIntegral << "," << iSCDifferential; serialPort.writeLine(ssControler.str()); // cout << "+command: " << ssControler.str() << endl; if (!serialPort.readLine().find("a")!=std::string::npos){ serialPort.flush(); } // serialPort.writeLine(str.sprintf("%s,1,%d", robotCmds::setLEDs(), // (bLEDFrontal ? 1 : 0))); // ss.clear(); std::stringstream ssLEDFrontal; ssLEDFrontal << robotCmds::setLEDs() << ",1," << (bLEDFrontal ? 1 : 0); serialPort.writeLine(ssLEDFrontal.str()); // cout << "+command: " << ssLEDFrontal.str() << endl; if (!serialPort.readLine().find("l")!=std::string::npos) { serialPort.flush(); } // serialPort.writeLine(str.sprintf("%s,0,%d", robotCmds::setLEDs(), // (bLEDLateral ? 1 : 0))); // ss.clear(); std::stringstream ssLEDLateral; ssLEDLateral << robotCmds::setLEDs() << ",0," << (bLEDLateral ? 1 : 0); serialPort.writeLine(ssLEDLateral.str()); // cout << "+command: " << ssLEDLateral.str() << endl; if (!serialPort.readLine().find("l")!=std::string::npos) { serialPort.flush(); } if(bShowOutput){ clsEPuckDisp = new ClsEPuckDisp("EPuck Display"); clsEPuckDisp->setGeometry(0, 0, 250, 250); clsEPuckDisp->DrawStatus( ); clsEPuckDisp->show(); } };
iqrcommon::moduleBttvVideo::moduleBttvVideo() : ClsBaseVideoItem() { #else iqrcommon::moduleBttvVideo::moduleBttvVideo() { #endif #ifdef IQRMODULE clsStateVariableVideoOutput = addOutputToGroup("videoOutput", "Video Output"); #endif iRoundCounter = 0; } #ifdef IQRMODULE moduleIcon iqrcommon::moduleBttvVideo::getIcon() { moduleIcon mi(ModuleIcon_CameraBttv_png_data, ModuleIcon_CameraBttv_png_len, 3 ,5); return mi; } #endif iqrcommon::moduleBttvVideo::~moduleBttvVideo() { cleanup(); } void iqrcommon::moduleBttvVideo::init() { cout << "moduleBttvVideo::init()" << endl; fCPS = 50; deviceID = -1; captureBuf = NULL; ClsBaseVideoItem::init(); openDevice( strDeviceName) ; // Select Y8 capture format captureFormat = V4L_FORMAT_Y8; // Initialize capture size based on window size // Initialize picture attributes to mid-range v4lFormat.width = imgWidth; v4lFormat.height = imgHeight; v4lFormat.format = captureFormat;; V4LMSetFormat(&v4lFormat); V4LMGetFormat(&v4lFormat); imgWidth = v4lFormat.width; imgHeight = v4lFormat.height; captureFrame = 0; if (V4LMCapture(deviceID, captureFrame) < 0) { #ifdef IQRMODULE throw ModuleError(string("Module \"") + label() + "\": Error: V4LMCapture: " + strerror(errno)); #else cerr << "Error: V4LMCapture: " << strerror(errno) << endl; exit(1); #endif } setPictureProperties(); if(bShowOutput) { clsXWin.createWindow(imgWidth, imgHeight); iScreenDepth = clsXWin.getScreenDepth(); if(iScreenDepth != 16 && iScreenDepth != 24) { cerr << "Cannot screen depth of " << iScreenDepth << endl; #ifdef IQRMODULE throw ModuleError(string("Module \"") + label() + "\": Error: V4LMCapture: " + strerror(errno)); #else exit(-1); #endif } } #ifdef IQRMODULE iNrCells = clsStateVariableVideoOutput->getStateArray().getWidth(); iGroupWidth = (int)(sqrt((double)iNrCells / fImageRatio)); iGroupHeight = iNrCells/iGroupWidth; iHPace = (int)ceil((double)imgWidth / (double)iGroupWidth); iVPace = (int)ceil((double)imgHeight / (double)iGroupHeight); // cout << "iHPace, iVPace: " << iHPace << ", " << iVPace << endl; // cout << "iGroupWidth, iGroupHeight: " << iGroupWidth << ", " << iGroupHeight << endl; #endif printDeviceInfo(); }
void iqrcommon::moduleBttvVideo::openDevice(string strDeviceName) { cout << "moduleBttvVideo::openDevice(string strDeviceName)" << endl; cout << "device: " << strDeviceName << endl; errno = 0; if ((deviceID = open(strDeviceName.c_str(), O_RDWR)) < 0) { #ifdef IQRMODULE throw ModuleError(string("Module \"") + label() + "\": Error: Can't open: " + strDeviceName + ", Error: " + strerror(errno)); #else cerr << "Error: Can't open: " << strDeviceName.c_str() << ", Error: " << strerror(errno) << endl; exit(1); #endif } if (V4LMGetMMInfo(deviceID, &v4lMMInfo) < 0) { #ifdef IQRMODULE throw ModuleError(string("Module \"") + label() + "\": Error: V4LMGetMMInfo: " + strerror(errno)); #else cerr << "Error: V4LMGetMMInfo: " << strerror(errno) << endl; exit(1); #endif } //#if (0) cerr << "Capture buffer size = " << v4lMMInfo.size << endl; cerr << "Capture buffer frames = " << v4lMMInfo.frames << endl; //#endif if (v4lMMInfo.frames < 2) { #ifdef IQRMODULE throw ModuleError(string("Module \"") + label() + "\": Error: V4LMGetMMInfo: frames < 2" + strerror(errno)); #else cerr << "Error: V4LMGetMMInfo: frames < 2" << endl; exit(1); #endif } if ((captureBuf = (bits8 *) mmap(0, v4lMMInfo.size, PROT_READ | PROT_WRITE, MAP_SHARED, deviceID, 0)) == MAP_FAILED) { #ifdef IQRMODULE throw ModuleError(string("Module \"") + label() + "\": Error: mmap(): " + strerror(errno)); #else cerr << "Error: mmap(): " << strerror(errno) << endl; exit(1); #endif } // if (V4LSetSource(v4l, BigPictureCompositeSource, VIDEO_MODE_NTSC) < 0) { if (V4LSetSource(deviceID, BigPictureCompositeSource, VIDEO_MODE_PAL) < 0) { #ifdef IQRMODULE throw ModuleError(string("Module \"") + label() + "\": Error: V4LSetSource: " + strerror(errno)); #else cerr << "Error: V4LSetSource: " << strerror(errno) << endl; exit(1); #endif } if (V4LGetCaps(deviceID, &v4lCaps) < 0) { #ifdef IQRMODULE throw ModuleError(string("Module \"") + label() + "\": Error: V4LGetCaps: " + strerror(errno)); #else cerr << "Error: V4LGetCaps: " << strerror(errno) << endl; exit(1); #endif } }
void iqrcommon::moduleKhepera::init(){ // cout << "moduleKhepera::init()" << endl; ClsBaseKRobot::init(); #ifdef IQRMODULE string strSerialPort = clsStringParameterSerialPort->getValue(); bShowOutput = clsBoolParameterShowOutput->getValue(); bLEDFrontal = clsBoolParameterLEDFrontal->getValue(); bLEDLateral = clsBoolParameterLEDLateral->getValue(); #else string strSerialPort = "/dev/ttyS0"; bLEDFrontal = true; bLEDLateral = true; bShowOutput = true; #endif string strReply; int iSerialSpeed; iSerialSpeed = B38400; // iSerialSpeed = B115200; serialPort.setDfltTimeOut(50); serialPort.setDevice(strSerialPort); serialPort.setBaudRate(iSerialSpeed); if (serialPort.openDevice()) { serialPort.flush(); serialPort.writeLine("restart"); // serialPort.writeLine("B"); bool timedOut; bool ok=false; do { cout << "strReply: " << strReply << endl; strReply=serialPort.readLine(1000 ,&timedOut); if (strReply.find("Command not found")!=std::string::npos){ serialPort.writeLine("restart"); } else if (strReply.find("ROM of minirobot")!=std::string::npos || strReply.find("hemisson")!=std::string::npos){ ok=true; } } while (!timedOut); if (!ok) { throw ModuleError(string("Module \"") + label() + "\": Cannot find robot on " + strSerialPort ); serialPort.closeDevice(); } } else { throw ModuleError(string("Module \"") + label() + "\": opening serial port " + strSerialPort); } iCounter = 0; // serialPort.writeLine(str.sprintf("%s,0,0", robotCmds::setSpeed())); // ss.clear(); std::stringstream ssSpeed; ssSpeed << robotCmds::setSpeed() << ",0,0"; serialPort.writeLine(ssSpeed.str()); // cout << "+command: " << ssSpeed.str() << endl; strReply=serialPort.readLine(); if (!strReply.find("d")!=std::string::npos) { serialPort.flush(); } // serialPort.writeLine(str.sprintf("%s,%d,%d,%d", robotCmds::setSpeedControler(), // iSCProportional, // iSCIntegral, // iSCDifferential)); // ss.clear(); std::stringstream ssControler; ssControler << robotCmds::setSpeedControler() << "," << iSCProportional << "," << iSCIntegral << "," << iSCDifferential; serialPort.writeLine(ssControler.str()); // cout << "+command: " << ssControler.str() << endl; if (!serialPort.readLine().find("a")!=std::string::npos){ serialPort.flush(); } // serialPort.writeLine(str.sprintf("%s,1,%d", robotCmds::setLEDs(), // (bLEDFrontal ? 1 : 0))); // ss.clear(); std::stringstream ssLEDFrontal; ssLEDFrontal << robotCmds::setLEDs() << ",1," << (bLEDFrontal ? 1 : 0); serialPort.writeLine(ssLEDFrontal.str()); // cout << "+command: " << ssLEDFrontal.str() << endl; if (!serialPort.readLine().find("l")!=std::string::npos) { serialPort.flush(); } // serialPort.writeLine(str.sprintf("%s,0,%d", robotCmds::setLEDs(), // (bLEDLateral ? 1 : 0))); // ss.clear(); std::stringstream ssLEDLateral; ssLEDLateral << robotCmds::setLEDs() << ",0," << (bLEDLateral ? 1 : 0); serialPort.writeLine(ssLEDLateral.str()); // cout << "+command: " << ssLEDLateral.str() << endl; if (!serialPort.readLine().find("l")!=std::string::npos) { serialPort.flush(); } if(bShowOutput){ clsKhepDisp = new ClsKhepDisp("Khepera Display"); clsKhepDisp->setGeometry(0, 0, 250, 250); clsKhepDisp->DrawStatus( ); clsKhepDisp->show(); } };