Example #1
0
void Mwars::on_pbRectangle_clicked()
{
    if(rectangleIsRunning) {
        QMessageBox::critical(this, "Error", "Rectangle is already running");
        return;
    }

    workerThread = new QThread();            // instantiates ScannerDraw class and the QThread
    scannerDraw = new ScannerDraw(this, 33, 44);   // on heap

    scannerDraw->moveToThread(workerThread);
    connect(workerThread, SIGNAL(started()), scannerDraw, SLOT(drawRectangle()));

    connect(scannerDraw, SIGNAL(finished()), workerThread, SLOT(quit()), Qt::DirectConnection);
    connect(scannerDraw, SIGNAL(finished()), scannerDraw, SLOT(deleteLater()));
    connect(scannerDraw, SIGNAL(finished()), workerThread, SLOT(deleteLater()));

    connect(workerThread, SIGNAL(finished()), this, SLOT(rectangleFinished()));

    connect(ui->pbStopRectangle, SIGNAL(clicked()), this, SLOT(stopRectangle()));

    // need these signals cause can't call sockets across threads
    connect(scannerDraw, SIGNAL(sendScannerMssg (ushort, ushort, ushort)), this, SLOT(sendScannerMssg(ushort, ushort, ushort)));
    connect(scannerDraw, SIGNAL (laserOn()), this, SLOT(laserOn()));
    connect(scannerDraw, SIGNAL (laserOff()), this, SLOT(laserOff()));
    connect(scannerDraw, SIGNAL (scannerOn()), this, SLOT(scannerOn()));
    connect(scannerDraw, SIGNAL (scannerOff()), this, SLOT(scannerOff()));

    workerThread->start();

    rectangleIsRunning = true;
    ui->pbStopRectangle->setEnabled(true);
}
Example #2
0
int
hokuyo::Laser::stopScanning() {
  try {
    return laserOff();
  }
  catch (hokuyo::Exception &e)
  {
    // Ignore exception because we might have gotten part of a scan 
    // instead of the expected response, which shows up as a bad checksum.
    laserFlush();
  } 
  return laserOff(); // This one should work because the scan is stopped.
}
Example #3
0
//--------------------------------------------------------------------------------------
// void Mwars::laserDisableToggle(void)
//		signals:	pushButtonLaserEnableToggle(clicked)
// Enable Scanner button signal comes here
//
// This clears laser
//-------------------------------------------------------------------------------------
void Mwars::laserDisableToggle(void) {

   if (laserDisableFlag)    {     // Is disabled, clear the flag

      ui->labelLaser_3->setText("ENABLED");
      ui->pushButtonLaserDisableToggle->setStyleSheet("background-color: rgb(255, 255, 255); color: rgb(75, 75, 75)");

      // enable other buttons
      ui->pbLaserToggle->setEnabled(true);        // enable the laser button
      ui->pushButtonCameraDataToggle->setEnabled(true);
      ui->pushButtonTestDataToggle->setEnabled(true);

      laserDisableFlag = false;
      ui->notificationLabel->setText("LASER ENABLED");

      ui->pushButtonTestDataToggle->setEnabled(true);     // enable test data button
   }
   else   {                   // not disabled, turn it off, disable it
       laserOff();
       ui->pbLaserToggle->setEnabled(false);  // disable the laser button
       ui->labelLaser_3->setText("DISABLED");
       ui->pushButtonLaserDisableToggle->setStyleSheet("background-color: rgb(255, 255, 0); color: rgb(75, 75, 75)");

       disableCameraData();
       ui->pushButtonCameraDataToggle->setEnabled(false);     // and disable its button

       disableTestData();
       ui->pushButtonTestDataToggle->setEnabled(false);     // and disable its button

       laserDisableFlag = true;
       ui->notificationLabel->setText("LASER DISABLED");
    }
}
//--------------------------------------------------------------------------------------
// void Mwars::calibrateOff(void)
//--------------------------------------------------------------------------------------
void Mwars::calibrateOff(void) {

    // we come here when calibration is complete (including calib file updated)

    disableCalibrationWidgets();

   // init slider & spinbox ranges to the scanner values corresponding
   // to the camera view extents 0,0 to 640, 480 pixels
    ui->xSlider->setRange(g_xScanFOVOrigin_su, g_xScanFOVMax_su);
    ui->ySlider->setRange(g_yScanFOVOrigin_su, g_yScanFOVMax_su);

    laserOff();
    centre_scanner();
    scannerOff();

    ui->notificationLabelCal->setText("");
    calibrateFlag = false;


   /* qDebug("xOffset: %d yOffset: %d xMax: %d, yMax: %d \n"
           " xDelta: %d yDelta: %d, xScale: %d yScale: %d\n"
           " g_xCamTrim %d  g_yCamTrim %d",
        g_xScanFOVOrigin_su, g_yScanFOVOrigin_su, g_xScanFOVMax_su, g_yScanFOVMax_su,
        (g_xScanFOVMax_su-g_xScanFOVOrigin_su), (g_yScanFOVMax_su-g_yScanFOVOrigin_su),
            g_xSF_PixelToSU, g_ySF_PixelToSU, g_xCamTrim,g_yCamTrim);  */
}
Example #5
0
//--------------------------------------------------------------------------------------
// void Mwars::laserToggle(void)
//		signals:	pbLaserToggle(clicked)
// Enable Scanner button signal comes here
// Note: a toggle
//-------------------------------------------------------------------------------------
void Mwars::on_pbLaserToggle_clicked(void) {
//void Mwars::laserToggle(void) {

   if (laserOnFlag)        // Is ON; turn off scanner
      laserOff();
   else                      // Is OFF, turn on
      laserOn();
}
Example #6
0
//--------------------------------------------------------------------------------------
// void Mwars::disableCameraData(void)
//-------------------------------------------------------------------------------------
void Mwars::disableCameraData(void) {

    laserOff();
    centre_scanner();        // leave scanner centred
    scannerOff();

    ui->pushButtonCameraDataToggle->setStyleSheet("background-color: rgb(255, 255, 255); color: rgb(75, 75, 75)");
    cameraDataEnableFlag = false;
}
void Mwars::calSetLRHC(void) {

    g_xScanFOVMax_su = ui->xSpinBox->value();
    g_yScanFOVMax_su = ui->ySpinBox->value();

    scannerOff();
    laserOff();

    ui->notificationLabelCal->setText("LRHC recorded");
}
Example #8
0
//--------------------------------------------------------------------------------------
// void Mwars::enableCameraData(void)
//-------------------------------------------------------------------------------------
void Mwars::enableCameraData(void) {

    laserOff();                 // opencv data stream will turn laser on / off

    disableTestData();          // turn off test data (if on)
    calibrateOff();             //
    centre_scanner();
    scannerOn();

    // and turn on camera data
    ui->pushButtonCameraDataToggle->setStyleSheet("background-color: rgb(255, 255, 0); color: rgb(75, 75, 75)");
    cameraDataEnableFlag = true;
}
Example #9
0
//--------------------------------------------------------------------------------------
// void Mwars::resetScanner(void)
//		signals:	pushButtonresetScanner(clicked)
//--------------------------------------------------------------------------------------
void Mwars::resetScanner(void) {

    laserOff();
    serverReady = false;
    testDataEnableFlag   = false;             // turn off data stream
    cameraDataEnableFlag = false;             // turn off data stream

    centre_scanner();
    scannerOff();

    ui->pushButtonTestDataToggle->setStyleSheet("background-color: rgb(255, 255, 255); color: rgb(75, 75, 75)");
    ui->pushButtonCameraDataToggle->setStyleSheet("background-color: rgb(255, 255, 255); color: rgb(75, 75, 75)");

    sendScannerMssg(CMD_RESET, 0, 0);
    qDebug() << "Reset server cmd sent";
    }
