예제 #1
0
void Mobile::simulate( ftype dt )
{
    //world perception
    simSensors( dt );
    //simulate AI of the bot
    simBrain( dt );
    //simulate movement
    pos += speed*dt;
    rot.add( dt*rotationSpeed );
    applyLimits();
    //Simulate forces
    simMotors( dt );
    //friction
    simFriction( dt );

	//food eating behavior
    if (foodEatingTicker.step( dt ))
	tryEatFood();
    
    energy -= world->getIdleEnergyConsumptionRate()*dt;
    if (energy <= 0){//Bot is dead.
	world->reportDeadBot( *this );
    }

}
예제 #2
0
void Dribbler::step(float dt) {
	Wheel::step(dt);

	double delayStopPeriod = 0.1;

	if (stopRequestedTime != -1.0 && Util::duration(stopRequestedTime) >= delayStopPeriod) {
		setTargetOmega(0);
		//setTargetOmega(-Config::robotDribblerSpeed / 5);

		stopRequestedTime = -1.0;
	}

	if (ballDetected) {
		ballInDribblerTime += dt;

		if (ballInDribblerTime >= Config::ballInDribblerThreshold) {
			ballLostTime = -1.0f;
		}
	} else {
		if (everDetectedBall) {
			if (ballLostTime == -1.0f) {
				ballLostTime = dt;
			} else {
				ballLostTime += dt;
			}
		}

		if (ballLostTime >= Config::dribblerBallLostThreshold) {
			ballInDribblerTime = 0.0f;
		}
	}

	if (isRaiseRequested) {
		timeSinceRaised += dt;
		timeSinceLowered = 0.0f;
	} else {
		timeSinceLowered += dt;
		timeSinceRaised = 0.0f;
	}

	// apply limits just in case periodically
	if (timeSinceLimitsApplied > 1.0f) {
		applyLimits();
	}

	timeSinceLimitsApplied += dt;

	useChipKickLimitsMissedFrames++;

	/*if (useChipKickLimitsMissedFrames >= 2) {
		useNormalLimits();
	}*/

	//std::cout << "ballInDribblerTime: " << ballInDribblerTime << ", ballLostTime: " << ballLostTime << ", got ball: " << (gotBall() ? "yes" : "no") << std::endl;
}
예제 #3
0
Dribbler::Dribbler(int id, AbstractCommunication* com, Coilgun* coilgun, Configuration* conf) : Wheel(id, 10000, conf->robot.wheelSpeedToMetric), com(com), coilgun(coilgun), conf(conf), ballDetected(false), everDetectedBall(false), isRaiseRequested(false), timeSinceRaised(0.0f), timeSinceLowered(0.0f), timeSinceLimitsApplied(0.0f), ballInDribblerTime(0.0), ballLostTime(-1.0f), stopRequestedTime(-1.0), useChipKickLimitsMissedFrames(0) {
	lowerLimit = conf->robot.dribblerNormalLowerLimit;
	upperLimit = conf->robot.dribblerNormalUpperLimit;
	applyLimits();
};
예제 #4
0
void Dribbler::setLimits(int lower, int upper) {
	lowerLimit = (int)Util::limit((float)lower, 0.0f, 100.0f);
	upperLimit = (int)Util::limit((float)upper, 0.0f, 100.0f);

	applyLimits();
}
예제 #5
0
void Dribbler::setUpperLimit(int limit) {
	upperLimit = (int)Util::limit((float)limit, 0.0f, 100.0f);

	applyLimits();
}
예제 #6
0
static int execute_cgi(lscgid_t *pCGI)
{
    char ch;
    if (setpriority(PRIO_PROCESS, 0, pCGI->m_data.m_priority))
        perror("lscgid: setpriority()");
    applyLimits(&pCGI->m_data);

#ifdef HAS_CLOUD_LINUX

#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
    if (s_lve && pCGI->m_data.m_uid)   //root user should not do that
    {
        uint32_t cookie;
        int ret = -1;
        int count;
        //for( count = 0; count < 10; ++count )
        {
            ret = (*fp_lve_enter)(s_lve, pCGI->m_data.m_uid, -1, -1, &cookie);
            //if ( !ret )
            //    break;
            //usleep( 10000 );
        }
        if (ret < 0)
        {
            fprintf(stderr, "lscgid (%d): enter LVE (%d) : result: %d !\n", getpid(),
                    pCGI->m_data.m_uid, ret);
            set_cgi_error("lscgid: lve_enter() failure, reached resource limit.",
                          NULL);
            return 500;
        }
    }
#endif

#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
    if (!s_uid && pCGI->m_data.m_uid && fp_lve_jail)
    {
        char  error_msg[1024] = "";
        int ret;
        struct passwd *pw = getpwuid(pCGI->m_data.m_uid);
        if (pw)
        {
            ret = (*fp_lve_jail)(pw, error_msg);
            if (ret < 0)
            {
                fprintf(stderr, "lscgid (%d): LVE jail(%d) ressult: %d, error: %s !\n",
                        getpid(), pCGI->m_data.m_uid, ret, error_msg);
                set_cgi_error("lscgid: jail() failure.", NULL);
                return 500;
            }
        }
    }
#endif

#endif

    if ((!s_uid) && (pCGI->m_data.m_uid || pCGI->m_data.m_gid))
    {
        if (setUIDs(pCGI->m_data.m_uid, pCGI->m_data.m_gid,
                    pCGI->m_pChroot) == -1)
            return 403;
    }
    ch = *(pCGI->m_argv[0]);
    * pCGI->m_argv[0] = 0;
    if (chdir(pCGI->m_pCGIDir) == -1)
    {
        int error = errno;
        set_cgi_error((char *)"lscgid: chdir()", pCGI->m_pCGIDir);
        switch (error)
        {
        case ENOENT:
            return 404;
        case EACCES:
            return 403;
        default:
            return 500;
        }
    }
    *(pCGI->m_argv[0]) = ch;
    if (ch == '&')
    {
        static const char sHeader[] = "Status: 200\r\n\r\n";
        writeall(STDOUT_FILENO, sHeader, sizeof(sHeader) - 1);
        pCGI->m_pCGIDir = (char *)"/bin/sh";
        pCGI->m_argv[0] = (char *)"/bin/sh";
    }
    else
    {
        //pCGI->m_argv[0] = strdup( pCGI->m_pCGIDir );
        pCGI->m_argv[0] = pCGI->m_pCGIDir;
    }

    umask(pCGI->m_data.m_umask);
    //fprintf( stderr, "execute_cgi m_umask=%03o\n", pCGI->m_data.m_umask );
    if (execve(pCGI->m_pCGIDir, pCGI->m_argv, pCGI->m_env) == -1)
    {
        set_cgi_error((char *)"lscgid: execve()", pCGI->m_pCGIDir);
        return 500;
    }

    return 0;
}