Esempio n. 1
0
MotorDirection StepperMotor::resolveDirection(MotorDirection dir) {
	if (m_reverseDirection) {
		return reverseDirection(dir);
	}
	else {
		return dir;
	}
}
Esempio n. 2
0
void CEnemy::changeState(EnemyState newState)
{
    // reversing direction if we were not frightened or inactive
    if (_state != EnemyStateFrighten && _state != EnemyStateNone) {
        reverseDirection();
    }
    
    _state = newState;
}
Esempio n. 3
0
GameState& GameState::undo(Direction direction)
{
	lastMoveCode_ = -1;
	
	if(!canRebound() && !isBlocked())
	{
		if(currentPlayer_ == PLAYER_1)
			--turnNumber_;
		
		currentPlayer_ = otherPlayer(currentPlayer_);
	}
	
	direction = reverseDirection(direction);
	getField_(currentPosition_).setOccupied_(direction, false);
	currentPosition_ = currentPosition_.getNeighbor(direction);
	getField_(currentPosition_).setOccupied_(reverseDirection(direction), false);
	
	--moveNumber_;
	
	return *this;
}
Esempio n. 4
0
GameState& GameState::move(Direction direction)
{
	lastMoveCode_ = getMoveCode(direction);
	
	getField_(currentPosition_).setOccupied_(direction);
	currentPosition_ = currentPosition_.getNeighbor(direction);
	getField_(currentPosition_).setOccupied_(reverseDirection(direction));
	
	if(!canRebound() && !isBlocked())
	{
		currentPlayer_ = otherPlayer(currentPlayer_);
		
		if(currentPlayer_ == PLAYER_1)
			++turnNumber_;
	}
	
	++moveNumber_;
	
	return *this;
}
int main(void)
{
    int n;
    printf("How many vertices you want to take?");
    scanf("%d",&n);
    initialize(n);
    insertEdges(n);
    DFS(n);
    sortVertices(n);
    checker = 1;
    initialize(n);
    reverseDirection(n);
    for(int i = 1; i <= n; i++)
    {
        int v = s_vertices[i];

        if(color[v] == 0)
        {
            c = 0;
            DFS_Visit(n, v);
            for(int j = 1; j <= c; j++)
            {
                if(j == 1)
                {
                    printf("%d ", ver[j]);
                }
                else{

                    printf(", %d",ver[j]);
                }
            }
            printf("\n");
        }
    }


return 0;
}
Esempio n. 6
0
void Ghost::setState(int state)
{
    if(m_state != state)
        reverseDirection();
    m_state = state;
}
Esempio n. 7
0
 int getReverseTag(int neighbor) {
     return tags[reverseDirection(localRank, neighbor)];
 }
