//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++ task main() { // variables to be used: int sonar_value; // Will hold the current reading of the sonar sensor. int light_value; int potmeter_value; int bumper_value; int switch_value; int encoder_value; int timer_value; int minPos = 0; int min=1090; int minPot; potmeter_value = SensorValue(Potmeter_sensor); SensorValue[QuadEncoder] = 0; //clear and reset the encoder SensorValue[RotEncoder] = 0; while(true) { // IF THE JUMPER IS NOT IN, DISPLAY THESE SENSORS: if(SensorValue(Jumper)) { ClearTimer(T1); light_value = SensorValue(Light_sensor); writeDebugStreamLine("light value = %d\n", light_value); potmeter_value = SensorValue(Potmeter_sensor); writeDebugStreamLine("potmeter value = %d\n", potmeter_value); bumper_value = SensorValue(Bump); writeDebugStreamLine("bumper value = %d\n", bumper_value); switch_value = SensorValue(LimitSwitch); writeDebugStreamLine("whisker value = %d\n", switch_value); wait1Msec(1000); //Gets the value of Timer T1 in 1ms increments and stores it in a variable timer_value = time1[T1]; //printVal = (int)timerVal; writeDebugStreamLine("time to read these values = %d\n", timer_value); timer_value = time1[T3]; writeDebugStream("time since start = %d\n", timer_value); writeDebugStreamLine("...................................");//(35) =limit of chars to put in debug stream....? if(doMotor){ for(int i = -127; i<127 ; i +=1) { MotorMove(i); } } } // ELSE DISPLAY FROM OTHER SENSORS: else { ClearTimer(T2); writeDebugStreamLine("sonar value = %d\n", sonar_value); encoder_value = SensorValue(QuadEncoder); writeDebugStreamLine("Quad encoder value = %d\n", encoder_value); encoder_value = SensorValue(RotEncoder); writeDebugStreamLine("Rotation encoder value = %d\n", encoder_value); //Gets the value of Timer T2 in 1ms increments and stores it in a variable timer_value = time1[T2]; writeDebugStreamLine("time to read these values = %d\n", timer_value); timer_value = time1[T3]; writeDebugStreamLine("time since start = %d\n", timer_value); writeDebugStreamLine("...................................");//(35) =limit of chars to put in debug stream....? wait1Msec(10); if(doServo){ motor[leftMotor] = 0; motor[rightMotor] = 0; for (int i = -127; i<127 ; i +=3) { ServoMove(i); potmeter_value = SensorValue(Potmeter_sensor); light_value =SensorValue (Light_sensor); if (light_value < min){ min = light_value; minPos = i; minPot = potmeter_value; } //if(i < 40 || i >100) { // i+= 19; //} // Function to get potemeter values at specific angles. //if(i == -71 || i == 0 || i == 85){ // writeDebugStreamLine("Hey! %d", potmeter_value); //} //writeDebugStreamLine("%d",min); //if(i >= -28){ // minPot = SensorValue(Potmeter_sensor); // break; //} } // doServo = false; ServoMove(minPos); writeDebugStreamLine("%d",minPos); int angle = abs(180-(minPot - 3911.0944)/(-14.38668)); writeDebugStreamLine("Our final angle is: %d. final servo: %d, final potent %d",angle, minPos, minPot); WhichMotor(abs(90-angle),(angle<90)); min = 1090; } } } }
MainWindow::MainWindow( QString myname ) : QMainWindow() { setupUi( this ); MainTab->setCurrentIndex( 0 ); RWDXMCenterF = false; DXMCenterFile = DXMCENTERFILE0; MCACanSaveAllOnMem = false; MCAPreAMPGainHasSet = false; MaxMCAEnergy = 20; MStabOk = false; MStabDelegate = ""; #if 0 AutoShutter->setChecked( false ); // 自動シャッターのボタンはデフォルトでは AutoShutter->setEnabled( false ); // 使えなくしておく #endif MCAFSel = scanFSel = monFSel = S2DFileSel = SelDFND = SelWBFND = SelRBFND = SelLFND = NULL; // Monitor の中で SSD の強度を別ファイルに書き出すときの時間を測るため T = new QTime; T->start(); FSTATMsgs[0][0] = tr( "Both the name and the data is old." ); FSTATMsgs[0][1] = tr( "The name is new, but the data is old." ); FSTATMsgs[1][0] = tr( "The data is new, but the name is old." ); FSTATMsgs[1][1] = tr( "The data and the name is new, but not saved." ); MeasDataStat = MeasNameStat = OLD; ScanDataStat = ScanNameStat = OLD; MonDataStat = MonNameStat = OLD; MCADataStat = MCANameStat = OLD; S2DDataStat = S2DNameStat = OLD; isQXafsModeAvailable = false; XMAPk2p = new KeV2Pix; fdbase = new FluoDBase; u = new Units; MMainTh = NULL; MDTh1 = NULL; EncMainTh = NULL; Enc2 = NULL; SLS = NULL; SI0 = NULL; SI1 = NULL; SFluo = NULL; MMStab = NULL; oldDeg = -100; AllInited = MotorsInited = SensorsInited = false; EncOrPM = XENC; MCAGains.clear(); MeasA = 0; OldDTh1 = 0; StatDisp = new Status(); StatTab->layout()->addWidget( StatDisp ); XAFSName = myname; XAFSKey = myname; XAFSTitle = myname; starsSV = new StarsSV2; conds = new Conditions; conds->setVersionInfo( VERSION, __DATE__, __TIME__ ); alarms = new Alarms; connect( alarms, SIGNAL( alarmOn() ), this, SLOT( alarmOn() ), Qt::UniqueConnection ); connect( alarms, SIGNAL( alarmOff() ), this, SLOT( alarmOff() ), Qt::UniqueConnection ); setupLogArea(); // ログに対する書き出しがある可能性があるので最初にイニシャライズ ReadDef( DefFileName ); remote = new AUnitRemote; connect( remote, SIGNAL( setMeasBlockF( bool ) ), MeasBlockB, SLOT( setChecked( bool ) ), Qt:: UniqueConnection ); selmc = new SelMC2( mccd ); setWindowTitle( XAFSTitle ); s = new Stars; // モータ類のイニシャライズの前に Stars の準備はしておく s->ReadStarsKeys( XAFSKey, XAFSName ); // Stars とのコネクション確立の準備 s->SetNewSVAddress( starsSV->SSVAddress() ); s->SetNewSVPort( starsSV->SSVPort() ); connect( s, SIGNAL( EvAll( SMsg ) ), this, SLOT( RcvEvAll( SMsg ) ), Qt::UniqueConnection ); TTable = new TuningTable; pmConds = new PMConditions; Initialize(); setupView(); setupCommonArea(); setupSetupArea(); // AUnit 関係の Initialize 後でないとだめ if ( SFluo != NULL ) { setupSetupSSDArea(); } else { MainTab->removeTab( MainTab->indexOf( SSDTab ) ); } setupChangerArea(); setupQXafsMode(); setupMeasArea(); setupReadDataArea(); setupScan2DArea(); setupWebView(); setupAutoSequence(); // useFixedDelta = false; connect( conds, SIGNAL( SetDXMPMC() ), this, SLOT( SetDXMPMC() ), Qt::UniqueConnection ); StatDisp->setupStatArea( &AMotors, &ASensors, starsSV, selmc, conds, pmConds ); connect( StatDisp, SIGNAL( NeedListNodes() ), this, SLOT( SendListNodes() ), Qt::UniqueConnection ); // QString msg = "XafsMsg_" + QLocale::system().name(); // NewLogMsg( msg ); NewLogMsg( QString( tr( "Mono: %1 (%2 A)" ) ) .arg( mccd[ selmc->MC() ]->getMCName() ) .arg( mccd[ selmc->MC() ]->getD() ) ); connect( s, SIGNAL( AskShowStat( QString, int ) ), this, SLOT( ShowMessageOnSBar( QString, int ) ), Qt::UniqueConnection ); connect( action_Quit, SIGNAL( triggered() ), qApp, SLOT( closeAllWindows() ), Qt::UniqueConnection ); // connect( action_SelMC, SIGNAL( triggered() ), selmc, SLOT( show() ), // Qt::UniqueConnection ); connect( selmc, SIGNAL( NewLogMsg( QString ) ), this, SLOT( NewLogMsg( QString ) ), Qt::UniqueConnection ); connect( selmc, SIGNAL( NewLatticeConstant( double ) ), u, SLOT( setD( double ) ), Qt::UniqueConnection ); // connect( action_SetSSV, SIGNAL( triggered() ), starsSV, SLOT( show() ), // Qt::UniqueConnection ); connect( starsSV, SIGNAL( SSVNewAddress( const QString & ) ), s, SLOT( SetNewSVAddress( const QString & ) ), Qt::UniqueConnection ); connect( starsSV, SIGNAL( SSVNewPort( const QString & ) ), s, SLOT( SetNewSVPort( const QString & ) ), Qt::UniqueConnection ); connect( s, SIGNAL( RecordSSVHistoryA( const QString & ) ), starsSV, SLOT( RecordSSVHistoryA( const QString & ) ), Qt::UniqueConnection ); connect( s, SIGNAL( RecordSSVHistoryP( const QString & ) ), starsSV, SLOT( RecordSSVHistoryP( const QString & ) ), Qt::UniqueConnection ); connect( starsSV, SIGNAL( AskReConnect() ), s, SLOT( ReConnect() ), Qt::UniqueConnection ); connect( s, SIGNAL( ReConnected() ), this, SLOT( InitializeUnitsAgain() ), Qt::UniqueConnection ); // connect( starsSV, SIGNAL( accepted() ), s, SLOT( ReConnect() ), // Qt::UniqueConnection ); connect( s, SIGNAL( ConnectionIsReady( void ) ), this, SLOT( Initialize( void ) ), Qt::UniqueConnection ); connect( s, SIGNAL( AnsListNodes( SMsg ) ), this, SLOT( RcvListNodes( SMsg ) ), Qt::UniqueConnection ); connect( s, SIGNAL( EvConnected( SMsg ) ), this, SLOT( SomeDrvIsConnected( SMsg ) ), Qt::UniqueConnection ); connect( s, SIGNAL( EvDisconnected( SMsg ) ), this, SLOT( SomeDrvIsDisconnected( SMsg ) ), Qt::UniqueConnection ); if ( ! isQXafsModeAvailable ) { QXafsMode->setChecked( false ); QXafsMode->setEnabled( false ); } GoTimer = new QTimer; MCATimer = new QTimer; ScanTimer = new QTimer; MonTimer = new QTimer; MeasTimer = new QTimer; MeasDarkTimer = new QTimer; connect( GoTimer, SIGNAL( timeout() ), this, SLOT( MotorMove() ), Qt::UniqueConnection ); connect( MCATimer, SIGNAL( timeout() ), this, SLOT( MCASequence() ), Qt::UniqueConnection ); connect( ScanTimer, SIGNAL( timeout() ), this, SLOT( ScanSequence() ), Qt::UniqueConnection ); connect( MonTimer, SIGNAL( timeout() ), this, SLOT( MonSequence() ), Qt::UniqueConnection ); connect( MeasTimer, SIGNAL( timeout() ), this, SLOT( MeasSequence() ), Qt::UniqueConnection ); connect( MeasDarkTimer, SIGNAL( timeout() ), this, SLOT( MeasDarkSequence() ), Qt::UniqueConnection ); connect( s, SIGNAL( SSisActive( bool ) ), StatDisp, SLOT( SetSSVStat( bool ) ), Qt::UniqueConnection ); connect( AddNewDTh1TPoint, SIGNAL( clicked() ), this, SLOT( AddNewDTh1TunePoint() ), Qt::UniqueConnection ); connect( conds, SIGNAL( AskToSaveDTh1TTable() ), TTable, SLOT( SaveTuneTable() ), Qt::UniqueConnection ); connect( conds, SIGNAL( AskToShowDTh1TTable() ), TTable, SLOT( ShowTuneTable() ), Qt::UniqueConnection ); connect( conds, SIGNAL( NewDiff1( int ) ), this, SIGNAL( NewDiff1( int ) ), Qt::UniqueConnection ); connect( conds, SIGNAL( NewDiff2( int ) ), this, SIGNAL( NewDiff2( int ) ), Qt::UniqueConnection ); connect( Special, SIGNAL( clicked() ), this, SLOT( SpecialMove() ) ); conds->setupDataRoot(); // 他のファイルダイアログが全部 new されていないとダメ ! s->AskStatus(); s->MakeConnection(); }