void BountyMissionObjectiveImplementation::updateWaypoint() {
	Locker locker(&syncMutex);

	ManagedReference<MissionObject* > mission = this->mission.get();

	WaypointObject* waypoint = mission->getWaypointToMission();

	if (waypoint == NULL) {
		Locker mlocker(mission);
		waypoint = mission->createWaypoint();
	}

	Locker wplocker(waypoint);

	waypoint->setPlanetCRC(getTargetZoneName().hashCode());
	Vector3 position = getTargetPosition();
	waypoint->setPosition(position.getX(), 0, position.getY());
	waypoint->setActive(true);

	mission->updateMissionLocation();

	if (mission->getMissionLevel() == 1) {
		getPlayerOwner().get()->sendSystemMessage("@mission/mission_bounty_informant:target_location_received"); // Target Waypoint Received.
	}
}
Exemplo n.º 2
0
void setUtc(uavcan::UtcTime time)
{
    MutexLocker mlocker(mutex);
    UAVCAN_ASSERT(initialized);

    {
        CriticalSectionLocker locker;
        time_utc = time.toUSec();
    }

    utc_set = true;
    utc_locked = false;
    utc_jump_cnt++;
    utc_prev_adj = 0;
    utc_rel_rate_ppm = 0;
}
Exemplo n.º 3
0
/*!
 * \brief Starts PGE Engine with current configuration package selected
 */