Esempio n. 8
0
File: astar.c Progetto: pd0wm/epo2
Path_element* findShortestPath(int start_x, int start_y, int facing_direction, int destination_x, int destination_y) {
	// Check wether the destination and start arent the same
	if (start_x == destination_x && start_y == destination_y) return NULL;

	// Initiate the node element, the start and destination and the path
	Node *node = malloc(sizeof (Node)), *start = malloc(sizeof (Node)), *destination = malloc(sizeof (Node));
	Path_element *path = NULL;

	// Find initial 'parent location'
	int parent_location = reverseDirection(facing_direction);

	// Clears the grid cache to prevent incorrect results
	clearGridCache();

	// Link start and destination to the grid consequently
	start = grid[start_x][start_y];
	destination = grid[destination_x][destination_y];

	// Add start to open list
	addToList(&list_open, start);

	do {
		// Find the node with the best score in the open list
		node = findLowestFInList(list_open);

		// Remove the node from the open list
		removeFromList(&list_open, node);

		// Add the node to the closed list
		addToList(&list_closed, node);

		// Find the parent location
		if (node->parent) parent_location = getParentLocation(node);

		// Process the neighbours
		processNeighbour(node->south, node, determineStepWeight(SOUTH, parent_location), destination->position);
		processNeighbour(node->north, node, determineStepWeight(NORTH, parent_location), destination->position);
		processNeighbour(node->east, node, determineStepWeight(EAST, parent_location), destination->position);
		processNeighbour(node->west, node, determineStepWeight(WEST, parent_location), destination->position);

		// Do this while the destination is not in the closed list, in which case the path has been found, or the open list is empty
	} while (!inList(list_closed, destination) && list_open != NULL);

	// Check if best path is found, in which case the destination is in the closed list
	if (inList(list_closed, destination)) {
		// Add destination to path
		node = destination;
		addToBeginOfPath(&path, node->position.x, node->position.y, reverseDirection(getParentLocation(node)), node->step_weight, node->id);

		do {
			// Get the parent of the node, doing this enough times will eventually get you to the start
			node = node->parent;

			// Add node to path
			addToBeginOfPath(
					&path,
					node->position.x, node->position.y,
					!getParentLocation(node) ? facing_direction : reverseDirection(getParentLocation(node)),
					node->step_weight,
					node->id
					);
		} while (node != start);
	}

	// Clear the lists
	clearList(&list_closed);
	clearList(&list_open);

	// Return the path
	return path;
}
Esempio n. 9
0
void
DriverThread::operateHardware()
{
    // temp data structures.
    hydrointerfaces::SegwayRmp::Data data;
    hydrointerfaces::SegwayRmp::Command command(0,0);

    // monitor the speed set-point, don't allow it to change faster than the acceleration limits
    // (initialises to zero speed)
    SpeedSetPoint speedSetPoint( config_.maxForwardAcceleration,
                                 config_.maxReverseAcceleration );

    // initialise stall sensor
    StallSensor stallSensor( config_.stallSensorConfig );
    StallType stallType;

    // clear any pending commands
    commandStore_.set( command );

    gbxiceutilacfr::Timer newCommandTimer;

    //
    // The big loop (we exit immediately on detecting a fault)
    //
    while ( !isStopping() )
    {
        speedSetPoint.evaluateDt();

        if ( stateMachine_.isFault() )
        {
            // Can't operate in a fault condition.
            break;
        }

        //
        // Read from the hardware
        //

        try {
            segwayRmp_.read( data );
            if ( config_.driveInReverse ) reverseDirection( data );

            // Let the higher-ups know
            stallType = stallSensor.isStalled(data);
            callback_.receiveData( data, stallType );

            // Check for warnings/faults
            if ( data.hasFaults ||
                 (stallType != NoStall) )
            {
                stringstream ssFault;
                if ( data.hasFaults )
                {
                    ssFault << data.warnFaultReason << "\n";
                }
                if ( stallType != NoStall )
                {
                    ssFault << stallString( data, stallType );
                }
                health().fault( ssFault.str() );
                if ( data.hasFaults )
                {
                    stateMachine_.setFault( ssFault.str() );
                    break;
                }
            }
            else if ( data.hasWarnings )
            {
                stateMachine_.setWarning( data.warnFaultReason );
                health().warning( data.warnFaultReason );
            }
            else
            {
                stateMachine_.setOK();
                health().ok();
            }
        }
        catch ( ... ) {
            string problem = hydroiceutil::catchExceptionsWithStatus( "reading from hardware", health() );
            stateMachine_.setFault( problem );
            break;
        }

        //
        // Write pending commands to the hardware
        //

        // Have we got a new command?
        bool gotNewCommand = false;
        if ( commandStore_.isNewData() )
        {
            gotNewCommand = true;
            commandStore_.get( command );
            speedSetPoint.set( command.vx );
            newCommandTimer.restart();
        }

        // Are we still trying to hit our set-point?
        bool setPointAlreadyReached = false;
        command.vx = speedSetPoint.currentCmdSpeed( setPointAlreadyReached );

        // Write if we're supposed to
        if ( gotNewCommand || !setPointAlreadyReached )
        {
            if ( config_.driveInReverse ) reverseDirection( command );
            try {
                // Probably better not to have this (mutex-locking)
                // statement in the middle of this very tight loop...
                //
                //stringstream ss;
                //ss << "DriverThread::"<<__func__<<"(): writing command: " << command.toString();
                //tracer_.debug( ss.str(), 2 );

                segwayRmp_.write( command );
            }
            catch ( ... ) {
                string problem = hydroiceutil::catchExceptionsWithStatus( "writing to hardware", health() );
                stateMachine_.setFault( problem );
                break;
            }
        }

        // Check for timeouts in receiving commands
        if ( newCommandTimer.elapsedSec() > 0.2 )
        {
            if ( command.vx != 0 || command.w != 0 )
            {
                tracer_.info( "newCommandTimer timed out, resetting desired speed to zero" );
                command = hydrointerfaces::SegwayRmp::Command(0,0);
                commandStore_.set(command);
                newCommandTimer.restart();
            }
        }
    }

    std::string faultReason;
    if ( stateMachine_.isFault(faultReason) )
    {
        health().fault( faultReason );
        // pause in case of persistent fault
        sleep(1);
    }
}
Esempio n. 10
0
void Slicer::slicing(QList<Triangle3D> *model)
{
    int n = 0;
  //  qDebug() << "Start Slicing\n";

    if(drawOutline)
    {
        if(!outsideOutline && !insideOutline)
        {
            QMessageBox::about(0, "Ошибка", "Укажите параметр внешней обводки");
            return;
        }
    }

    double currHeight = 0.0;

    while(currHeight <= height)
    {
        slice_byLine->clear();
        /*
        qDebug() << "Slice at " << currHeight << height << ":\n";
        qDebug() << "size(slice)" << slice->size() * sizeof(Point2D);
        qDebug() << "size(slice_byLine)" << slice_byLine->size() * sizeof(Line2D);
        qDebug() << "size(points)" << points->size() * sizeof(Point2D);
        qDebug() << "size(one_level)" << one_level->size() * sizeof(poid);
        qDebug() << "size(model)" << model->size() * sizeof(Triangle3D);*/
        GCodeOutStream << "Slice at " << currHeight << ":\r\n";

        for(int i = 0; i < model->size(); i++)
        {
            points->clear();

            if(points->isEmpty())
            {
                solveRelation(model->at(i).vertexes_p1, model->at(i).vertexes_p2, currHeight);
                solveRelation(model->at(i).vertexes_p2, model->at(i).vertexes_p3, currHeight);
                solveRelation(model->at(i).vertexes_p3, model->at(i).vertexes_p1, currHeight);

                if(points->size() == 2)
                {
                    Line2D line(points->at(0), points->at(1));
                    *slice_byLine += line;
                }
            }
            else
            {
                qDebug() << "********";
            }
        }

        if(slice_byLine->isEmpty())
        {
            break;
        }

        removeEqual();
        removeRepeated();
        removeReverseRepeated();

        while(!slice_byLine->isEmpty())
        {
        //    qDebug() << "1";
            start = findMin();
            slice->clear();
            buildOrder();

            if(!slice->at(0).isBiggerCorner(slice->at(slice->size() - 1)))
            {
                reverseDirection();
            }
        //    qDebug() << "size slice =" << sizeof(slice);

            if(slice->size() > 1)
            {
                if(drawOutline)
                {
                    if(insideOutline)
                    {
                        GCodeOutStream << "\tOutline shading - inside option:\r\n";
                        edgeShading(lineWidth, true, currHeight, impulse);
                    }
                    else if(outsideOutline)
                    {
                        GCodeOutStream << "\tOutline shading - outside option:\r\n";
                        edgeShading(lineWidth, false, currHeight, impulse);
                    }
                }
            }

            if(slice->size() > 2)
            {
                if(drawInline)
                {
                    GCodeOutStream << "\tInner shading:\r\n";
                    maxY = findMaxY();
                    innerShading(currHeight, impulse, scale);
                }
            }
        }

        currHeight += step_Z;
    }

    GCodeOut.close();
    QMessageBox::about(0, "Прогресс", "Печать прошла успешно!");
}