ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent) { m_config = new Ui_InputWidget(); m_config->setupUi(this); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); // First of all, put all the channel widgets into lists, so that we can // manipulate those: inMaxLabels << m_config->ch0Max << m_config->ch1Max << m_config->ch2Max << m_config->ch3Max << m_config->ch4Max << m_config->ch5Max << m_config->ch6Max << m_config->ch7Max; inMinLabels << m_config->ch0Min << m_config->ch1Min << m_config->ch2Min << m_config->ch3Min << m_config->ch4Min << m_config->ch5Min << m_config->ch6Min << m_config->ch7Min; inSliders << m_config->inSlider0 << m_config->inSlider1 << m_config->inSlider2 << m_config->inSlider3 << m_config->inSlider4 << m_config->inSlider5 << m_config->inSlider6 << m_config->inSlider7; inRevCheckboxes << m_config->ch0Rev << m_config->ch1Rev << m_config->ch2Rev << m_config->ch3Rev << m_config->ch4Rev << m_config->ch5Rev << m_config->ch6Rev << m_config->ch7Rev; inChannelAssign << m_config->ch0Assign << m_config->ch1Assign << m_config->ch2Assign << m_config->ch3Assign << m_config->ch4Assign << m_config->ch5Assign << m_config->ch6Assign << m_config->ch7Assign; // Now connect the widget to the ManualControlCommand / Channel UAVObject UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ManualControlCommand"))); connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateChannels(UAVObject*))); // Register for ManualControlSettings changes: obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ManualControlSettings"))); connect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(refreshValues())); // Get the receiver types supported by OpenPilot and fill the corresponding // dropdown menu: obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ManualControlSettings"))); UAVObjectField * field; // Fill in the dropdown menus for the channel RC Input assignement. QStringList channelsList; channelsList << "None"; QList<UAVObjectField*> fieldList = obj->getFields(); foreach (UAVObjectField* field, fieldList) { if (field->getUnits().contains("channel")) { channelsList.append(field->getName()); } } m_config->ch0Assign->addItems(channelsList); m_config->ch1Assign->addItems(channelsList); m_config->ch2Assign->addItems(channelsList); m_config->ch3Assign->addItems(channelsList); m_config->ch4Assign->addItems(channelsList); m_config->ch5Assign->addItems(channelsList); m_config->ch6Assign->addItems(channelsList); m_config->ch7Assign->addItems(channelsList); // And the flight mode settings: field = obj->getField(QString("FlightModePosition")); m_config->fmsModePos1->addItems(field->getOptions()); m_config->fmsModePos2->addItems(field->getOptions()); m_config->fmsModePos3->addItems(field->getOptions()); field = obj->getField(QString("Stabilization1Settings")); channelsList.clear(); channelsList.append(field->getOptions()); m_config->fmsSsPos1Roll->addItems(channelsList); m_config->fmsSsPos1Pitch->addItems(channelsList); m_config->fmsSsPos1Yaw->addItems(channelsList); m_config->fmsSsPos2Roll->addItems(channelsList); m_config->fmsSsPos2Pitch->addItems(channelsList); m_config->fmsSsPos2Yaw->addItems(channelsList); m_config->fmsSsPos3Roll->addItems(channelsList); m_config->fmsSsPos3Pitch->addItems(channelsList); m_config->fmsSsPos3Yaw->addItems(channelsList); // And the Armin configurations: field = obj->getField(QString("Arming")); m_config->armControl->clear(); m_config->armControl->addItems(field->getOptions()); connect(m_config->saveRCInputToSD, SIGNAL(clicked()), this, SLOT(saveRCInputObject())); connect(m_config->saveRCInputToRAM, SIGNAL(clicked()), this, SLOT(sendRCInputUpdate())); enableControls(false); refreshValues(); connect(parent, SIGNAL(autopilotConnected()),this, SLOT(onAutopilotConnect())); connect(parent, SIGNAL(autopilotDisconnected()), this, SLOT(onAutopilotDisconnect())); connect(m_config->ch0Rev, SIGNAL(toggled(bool)), this, SLOT(reverseCheckboxClicked(bool))); connect(m_config->ch1Rev, SIGNAL(toggled(bool)), this, SLOT(reverseCheckboxClicked(bool))); connect(m_config->ch2Rev, SIGNAL(toggled(bool)), this, SLOT(reverseCheckboxClicked(bool))); connect(m_config->ch3Rev, SIGNAL(toggled(bool)), this, SLOT(reverseCheckboxClicked(bool))); connect(m_config->ch4Rev, SIGNAL(toggled(bool)), this, SLOT(reverseCheckboxClicked(bool))); connect(m_config->ch5Rev, SIGNAL(toggled(bool)), this, SLOT(reverseCheckboxClicked(bool))); connect(m_config->ch6Rev, SIGNAL(toggled(bool)), this, SLOT(reverseCheckboxClicked(bool))); connect(m_config->ch7Rev, SIGNAL(toggled(bool)), this, SLOT(reverseCheckboxClicked(bool))); connect(m_config->doRCInputCalibration,SIGNAL(stateChanged(int)),this,SLOT(updateTips(int))); firstUpdate = true; // Connect the help button connect(m_config->inputHelp, SIGNAL(clicked()), this, SLOT(openHelp())); updateTips(Qt::Unchecked); }
ConfigGadgetWidget::ConfigGadgetWidget(QWidget *parent) : QWidget(parent) { setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); stackWidget = new MyTabbedStackWidget(this, true, true); stackWidget->setIconSize(64); QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(stackWidget); setLayout(layout); QWidget *qwd; QIcon *icon = new QIcon(); icon->addFile(":/configgadget/images/hardware_normal.png", QSize(), QIcon::Normal, QIcon::Off); icon->addFile(":/configgadget/images/hardware_selected.png", QSize(), QIcon::Selected, QIcon::Off); qwd = new DefaultHwSettingsWidget(this); stackWidget->insertTab(ConfigGadgetWidget::hardware, qwd, *icon, QString("Hardware")); icon = new QIcon(); icon->addFile(":/configgadget/images/vehicle_normal.png", QSize(), QIcon::Normal, QIcon::Off); icon->addFile(":/configgadget/images/vehicle_selected.png", QSize(), QIcon::Selected, QIcon::Off); qwd = new ConfigVehicleTypeWidget(this); stackWidget->insertTab(ConfigGadgetWidget::aircraft, qwd, *icon, QString("Vehicle")); icon = new QIcon(); icon->addFile(":/configgadget/images/input_normal.png", QSize(), QIcon::Normal, QIcon::Off); icon->addFile(":/configgadget/images/input_selected.png", QSize(), QIcon::Selected, QIcon::Off); qwd = new ConfigInputWidget(this); stackWidget->insertTab(ConfigGadgetWidget::input, qwd, *icon, QString("Input")); icon = new QIcon(); icon->addFile(":/configgadget/images/output_normal.png", QSize(), QIcon::Normal, QIcon::Off); icon->addFile(":/configgadget/images/output_selected.png", QSize(), QIcon::Selected, QIcon::Off); qwd = new ConfigOutputWidget(this); stackWidget->insertTab(ConfigGadgetWidget::output, qwd, *icon, QString("Output")); icon = new QIcon(); icon->addFile(":/configgadget/images/ins_normal.png", QSize(), QIcon::Normal, QIcon::Off); icon->addFile(":/configgadget/images/ins_selected.png", QSize(), QIcon::Selected, QIcon::Off); qwd = new DefaultAttitudeWidget(this); stackWidget->insertTab(ConfigGadgetWidget::sensors, qwd, *icon, QString("Attitude")); icon = new QIcon(); icon->addFile(":/configgadget/images/stabilization_normal.png", QSize(), QIcon::Normal, QIcon::Off); icon->addFile(":/configgadget/images/stabilization_selected.png", QSize(), QIcon::Selected, QIcon::Off); qwd = new ConfigStabilizationWidget(this); stackWidget->insertTab(ConfigGadgetWidget::stabilization, qwd, *icon, QString("Stabilization")); icon = new QIcon(); icon->addFile(":/configgadget/images/camstab_normal.png", QSize(), QIcon::Normal, QIcon::Off); icon->addFile(":/configgadget/images/camstab_selected.png", QSize(), QIcon::Selected, QIcon::Off); qwd = new ConfigCameraStabilizationWidget(this); stackWidget->insertTab(ConfigGadgetWidget::camerastabilization, qwd, *icon, QString("Gimbal")); icon = new QIcon(); icon->addFile(":/configgadget/images/txpid_normal.png", QSize(), QIcon::Normal, QIcon::Off); icon->addFile(":/configgadget/images/txpid_selected.png", QSize(), QIcon::Selected, QIcon::Off); qwd = new ConfigTxPIDWidget(this); stackWidget->insertTab(ConfigGadgetWidget::txpid, qwd, *icon, QString("TxPID")); stackWidget->setCurrentIndex(ConfigGadgetWidget::hardware); // Listen to autopilot connection events ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); TelemetryManager *telMngr = pm->getObject<TelemetryManager>(); connect(telMngr, SIGNAL(connected()), this, SLOT(onAutopilotConnect())); connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect())); // And check whether by any chance we are not already connected if (telMngr->isConnected()) { onAutopilotConnect(); } help = 0; connect(stackWidget, SIGNAL(currentAboutToShow(int, bool *)), this, SLOT(tabAboutToChange(int, bool *))); // Connect to the OPLinkStatus object updates UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); oplinkStatusObj = dynamic_cast<UAVDataObject *>(objManager->getObject("OPLinkStatus")); if (oplinkStatusObj != NULL) { connect(oplinkStatusObj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(updateOPLinkStatus(UAVObject *))); } else {
void HITLWidget::startButtonClicked() { QThread* mainThread = QThread::currentThread(); qDebug() << "Main Thread: "<< mainThread; // [1] // if(Simulator::IsStarted()) // { // widget->textBrowser->append("HITL alreary started!"); // return; // } // Simulator::setStarted(true); // [2] allow only one instance per simulator if(Simulator::Instances().indexOf(settings.simulatorId) != -1) { widget->textBrowser->append(settings.simulatorId + " alreary started!"); return; } if(!HITLPlugin::typeSimulators.size()) { qxtLog->info("There is no registered simulators, add through HITLPlugin::addSimulator"); return; } // Stop running process if one is active if(simulator) { QMetaObject::invokeMethod(simulator, "onDeleteSimulator",Qt::QueuedConnection); simulator = NULL; } //fgBridge = new FlightGearBridge(); //simulator = new Simulator(); if(settings.hostAddress == "" || settings.inPort == 0) { widget->textBrowser->append("Before start, set UDP parameters in options page!"); return; } SimulatorCreator* creator = HITLPlugin::getSimulatorCreator(settings.simulatorId); simulator = creator->createSimulator(settings);//hostName, outPort, inPort, manualControl, pathBin, pathData); // move to thread simulator->setName(creator->Description()); simulator->setSimulatorId(creator->ClassId()); // Setup process widget->textBrowser->append(QString("[%1] Starting %2... ").arg(QTime::currentTime().toString("hh:mm:ss")).arg(creator->Description())); qxtLog->info("HITL: Starting " + creator->Description()); // Start bridge //bool ret = simulator->setupProcess(); bool ret = QMetaObject::invokeMethod(simulator, "setupProcess",Qt::QueuedConnection); if(ret) { Simulator::setInstance(settings.simulatorId); connect(this,SIGNAL(deleteSimulator()),simulator, SLOT(onDeleteSimulator()),Qt::QueuedConnection); widget->startButton->setEnabled(false); widget->stopButton->setEnabled(true); qxtLog->info("HITL: Starting bridge, initializing flight simulator and Autopilot connections"); connect(simulator, SIGNAL(processOutput(QString)), widget->textBrowser, SLOT(append(QString))); connect(simulator, SIGNAL(autopilotConnected()), this, SLOT(onAutopilotConnect()),Qt::QueuedConnection); connect(simulator, SIGNAL(autopilotDisconnected()), this, SLOT(onAutopilotDisconnect()),Qt::QueuedConnection); connect(simulator, SIGNAL(simulatorConnected()), this, SLOT(onSimulatorConnect()),Qt::QueuedConnection); connect(simulator, SIGNAL(simulatorDisconnected()), this, SLOT(onSimulatorDisconnect()),Qt::QueuedConnection); // Initialize connection status if ( simulator->isAutopilotConnected() ) { onAutopilotConnect(); } else { onAutopilotDisconnect(); } if ( simulator->isSimulatorConnected() ) { onSimulatorConnect(); } else { onSimulatorDisconnect(); } } }
void MoCapWidget::startButtonClicked() { QThread* mainThread = QThread::currentThread(); qDebug() << "Main Thread: "<< mainThread; //Allow only one instance per exporter if(Exporter::Instances().indexOf(settings.exporterId) != -1) { widget->textBrowser->append(settings.exporterId + " alreary started!"); return; } if(!MoCapPlugin::typeMocaps.size()) { qxtLog->info("There is no registered exporters, add through MoCapPlugin::addExporter"); return; } // Stop running process if one is active if(exporter) { QMetaObject::invokeMethod(exporter, "onDeleteExporter",Qt::QueuedConnection); exporter = NULL; } if(settings.hostAddress == "" || settings.inPort == 0) { widget->textBrowser->append("Before start, set UDP parameters in options page!"); return; } MocapCreator* creator = MoCapPlugin::getMocapCreator(settings.exporterId); exporter = creator->createExporter(settings, widget); // move to thread <--[BCH] exporter->setName(creator->Description()); exporter->setExporterId(creator->ClassId()); connect(exporter, SIGNAL(processOutput(QString)), this, SLOT(onProcessOutput(QString))); // Setup process widget->textBrowser->append(QString("[%1] Starting %2... ").arg(QTime::currentTime().toString("hh:mm:ss")).arg(creator->Description())); qxtLog->info("MoCap: Starting " + creator->Description()); // Start bridge bool ret = QMetaObject::invokeMethod(exporter, "setupProcess",Qt::QueuedConnection); if(ret) { Exporter::setInstance(settings.exporterId); connect(this,SIGNAL(deleteExporter()),exporter, SLOT(onDeleteExporter()),Qt::QueuedConnection); widget->startButton->setEnabled(false); widget->stopButton->setEnabled(true); qxtLog->info("MoCap: Starting bridge, initializing flight exporter and Autopilot connections"); connect(exporter, SIGNAL(autopilotConnected()), this, SLOT(onAutopilotConnect()),Qt::QueuedConnection); connect(exporter, SIGNAL(autopilotDisconnected()), this, SLOT(onAutopilotDisconnect()),Qt::QueuedConnection); connect(exporter, SIGNAL(exporterConnected()), this, SLOT(onExporterConnect()),Qt::QueuedConnection); connect(exporter, SIGNAL(exporterDisconnected()), this, SLOT(onExporterDisconnect()),Qt::QueuedConnection); connect(widget->trackablesComboBox, SIGNAL( currentIndexChanged(int)), this, SLOT(ontrackablesComboBox_changed())); // Initialize connection status if ( exporter->isAutopilotConnected() ) { onAutopilotConnect(); } else { onAutopilotDisconnect(); } if ( exporter->isExporterConnected() ) { onExporterConnect(); } else { onExporterDisconnect(); } } }
void Simulator::onStart() { QMutexLocker locker(&lock); QThread* mainThread = QThread::currentThread(); qDebug() << "Simulator Thread: "<< mainThread; // Get required UAVObjects ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager* objManager = pm->getObject<UAVObjectManager>(); actDesired = ActuatorDesired::GetInstance(objManager); actCommand = ActuatorCommand::GetInstance(objManager); manCtrlCommand = ManualControlCommand::GetInstance(objManager); gcsReceiver = GCSReceiver::GetInstance(objManager); flightStatus = FlightStatus::GetInstance(objManager); posHome = HomeLocation::GetInstance(objManager); velActual = VelocityActual::GetInstance(objManager); posActual = PositionActual::GetInstance(objManager); baroAlt = BaroAltitude::GetInstance(objManager); airspeedActual = AirspeedActual::GetInstance(objManager); attActual = AttitudeActual::GetInstance(objManager); attitudeSettings = AttitudeSettings::GetInstance(objManager); accels = Accels::GetInstance(objManager); gyros = Gyros::GetInstance(objManager); gpsPos = GPSPosition::GetInstance(objManager); gpsVel = GPSVelocity::GetInstance(objManager); telStats = GCSTelemetryStats::GetInstance(objManager); groundTruth = GroundTruth::GetInstance(objManager); // Listen to autopilot connection events TelemetryManager* telMngr = pm->getObject<TelemetryManager>(); connect(telMngr, SIGNAL(connected()), this, SLOT(onAutopilotConnect())); connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect())); //connect(telStats, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(telStatsUpdated(UAVObject*))); // If already connect setup autopilot GCSTelemetryStats::DataFields stats = telStats->getData(); if ( stats.Status == GCSTelemetryStats::STATUS_CONNECTED ) onAutopilotConnect(); inSocket = new QUdpSocket(); outSocket = new QUdpSocket(); setupUdpPorts(settings.hostAddress,settings.inPort,settings.outPort); emit processOutput("\nLocal interface: " + settings.hostAddress + "\n" + \ "Remote interface: " + settings.remoteAddress + "\n" + \ "inputPort: " + QString::number(settings.inPort) + "\n" + \ "outputPort: " + QString::number(settings.outPort) + "\n"); qxtLog->info("\nLocal interface: " + settings.hostAddress + "\n" + \ "Remote interface: " + settings.remoteAddress + "\n" + \ "inputPort: " + QString::number(settings.inPort) + "\n" + \ "outputPort: " + QString::number(settings.outPort) + "\n"); connect(inSocket, SIGNAL(readyRead()), this, SLOT(receiveUpdate()),Qt::DirectConnection); // Setup transmit timer txTimer = new QTimer(); connect(txTimer, SIGNAL(timeout()), this, SLOT(transmitUpdate()),Qt::DirectConnection); txTimer->setInterval(updatePeriod); txTimer->start(); // Setup simulator connection timer simTimer = new QTimer(); connect(simTimer, SIGNAL(timeout()), this, SLOT(onSimulatorConnectionTimeout()),Qt::DirectConnection); simTimer->setInterval(simTimeout); simTimer->start(); // setup time time = new QTime(); time->start(); current.T=0; current.i=0; }