コード例 #1
0
ファイル: Square.cpp プロジェクト: mattprintz/wx-xword
Square * Square::GetSolutionWordStart(GridDirection dir)
{
    return FindSolutionWordBoundary(this, (GridDirection)InvertDirection(dir));
}
コード例 #2
0
void StepperMotor::PerformStep(MotorDirection Direction)
{
	//full step sequence. maximum torque
	const unsigned int FullStep[4][4] = { {1,0,1,0},{0,1,1,0},{0,1,0,1},{1,0,0,1} };
	//half-step sequence. double resolution. But the torque of the stepper motor is not constant
	const unsigned int HalfStep[8][4] = { {1,0,0,0},{1,0,1,0},{0,0,1,0},{0,1,1,0},{0,1,0,0},{0,1,0,1},{0,0,0,1},{1,0,0,1} };

	int TargetPhase;
	this->Direction = Direction;

	if (_IsInverted)
		InvertDirection();
	if (_Enabled)
	{
		//Record our target phase
		TargetPhase = (this->Phase + this->Direction);

		//Check if we need to reset the phase.
		if (!_IsHalfStep)
		{
			if (this->Direction == CLOCKWISE && TargetPhase > 3)
				TargetPhase = 0;
			else if (this->Direction == CTRCLOCKWISE && TargetPhase < 0)
				TargetPhase = 3;
		}
		else
		{
			if (this->Direction == CLOCKWISE && TargetPhase > 7)
				TargetPhase = 0;
			else if (this->Direction == CTRCLOCKWISE && TargetPhase < 0)
				TargetPhase = 7;

		}

		//Set coils based upon phase shift, direction,and stepping style.
		if (!_IsHalfStep)
		{
			digitalWrite(_Coil_1, FullStep[TargetPhase][0]);
			digitalWrite(_Coil_3, FullStep[TargetPhase][2]);
			if (!_IsNOTGated)
			{
				digitalWrite(_Coil_2, FullStep[TargetPhase][1]);
				digitalWrite(_Coil_4, FullStep[TargetPhase][3]);
			}
		}
		else
		{
			digitalWrite(_Coil_1, HalfStep[TargetPhase][0]);
			digitalWrite(_Coil_3, HalfStep[TargetPhase][2]);
			if (!_IsNOTGated)
			{
				digitalWrite(_Coil_2, HalfStep[TargetPhase][1]);
				digitalWrite(_Coil_4, HalfStep[TargetPhase][3]);
			}
		}

		//Update motor status.
		this->Phase = TargetPhase;
		this->Position += this->Direction;
	}
	//If we're not holding the motor position let's release it.
	if (!HoldPosition)
		CoilsOff();
}
コード例 #3
0
ファイル: Square.cpp プロジェクト: mattprintz/wx-xword
const Square * Square::GetWordStart(GridDirection dir) const 
{
    return FindWordBoundary(this, (GridDirection)InvertDirection(dir));
}
コード例 #4
0
    void JoystickEntityHandler::MoveJoystick() 
    {
        // Safir::Logging::SendSystemLog(Safir::Logging::Critical,
        //                              L"JoystickEntityHandler::MoveJoystick");
     
             Safir::Dob::EntityProxy entityProxy = m_connection.Read(m_JoystickEntity);
        Consoden::TankGame::JoystickPtr joystick = 
            boost::static_pointer_cast<Consoden::TankGame::Joystick>(entityProxy.GetEntity());

        Consoden::TankGame::Direction::Enumeration newDirection;

        // Make a random movement
        float r = random();
        r = r / RAND_MAX;

        // Since moving backwards will kill the tank, make that unprobable (1%)
        if (r < 0.01) {
            // Backwards (1%)
            newDirection = InvertDirection(m_LastDirection);
            MoveDirection(newDirection, joystick);
            m_LastDirection = newDirection;
        } else if (r < 0.41) {
            // Forward (40%)
            newDirection = m_LastDirection;
            MoveDirection(newDirection, joystick);
            m_LastDirection = newDirection;
        } else if (r < 0.61) {
            // Turn right (20%)
            newDirection = TurnRight(m_LastDirection);
            MoveDirection(newDirection, joystick);
            m_LastDirection = newDirection;
        } else if (r < 0.81) {
            // Turn left (20%)
            newDirection = TurnLeft(m_LastDirection);
            MoveDirection(newDirection, joystick);
            m_LastDirection = newDirection;
        } else {
            // Stand still (19%) 
            MoveDirection(Consoden::TankGame::Direction::Neutral, joystick);
        }

        // Set a random fire direction
        r = random();
        r = r / RAND_MAX;
        if (r < 0.25) {
            TowerDirection(Consoden::TankGame::Direction::Left, joystick);
        } else if (r < 0.50) {
            TowerDirection(Consoden::TankGame::Direction::Right, joystick);
        } else if (r < 0.75) {
            TowerDirection(Consoden::TankGame::Direction::Up, joystick);
        } else {
            TowerDirection(Consoden::TankGame::Direction::Down, joystick);
        }

        // Fire?
        r = random();
        r = r / RAND_MAX;
        if (r < 0.2) {
            // Yes! 20%
            Fire(true, joystick);
        } else {
            // No! 80%
            Fire(false, joystick);
        }

    }