void MainWindow::on_action_Start_Engine_triggered()
{
    QString command = ApplicationPath + QStringLiteral("/") + PGE_ENGINE_EXE;

    QMutexLocker mlocker(&engine_mutex);
    Q_UNUSED(mlocker);

    if(!findEngine(this, command))
        return;

    QStringList args;
    args << "--config=\"" + configs.config_dir + "\"";

    QProcess::startDetached(command, args);

    //Stop music playback in the PGE Editor!
    setMusicButton(false);
    on_actionPlayMusic_triggered(false);

}
void EntertainerMissionObjectiveImplementation::activate() {
	Locker _lock(_this.getReferenceUnsafeStaticCast());

	ManagedReference<MissionObject* > mission = this->mission.get();

	MissionObjectiveImplementation::activate();

	if (hasObservers()) {
		return;
	}

	if (mission == NULL)
		return;

	ManagedReference<ZoneServer*> zoneServer = Core::lookupObject<ZoneServer>("ZoneServer");

	if (locationActiveArea == NULL) {
		locationActiveArea = ( zoneServer->createObject(STRING_HASHCODE("object/active_area.iff"), 1)).castTo<ActiveArea*>();
	}

	if (!locationActiveArea->isInQuadTree()) {
		String planetName = mission->getStartPlanet();

		Zone* zone = zoneServer->getZone(planetName);

		Locker locker(locationActiveArea);

		locationActiveArea->initializePosition(mission->getStartPositionX(), 0, mission->getStartPositionY());
		locationActiveArea->setRadius(32.f);

		if (zone != NULL) {
			zone->transferObject(locationActiveArea, -1, true);
		} else {
			error("Failed to insert entertainer location to zone.");
			abort();
			return;
		}
	}

	Locker locationLocker(locationActiveArea);

	ManagedReference<MissionObserver*> observer1 = new MissionObserver(_this.getReferenceUnsafeStaticCast());
	addObserver(observer1, true);
	locationActiveArea->registerObserver(ObserverEventType::ENTEREDAREA, observer1);

	ManagedReference<MissionObserver*> observer2 = new MissionObserver(_this.getReferenceUnsafeStaticCast());
	addObserver(observer2, true);
	locationActiveArea->registerObserver(ObserverEventType::EXITEDAREA, observer2);

	locationLocker.release();

	WaypointObject* waypoint = mission->getWaypointToMission();

	if (waypoint == NULL) {
		Locker mlocker(mission);
		waypoint = mission->createWaypoint();
	}

	Locker wplocker(waypoint);

	waypoint->setPlanetCRC(mission->getStartPlanetCRC());
	waypoint->setPosition(mission->getStartPositionX(), 0, mission->getStartPositionY());
	waypoint->setActive(true);

	mission->updateMissionLocation();
}
Exemplo n.º 5
0
RoboCompLaser::TLaserData HokuyoHandler::getNewData()
{
	QMutexLocker mlocker(&laserMutex);
	
	return wdataR;
}
Exemplo n.º 6
0
void setUtcSyncParams(const UtcSyncParams& params)
{
    MutexLocker mlocker(mutex);
    // Add some sanity check
    utc_sync_params = params;
}
Exemplo n.º 7
0
UtcSyncParams getUtcSyncParams()
{
    MutexLocker mlocker(mutex);
    return utc_sync_params;
}
Exemplo n.º 8
0
bool isUtcLocked()
{
    MutexLocker mlocker(mutex);
    return utc_locked;
}
Exemplo n.º 9
0
uavcan::uint32_t getUtcJumpCount()
{
    MutexLocker mlocker(mutex);
    return utc_jump_cnt;
}
Exemplo n.º 10
0
float getUtcRateCorrectionPPM()
{
    MutexLocker mlocker(mutex);
    const float rate_correction_mult = float(utc_correction_nsec_per_overflow) / float(USecPerOverflow * 1000);
    return 1e6F * rate_correction_mult;
}
Exemplo n.º 11
0
uavcan::MonotonicTime getMonotonic()
{
    uavcan::uint64_t usec = 0;
    // Scope Critical section
    {
        CriticalSectionLocker locker;

        volatile uavcan::uint64_t time = time_mono;

# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL

        volatile uavcan::uint32_t cnt = TIMX->CNT;
        if (TIMX->SR & TIM_SR_UIF)
        {
            cnt = TIMX->CNT;
# endif

# if UAVCAN_STM32_NUTTX

        volatile uavcan::uint32_t cnt = getreg16(TMR_REG(STM32_BTIM_CNT_OFFSET));

        if (getreg16(TMR_REG(STM32_BTIM_SR_OFFSET)) & BTIM_SR_UIF)
        {
            cnt = getreg16(TMR_REG(STM32_BTIM_CNT_OFFSET));
# endif
            time += USecPerOverflow;
        }
        usec = time + cnt;

# ifndef NDEBUG
    static uavcan::uint64_t prev_usec = 0;      // Self-test
    UAVCAN_ASSERT(prev_usec <= usec);
    (void)prev_usec;
    prev_usec = usec;
# endif
   } // End Scope Critical section

   return uavcan::MonotonicTime::fromUSec(usec);
}

uavcan::UtcTime getUtc()
{
    if (utc_set)
    {
        uavcan::uint64_t usec = 0;
        {
            CriticalSectionLocker locker;
            usec = sampleUtcFromCriticalSection();
        }
        return uavcan::UtcTime::fromUSec(usec);
    }
    return uavcan::UtcTime();
}

static float lowpass(float xold, float xnew, float corner, float dt)
{
    const float tau = 1.F / corner;
    return (dt * xnew + tau * xold) / (dt + tau);
}

static void updateRatePID(uavcan::UtcDuration adjustment)
{
    const uavcan::MonotonicTime ts = getMonotonic();
    const float dt = float((ts - prev_utc_adj_at).toUSec()) / 1e6F;
    prev_utc_adj_at = ts;
    const float adj_usec = float(adjustment.toUSec());

    /*
     * Target relative rate in PPM
     * Positive to go faster
     */
    const float target_rel_rate_ppm = adj_usec * utc_sync_params.offset_p;

    /*
     * Current relative rate in PPM
     * Positive if the local clock is faster
     */
    const float new_rel_rate_ppm = (utc_prev_adj - adj_usec) / dt; // rate error in [usec/sec], which is PPM
    utc_prev_adj = adj_usec;
    utc_rel_rate_ppm = lowpass(utc_rel_rate_ppm, new_rel_rate_ppm, utc_sync_params.rate_error_corner_freq, dt);

    const float rel_rate_error = target_rel_rate_ppm - utc_rel_rate_ppm;

    if (dt > 10)
    {
        utc_rel_rate_error_integral = 0;
    }
    else
    {
        utc_rel_rate_error_integral += rel_rate_error * dt * utc_sync_params.rate_i;
        utc_rel_rate_error_integral =
            uavcan::max(utc_rel_rate_error_integral, -utc_sync_params.max_rate_correction_ppm);
        utc_rel_rate_error_integral =
            uavcan::min(utc_rel_rate_error_integral, utc_sync_params.max_rate_correction_ppm);
    }

    /*
     * Rate controller
     */
    float total_rate_correction_ppm = rel_rate_error + utc_rel_rate_error_integral;
    total_rate_correction_ppm = uavcan::max(total_rate_correction_ppm, -utc_sync_params.max_rate_correction_ppm);
    total_rate_correction_ppm = uavcan::min(total_rate_correction_ppm, utc_sync_params.max_rate_correction_ppm);

    utc_correction_nsec_per_overflow = uavcan::int32_t((USecPerOverflow * 1000) * (total_rate_correction_ppm / 1e6F));

//    lowsyslog("$ adj=%f   rel_rate=%f   rel_rate_eint=%f   tgt_rel_rate=%f   ppm=%f\n",
//              adj_usec, utc_rel_rate_ppm, utc_rel_rate_error_integral, target_rel_rate_ppm,
// total_rate_correction_ppm);
}

void adjustUtc(uavcan::UtcDuration adjustment)
{
    MutexLocker mlocker(mutex);
    UAVCAN_ASSERT(initialized);

    if (adjustment.getAbs() > utc_sync_params.min_jump || !utc_set)
    {
        const uavcan::int64_t adj_usec = adjustment.toUSec();

        {
            CriticalSectionLocker locker;
            if ((adj_usec < 0) && uavcan::uint64_t(-adj_usec) > time_utc)
            {
                time_utc = 1;
            }
            else
            {
                time_utc = uavcan::uint64_t(uavcan::int64_t(time_utc) + adj_usec);
            }
        }

        utc_set = true;
        utc_locked = false;
        utc_jump_cnt++;
        utc_prev_adj = 0;
        utc_rel_rate_ppm = 0;
    }
    else
    {
        updateRatePID(adjustment);

        if (!utc_locked)
        {
            utc_locked =
                (std::abs(utc_rel_rate_ppm) < utc_sync_params.lock_thres_rate_ppm) &&
                (std::abs(utc_prev_adj) < utc_sync_params.lock_thres_offset.toUSec());
        }
    }
}
Exemplo n.º 12
0
/*!
 * \brief Starts level testing in PGE Engine without interprocess communication (File saving is needed)
 */
void MainWindow::on_action_doSafeTest_triggered()
{
    pge_engine_alphatestingNotify(this);

    QString command = ApplicationPath + QStringLiteral("/") + PGE_ENGINE_EXE;

    QMutexLocker mlocker(&engine_mutex);
    Q_UNUSED(mlocker);

    if(!findEngine(this, command))
        return;

    if(engine_proc.state() == QProcess::Running)
    {
        if(QMessageBox::warning(this, tr("Engine already runned"),
                                tr("Engine is already testing another level.\n"
                                   "Do you want to abort current testing process?"),
                                QMessageBox::Abort | QMessageBox::Cancel) == QMessageBox::Abort)
        {
            engine_proc.terminate();
            engine_proc.close();
        }
        return;
    }

    QStringList args;
    args << "--debug";
    args << "--config=\"" + configs.config_dir + "\"";

    SETTINGS_TestSettings t = GlobalSettings::testing;
    args << QString("--num-players=%1").arg(t.numOfPlayers);
    args << QString("--p1c=%1").arg(t.p1_char);
    args << QString("--p1s=%1").arg(t.p1_state);
    args << QString("--p2c=%1").arg(t.p2_char);
    args << QString("--p2s=%1").arg(t.p2_state);
    if(t.xtra_chuck) args << "--debug-chucknorris";
    if(t.xtra_god) args << "--debug-pagan-god";
    if(t.xtra_flyup) args << "--debug-superman";
    if(t.xtra_worldfreedom) args << "--debug-worldfreedom";
    if(t.xtra_physdebug) args << "--debug-physics";
    if(t.xtra_debug)
        args << "--debug-print=yes";
    else
        args << "--debug-print=no";

    if(activeChildWindow() == WND_Level)
    {
        LevelEdit *le = activeLvlEditWin();
        if(le->isUntitled())
        {
            QMessageBox::warning(this, tr("Save file first"),
                                 tr("To run testing of saved file, please save them into disk first!\n"
                                    "You can run testing without saving of file if you will use \"Run testing\" menu item."),
                                 QMessageBox::Ok);
            return;
        }
        args << le->curFile;
    }
    else if(activeChildWindow() == WND_World)
    {
        WorldEdit *we = activeWldEditWin();
        if(we->isUntitled())
        {
            QMessageBox::warning(this, tr("Save file first"),
                                 tr("To run testing of saved file, please save them into disk first!\n"
                                    "You can run testing without saving of file if you will use \"Run testing\" menu item."),
                                 QMessageBox::Ok);
            return;
        }
        args << we->curFile;
    }

    engine_proc.start(command, args);
    if(engine_proc.waitForStarted())
    {
        //Stop music playback in the PGE Editor!
        stopMusicForTesting();
    }

}
Exemplo n.º 13
0
/*!
 * \brief Starts level testing in PGE Engine with interprocess communication (File saving is not needed)
 */
void MainWindow::on_action_doTest_triggered()
{
    pge_engine_alphatestingNotify(this);

    QString command;

    QMutexLocker mlocker(&engine_mutex);
    Q_UNUSED(mlocker);

    if(!findEngine(this, command))
        return;

    if(engine_proc.state() == QProcess::Running)
    {
        if(QMessageBox::warning(this, tr("Engine already runned"),
                                tr("Engine is already testing another level.\n"
                                   "Do you want to abort current testing process?"),
                                QMessageBox::Abort | QMessageBox::Cancel) == QMessageBox::Abort)
        {
            engine_proc.terminate();
            engine_proc.close();
        }
        return;
    }

    if(activeChildWindow() == WND_Level)
    {
        IntEngine::init(&engine_proc);

        //if(activeLvlEditWin()->isUntitled) return;
        LevelEdit *edit = activeLvlEditWin();
        if(!edit) return;

        QStringList args;
        args << "--debug";
        args << "--config=\"" + configs.config_dir + "\"";
        args << "--interprocessing";//activeLvlEditWin()->curFile;
        SETTINGS_TestSettings t = GlobalSettings::testing;
        args << QString("--num-players=%1").arg(t.numOfPlayers);
        args << QString("--p1c=%1").arg(t.p1_char);
        args << QString("--p1s=%1").arg(t.p1_state);
        args << QString("--p2c=%1").arg(t.p2_char);
        args << QString("--p2s=%1").arg(t.p2_state);
        if(t.xtra_chuck) args << "--debug-chucknorris";
        if(t.xtra_god) args << "--debug-pagan-god";
        if(t.xtra_flyup) args << "--debug-superman";
        if(t.xtra_worldfreedom) args << "--debug-worldfreedom";
        if(t.xtra_physdebug) args << "--debug-physics";
        if(t.xtra_debug)
            args << "--debug-print=yes";
        else
            args << "--debug-print=no";

        edit->prepareLevelFile(edit->LvlData);
        IntEngine::setTestLvlBuffer(edit->LvlData);

        qDebug() << "Executing engine..." << command;
        engine_proc.start(command, args);
        if(engine_proc.waitForStarted())
        {
            qDebug() << "Started";
            //Stop music playback in the PGE Editor!
            stopMusicForTesting();
        }
        else
            qWarning() << "Failed to start PGE Engine!" << command << "with args" << args;

    }
    else
        return;
}