Beispiel #1
0
void return_to_origin() 
{
	set_point(0, 0);

	//returns the robot to the origin position.
	turnRight(PHASE1_SPEED, PHASE1_SLOW, (2 * M_PI - bearing) * RADIANS_TO_DEGREES); //get the robot to face origin

	double dist_to_origin = getDistance(xpos, ypos, 0, 0);
	moveForwards(PHASE1_SPEED, PHASE1_SLOW, dist_to_origin * CM_TO_ENCODER); //move to origin

	fixBearing(0); //resets robot's bearing to face upwards
}
void FreeCamera::update(double deltaTime) {
	float vel = inputVector.z ? slowVelocity : velocity;

	if (inputVector.x < 0)
		moveForwards((float)-inputVector.x * vel * (float)deltaTime);
	else if (inputVector.x > 0)
		moveBackwards((float)inputVector.x * vel * (float)deltaTime);

	if (inputVector.y < 0)
		strafeLeft((float)-inputVector.y * vel * (float)deltaTime);
	else if (inputVector.y > 0)
		strafeRight((float)inputVector.y * vel * (float)deltaTime);
}
Beispiel #3
0
// Decides which kind of movement the tank will do with the given signal read from tty port
void move(int signal) {
	 if(signal == 1 ){
		moveForwards(1);

    }else if(signal == 2){
		moveBackwards(1);   

    }else if(signal == 3){
		turnLeft(1);

    }else if(signal == 4){
		turnRight(1);

    }else if(signal == 0){
        stop();
    }
}
Beispiel #4
0
char* getPath(int startx, int starty, int destx, int desty)
{
	//moves the robot from a square to another (in the grid where start = (0, 0)), following left wall, and records the path taken.

	int left, right, index = 0, currentx = startx, currenty = starty; //stores current position of robot in the grid in currentx and currenty 
	int idealBearing = getIdealBearing(); 
	char* path = malloc(sizeof(char) * PATH_MAX_LENGTH);

	while (currentx != destx || currenty != desty)
	{
		get_front_ir_dists(&left, &right);
		int front = get_us_dist();

		/*if(front < MAX_DIST_TO_WALL)
		{
			checkFrontWall(front);
		}*/

		//checks accurancy of the robot's calculated current position vs its real position
		log_trail();
		set_point(xpos, ypos);

		if(left > MAX_DIST_TO_WALL) 
		{
			//turn left
			turnLeft(PHASE1_SPEED, PHASE1_SLOW, 90);
			idealBearing -= 90;
			if(idealBearing < 0) { idealBearing += 360; }
			path[index] = 'L';
		}
		else if(front > MAX_DIST_TO_WALL)
		{
			//go straight
			path[index] = 'S';
		}
		else if(right > MAX_DIST_TO_WALL)
		{
			//turn right
			turnRight(PHASE1_SPEED, PHASE1_SLOW, 90);
			idealBearing += 90;
			if(idealBearing >= 360) { idealBearing -= 360; }
			path[index] = 'R';
		}
		else
		{
			//turn around
			turnRight(PHASE1_SPEED, PHASE1_SLOW, 180);
			idealBearing += 180;
			if(idealBearing >= 360) { idealBearing -= 360; }
			path[index] = 'B';
		}

		fixBearing(idealBearing);
		moveForwards(PHASE1_SPEED, PHASE1_SLOW, SQUARE_DIST * CM_TO_ENCODER);

		//uses robot's idealBearing to figure out which square in the grid the robot is currently in after moving 
		switch(idealBearing)
		{
			case 0: currenty++; break;
			case 90: currentx++; break;
			case 180: currenty--; break;
			case 270: currentx--; break;
			default: printf("Error: unexpected value for idealBearing\n"); break;
		}

		index++;
	}
	path[index] = '\0';
	return path;
}
Beispiel #5
0
void main() {
    // I/O structures
    inputs  iMem;
    outputs oMem = {0};
    
    // Ports mapping
    INTCON = 0;
    // Outputs
    TRISC = 0;
    PORTC = 0;
    TRISD = 0;
    PORTD = 0;
    // Input
    TRISB = 0xff;
    
    // Cleans ports
    syncOutputs(&oMem);
    // Updates inbound
    freezeInputs(&iMem);
    
    // Turns on READY LED
    oMem.delReady = 1;
    // Turns on WAITING LED
    oMem.delWaiting = 1;
    // If in debug mode, turns on DEBUG LED
    if (DBGMODE)    oMem.delDebug = 1;
    
    // Stops motors (just in case)
    moveStops(&oMem);
    
    // Commit on ports
    syncOutputs(&oMem);
    
    
    // Wait until user press on start
    while (!iMem.startButton)     freezeInputs(&iMem);
    
    
    // Turns off READY and WAITING LEDs
    oMem.delReady = 0;
    oMem.delWaiting = 0;
    // Turns on RUNNING LED
    oMem.delRun = 1;
    // Commits
    syncOutputs(&oMem);
    
    // Main loop
    do {
        // Gets a snapshot of the inputs to prevent such issues as in bug #24
        freezeInputs(&iMem);
        // Commit output changes
        syncOutputs(&oMem);
        
        // Distance checks
        // If obstacle is "FAR AWAY", we continue forward
        if (obstacleDistanceIsFaraway(iMem)) {
            moveForwards(&oMem);
        // If obsacle is close, but not too much, we turns left
        } else if (obstacleDistanceIsOk(iMem)) {
            moveTurnsLeft(&oMem);
        // If obstacle is too close, we stops motors and stops the program
        } else {
            moveStops(&oMem);
            break;
        }
    } while (1);
    
    // This is the shutdown program, executed when the infinite loop
    // is broken.
    // We turns off the RUN LED and turns on the ERROR LED
    oMem.delRun = 0;
    oMem.delError = 1;
    // Just in case, we stops the motors.
    moveStops(&oMem);
    // Sync
    syncOutputs(&oMem);
}
Beispiel #6
0
MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow)
{
	ui->setupUi(this);

	for (int i = 0; i < MaxRecentFiles; ++i)
	{
		recentFileActions[i] = new QAction(this);
		recentFileActions[i]->setVisible(false);
		connect(recentFileActions[i], SIGNAL(triggered()), this, SLOT(openRecentFile()));
		ui->menuFile->insertAction(ui->actionExit, recentFileActions[i]);
	}
	recentFilesSeparator = ui->menuFile->insertSeparator(ui->actionExit);

	form = new Form(this);
	view = new GraphicsView(form, this);
	setCentralWidget(view);

	itemWidget = new ItemWidget(ui->propertyWidget);
	itemWidget->setHidden(true);
	connect(view, SIGNAL(mouseDoubleClick()), itemWidget, SLOT(selectPicture()));

	formWidget = new FormWidget(ui->propertyWidget);
	formWidget->connectForm(form);
	formWidget->update(form);
	ui->propertyWidget->setWidget(formWidget);

	fontCombo = new QFontComboBox(this);
	ui->formatToolBar->insertWidget(ui->actionBold, fontCombo);

	insertGroup = new QActionGroup(this);
	insertGroup->addAction(ui->actionSelect);
	insertGroup->addAction(ui->actionPaint);
	connect(insertGroup, SIGNAL(triggered(QAction*)), this, SLOT(insertObject(QAction*)));

	ui->actionLeft->setData(Qt::AlignLeft);
	ui->actionCenter->setData(Qt::AlignHCenter);
	ui->actionRight->setData(Qt::AlignRight);

	zoomGroup = new QActionGroup(this);
	zoomGroup->addAction(ui->actionActualSize);
	zoomGroup->addAction(ui->actionFitWidth);
	zoomGroup->addAction(ui->actionFitHeight);
	connect(zoomGroup, SIGNAL(triggered(QAction*)), this, SLOT(zoom(QAction*)));

	ui->actionActualSize->setData(GraphicsView::ActualSize);
	ui->actionFitWidth->setData(GraphicsView::FitWidth);
	ui->actionFitHeight->setData(GraphicsView::FitHeight);

	horzAlignGroup = new QActionGroup(this);
	horzAlignGroup->addAction(ui->actionLeft);
	horzAlignGroup->addAction(ui->actionCenter);
	horzAlignGroup->addAction(ui->actionRight);
	connect(horzAlignGroup, SIGNAL(triggered(QAction*)), this, SLOT(horzAlign(QAction*)));

	sizeGroup = new QActionGroup(this);
	sizeGroup->addAction(ui->actionShrinkWidth);
	sizeGroup->addAction(ui->actionGrowWidth);
	sizeGroup->addAction(ui->actionPageWidth);
	sizeGroup->addAction(ui->actionShrinkHeight);
	sizeGroup->addAction(ui->actionGrowHeight);
	sizeGroup->addAction(ui->actionPageHeight);
	sizeGroup->addAction(ui->actionShrinkBoth);
	sizeGroup->addAction(ui->actionGrowBoth);
	sizeGroup->addAction(ui->actionPageBoth);

	ui->actionShrinkWidth->setData(Form::ShrinkWidth);
	ui->actionGrowWidth->setData(Form::GrowWidth);
	ui->actionPageWidth->setData(Form::PageWidth);
	ui->actionShrinkHeight->setData(Form::ShrinkHeight);
	ui->actionGrowHeight->setData(Form::GrowHeight);
	ui->actionPageHeight->setData(Form::PageHeight);
	ui->actionShrinkBoth->setData(Form::ShrinkBoth);
	ui->actionGrowBoth->setData(Form::GrowBoth);
	ui->actionPageBoth->setData(Form::PageBoth);

	connect(sizeGroup, SIGNAL(triggered(QAction*)), this, SLOT(size(QAction*)));

	connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(newForm()));
	connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openForm()));
	connect(ui->actionReload, SIGNAL(triggered()), this, SLOT(reload()));
	connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveForm()));
	connect(ui->actionSaveAs, SIGNAL(triggered()), this, SLOT(saveFormAs()));
	connect(ui->actionSaveAsPDF, SIGNAL(triggered()), this, SLOT(saveFormAsPdf()));
	connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
	connect(ui->actionOpenPrintData, SIGNAL(triggered()), this, SLOT(openPrintData()));
	connect(ui->actionPageSetup, SIGNAL(triggered()), form, SLOT(pageSetup()));
	connect(ui->actionPagePreview, SIGNAL(triggered()), this, SLOT(preview()));
	connect(ui->actionSend, SIGNAL(triggered()), this, SLOT(email()));
	connect(ui->actionPrint, SIGNAL(triggered()), this, SLOT(print()));
	connect(ui->actionFullScreen, SIGNAL(triggered()), this, SLOT(fullScreen()));
	connect(ui->actionMargins, SIGNAL(toggled(bool)), form, SLOT(showMargins(bool)));
	connect(ui->actionGrid, SIGNAL(toggled(bool)), form, SLOT(showGrid(bool)));
	connect(ui->actionPrintData, SIGNAL(toggled(bool)), form, SLOT(showData(bool)));
	connect(ui->actionSelectAll, SIGNAL(triggered()), form, SLOT(selectAll()));
	connect(ui->actionDelete, SIGNAL(triggered()), form, SLOT(deleteSelected()));
	connect(ui->actionProperties, SIGNAL(toggled(bool)), ui->propertyWidget, SLOT(setVisible(bool)));
	connect(ui->actionMoveForwards, SIGNAL(triggered()), form, SLOT(moveForwards()));
	connect(ui->actionMoveBackwards, SIGNAL(triggered()), form, SLOT(moveBackwards()));
	connect(ui->actionAlignLeft, SIGNAL(triggered()), form, SLOT(alignLeft()));
	connect(ui->actionAlignRight, SIGNAL(triggered()), form, SLOT(alignRight()));
	connect(ui->actionAlignTop, SIGNAL(triggered()), form, SLOT(alignTop()));
	connect(ui->actionAlignBottom, SIGNAL(triggered()), form, SLOT(alignBottom()));
	connect(ui->actionCut, SIGNAL(triggered()), form, SLOT(cut()));
	connect(ui->actionCopy, SIGNAL(triggered()), form, SLOT(copy()));
	connect(ui->actionPaste, SIGNAL(triggered()), this, SLOT(paste()));
	connect(ui->actionFirstPage, SIGNAL(triggered()), this, SLOT(firstPage()));
	connect(ui->actionPreviousPage, SIGNAL(triggered()), this, SLOT(previousPage()));
	connect(ui->actionNextPage, SIGNAL(triggered()), this, SLOT(nextPage()));
	connect(ui->actionLastPage, SIGNAL(triggered()), this, SLOT(lastPage()));

	connect(ui->menuView, SIGNAL(aboutToShow()), this, SLOT(updateViewMenu()));
	connect(form, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
	connect(form, SIGNAL(changed()), this, SLOT(formChanged()));
	connect(view, SIGNAL(doneRubberBanding(QRectF)), this, SLOT(doneRubberBanding(QRectF)));

	connectForm();
	loadSettings();
	QTimer::singleShot(0, this, SLOT(init()));
}