//--------------------------------------------------------------------------------------
// void Mwars::calibrateOn(void)
//
// Enables calibation buttons. Actual calibration occurs when they are pressed
//--------------------------------------------------------------------------------------
void Mwars::calibrateOn(void) {

    laserOff();
    centre_scanner();
    scannerOff();
    disableTestData();
    disableCameraData();

    // init slider & spinbox ranges to the max extents that scanner can slew
    ui->xSlider->setRange(DAC_X_MIN, DAC_X_MAX);
    ui->ySlider->setRange(DAC_Y_MIN, DAC_Y_MAX);
    ui->xSpinBox->setRange(DAC_X_MIN, DAC_X_MAX);
    ui->ySpinBox->setRange(DAC_Y_MIN, DAC_Y_MAX);

    // centre sliders
    ui->xSlider->setValue((DAC_X_MAX-DAC_X_MIN)/2 + DAC_X_MIN);
    ui->ySlider->setValue((DAC_Y_MAX-DAC_Y_MIN)/2 + DAC_Y_MIN);

   // enable calibration buttons
    ui->pbCalSetULHC->setEnabled(true);
    ui->pbCalSetLRHC->setEnabled(true);
    ui->pbCalFullFrame->setEnabled(true);
    ui->pbCalHalfFrame->setEnabled(true);
    ui->pbCamTrimOffset->setEnabled(true);
    ui->spinboxXCamTrim->setEnabled(true);
    ui->spinboxYCamTrim->setEnabled(true);
    ui->pbCamTrimOffset->setEnabled(true);
    ui->pbCalLaserBsight->setEnabled(true);
    ui->sbXCamOffset->setEnabled(true);
    ui->sbYCamOffset->setEnabled(true);
    ui->pbCamOffset->setEnabled(true);

    ui->pbRectangle->setEnabled(true);

    ui->notificationLabelCal->setText("Ready to calibrate");
    calibrateFlag = true;
}
Example #11
0
void laserCleanup(void) {
	laserOff();
	gpio_unexport(laserPin);
}
Example #12
0
void laserToggle(void) {
	if (laserState)
		laserOff();
	else
		laserOn();
}
Example #13
0
inline static void laserInit() {
	DDRA |= _BV(PA7);
	laserOff();
}
Example #14
0
int main() {
	sei();
	timerInit();

	ledInit();
	ledOn();
	delay(100);
	ledOff();

	packet.s.nodeId = eeprom_read_byte(I2C_ADDRESS_EEPROM_LOCATION);

	SPI.begin();
	laserInit();
	adcInit();

	detectorInit();
	detectorCalibrate();

	uint8_t radioInitialised = radio.initialize(RF69_868MHZ, packet.s.nodeId, 100);
	radio.encrypt(0);
	if(radioInitialised) {
		ledOn();
		delay(1500);
		sendStatusPacket();
		ledOff();
	} else {
		ledRapidBlink(2);
	}
	
	laserOn();

	while(1) {

		if(laserTripped) {
			ledOn();
			sendStatusPacket();
			delay(10);
			while((0 == (PINB & _BV(PB1)))){
				//WAIT
			}
			sendLaserVisiblePacket();
			detectorArm();
			while(0 == (PINA & _BV(PA3))) {
				//WAIT
			}
		} else {
			ledOff();
		}

		if(laserTripped || 0 == (PINA & _BV(PA3))) {
			sendStatusPacket();
			delay(300);
			while(0 == (PINA & _BV(PA3))) {
				//WAIT
			}
			delay(300);
		}


		if(radio.receiveDone()) {
			switch((char)radio.DATA[0]) {
				case CMD_LASER_ON: laserOn(); break;
				case CMD_LASER_OFF: laserOff(); break;
				case CMD_CALIBRATE: detectorCalibrate(); break;
				case CMD_GET_STATUS: waitAndSendStatus(); break;
			}
		}

		if(isBatteryLow()) {
			laserOff();
			radio.sleep();
			while(1) {
				ledRapidBlink(10);
				delay(2000);
			}
		}
	}
}