int resetSimulation(rtSimulationThread_t *p_thread)
{
	int i;
	stopSimulation(p_thread);
	pthread_mutex_lock(&p_thread->simulationMutex);
	restartSimulation(&p_thread->simulation);
	pthread_mutex_unlock(&p_thread->simulationMutex);
	
	return 0;
}
Esempio n. 2
0
/**
 * Constructor.
 * @param m pointer to main window
 */
Simulator::Simulator(MainWindow* m)
	 : QObject(m)
{
  main = m;
  simdlg = new SimulatorDlgImpl((QWidget*)main);
  current_state=NULL;

  connect(simdlg, SIGNAL(closing()), this, SLOT(stopSimulation()) );
  connect(simdlg, SIGNAL(inputSent()), this, SLOT(next()) );
  connect(simdlg, SIGNAL(resetPressed()), this, SLOT(reset()) );
}
Esempio n. 3
0
MainWindow::MainWindow()
{
  loadMapAction = new QAction( tr("Load Map"), this );
  startSimAction = new QAction( tr("Start Simulation"), this );
  stopSimAction = new QAction( tr("Stop Simulation"), this );
  exitAction = new QAction( tr("Exit"), this );
  aboutAction = new QAction( tr("About"), this );

  connect( loadMapAction, SIGNAL(triggered()), this, SLOT(loadMap()) );
  connect( startSimAction, SIGNAL(triggered()), this, SLOT(startSimulation()) );
  connect( stopSimAction, SIGNAL(triggered()), this, SLOT(stopSimulation()) );
  connect( exitAction, SIGNAL(triggered()), this, SLOT(exit()) );
  connect( aboutAction, SIGNAL(triggered()), this, SLOT(about()) );

  topMenu = menuBar()->addMenu( tr("File") );
  topMenu->addAction( loadMapAction );
  topMenu->addSeparator();
  topMenu->addAction( startSimAction );
  topMenu->addAction( stopSimAction );
  topMenu->addSeparator();
  topMenu->addAction( exitAction );

  customiseMapAction = new QAction( tr("Customise Map"), this );
  connect( customiseMapAction, SIGNAL(triggered()), this, SLOT(customiseMap()) );
  
  topMenu = menuBar()->addMenu( tr("Options") );
  topMenu->addAction( customiseMapAction );
	
  topMenu = menuBar()->addMenu( tr("Help") );
  topMenu->addAction( aboutAction );
  
  showMaximized();
	
  drawMain = new DrawWidgetMW();
  setCentralWidget( drawMain );

  simthread = new QThread();
  simwrk = new SimulationWorker( drawMain );

  simwrk->moveToThread( simthread );

  statusBar();
  statusBar()->addPermanentWidget( &scaleLabel );

  connect( simthread, SIGNAL(started()), simwrk, SLOT(startModeling()) );
  connect( simwrk, SIGNAL(finished()), simthread, SLOT(quit()) );
  connect( drawMain, SIGNAL( sendScale( int ) ), this, SLOT( showScale( const int ) ) );

  setWindowTitle( tr("Water Movement Simulation Tool") );
}
Esempio n. 4
0
RobotVREP::~RobotVREP()
{
	if (video_recording_flag) 
	{
		setVideoRecordingMode(false);
	}

	if (simulation_in_progress) 
	{	
		stopSimulation();
	}	

	simxFinish(clientID);

	vrep_error.close();
}
Esempio n. 5
0
void Mediator::handleDispatcher(int index){
	
	
	int fd = socketManager->getConnectedFD(index);
	char messageIN[BUFFER_SIZE];
	int rd  = ioStream->readLine(fd, messageIN, BUFFER_SIZE);
	if (rd > 0){
		cout << "[From Dispatcher...]\t" << messageIN  << flush;
		vector<char*> tokens ;
		char* token = strtok(messageIN, "|");
		while (token != NULL){
			tokens.push_back(token);
			token = strtok(NULL, "|\n");	
		}
		if (strcmp(tokens[0],"setupEnv") == 0)
			setupEnv(tokens, fd);
		else if (strcmp(tokens[0], "disconnect")==0){
			disconnect(tokens[1], fd);
		}
		else if (strcmp(tokens[0], "BG_putFile")==0){
			BG_put_file(tokens[1], atol(tokens[2]), fd);
		}
		else if (strcmp(tokens[0], "BG_start") == 0){
			BG_start(tokens[1], atol(tokens[2]));
		}
		else if (strcmp(tokens[0], "JOB_STOP") ==0 ){
       	//	processList.stopAll();
 		//	becomeFree(); 
			stopSimulation("dispatcher");
			becomeFree();
			simulationFinished();
		}
		else if (strcmp(tokens[0], "JOB_ABORT") ==0 ){
			abortSimulation();
		}
		else if (strcmp(tokens[0], "getTick\n") == 0){
			getTick(fd);
		}
		else
			cout << "else?" << endl << flush;
	}
	else{
		socketManager->closeByIndex(index);
		cout << "Dispatcher Closed" << endl << flush;
		
	}
}
static void* runThread(void *arg)
{
	rate_t loopRate;
	int ret = 0;
	
	rtSimulationThread_t *simulationThread = (rtSimulationThread_t*) arg;
	//allegro has to be initialized int thread
	//allegro creates thread -> shall inherit from this one
	ret = initAllegroComponents(simulationThread);
	if(ret != 0)
		exit(0);
		
	PRINT_INFO("SimulationThread started.\n");	
	simulationThread->running = 1;
	simulationThread->exitCode = initRate(&loopRate, SIMULATION_RATE);
	if(simulationThread->exitCode != 0) {
		PRINT_ERR("Failed to init rate (%d).\n", simulationThread->exitCode);
		simulationThread->keepRunning = 0;
	}
	
	while(simulationThread->keepRunning) {
		//EXEC RESTART_TIME_TAKING(simulationExecutionTime);
		RESTART_TIME_TAKING(simulationReactionTime);
		if(simulationThread->simulate) {
			// simulate the crash simulation for one timestep
			ret = stepSimulationThreadSafe(simulationThread);
			if(ret != 0)
				stopSimulation(simulationThread);
		}
		drawSimulationThreadSafe(simulationThread, ret);
		//EXEC STOP_TIME_TAKING(simulationExecutionTime);
		STOP_TIME_TAKING(simulationReactionTime);
		
		simulationThread->exitCode = sleepRate(&loopRate);
		if(simulationThread->exitCode != 0) {
			PRINT_ERR("Failed to sleep (%d).\n", simulationThread->exitCode);
			simulationThread->keepRunning = 0;
		}
	}
	
	destroyAllegroComponents(simulationThread);
	simulationThread->running = 0;
	PRINT_INFO("SimulationThread terminated.\n");
	pthread_exit(&simulationThread->exitCode);
}
FormSimulator::FormSimulator(FormMain* parent)
  : QDialog(parent), m_ui(new Ui::FormSimulator), m_mainWindow(parent), m_isActive(false), m_activeSimulation(NULL) {
  m_ui->setupUi(this);

  // Load some needed settings.
  m_isVisibleOnStartup = qApp->settings()->value(APP_CFG_SIMULATOR, "visible_on_startup", false).toBool();
  m_isSticked = qApp->settings()->value(APP_CFG_SIMULATOR, "is_sticked", false).toBool();

  // Do necessary initializations.
  setupIcons();
  setupPhoneWidget();

  connect(parent, SIGNAL(moved()), this, SLOT(conditionallyAttachToParent()));
  connect(parent, SIGNAL(resized()), this, SLOT(conditionallyAttachToParent()));
  connect(m_ui->m_btnRunSimulation, SIGNAL(clicked()), this, SLOT(startSimulation()));
  connect(m_ui->m_btnStopSimulation, SIGNAL(clicked()), this, SLOT(stopSimulation()));
  connect(m_ui->m_btnGoBack, SIGNAL(clicked()), this, SLOT(goBack()));
  connect(this, SIGNAL(stopEnableChanged(bool)), m_ui->m_btnStopSimulation, SLOT(setEnabled(bool)));

  // This window mustn't be deleted when closed by user.
  setAttribute(Qt::WA_DeleteOnClose, false);
  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
Esempio n. 8
0
void MainWindow::Toolbar()
{
    QPixmap openIcon((const char**) open_xpm);
    QPixmap redoIcon((const char**) redo_xpm);
    QPixmap simulateIcon((const char**) simulate_xpm);
    QPixmap stopIcon((const char**) stop_xpm);
    QPixmap cameraIcon((const char**) camera_xpm);
    QPixmap filmIcon((const char**) film_xpm);
    QPixmap frontViewIcon((const char**) frontView_xpm);
    QPixmap topViewIcon((const char**) topView_xpm);
    QPixmap rightSideViewIcon((const char**) rightSideView_xpm);

    toolbar = addToolBar("main toolbar");
    QAction *open = toolbar->addAction(QIcon(openIcon), "Open Scene (Ctrl + O)");
    QAction *redo = toolbar->addAction(QIcon(redoIcon), "Load last viewed scene (Ctrl + Shift + Q)");
    toolbar->addSeparator();
    QAction *simulate = toolbar->addAction(QIcon(simulateIcon), "Start Simulation (Ctrl + R");
    QAction *stop = toolbar->addAction(QIcon(stopIcon), "Stop Simulation (Ctrl + C");
    stop->setVisible(false);
    toolbar->addSeparator();
    QAction *camera = toolbar->addAction(QIcon(cameraIcon), "Export screenshot");
    QAction *film = toolbar->addAction(QIcon(filmIcon), "Export film sequence");
    toolbar->addSeparator();
    QAction *front = toolbar->addAction(QIcon(frontViewIcon), "View scene from front");
    QAction *top = toolbar->addAction(QIcon(topViewIcon), "View scene from top");
    QAction *rightSide = toolbar->addAction(QIcon(rightSideViewIcon), "View scene from right");

    connect(open, SIGNAL(triggered()), this, SLOT(loadScene()));
    connect(redo, SIGNAL(triggered()), this, SLOT(quickLoad()));
    connect(simulate, SIGNAL(triggered()), this, SLOT(startSimulation()));
    connect(stop, SIGNAL(triggered()), this, SLOT(stopSimulation()));
    connect(camera, SIGNAL(triggered()), this, SLOT(camera()));
    connect(film, SIGNAL(triggered()), this, SLOT(film()));
    connect(front, SIGNAL(triggered()), this, SLOT(front()));
    connect(top, SIGNAL(triggered()), this, SLOT(top()));
    connect(rightSide, SIGNAL(triggered()), this, SLOT(side()));
}
Esempio n. 9
0
void Mediator::handleCommand(int index){
	
	int fd = socketManager->getConnectedFD(index);
	char messageIN[BUFFER_SIZE];
	int rd = ioStream->readLine(fd, messageIN, BUFFER_SIZE);
	if (rd > 0){
		cout << "[From Command...]\t" << messageIN  << flush;
		char* command = strtok(messageIN, "|");
		if (strcmp(command,"init") ==0){
			char* ip   = strtok(NULL, "|\n");
			int	  cmd_port  = atoi(strtok(NULL, "|\n"));
			int   data_port = atoi(strtok(NULL, "|\n"));
			int   time_port = atoi(strtok(NULL, "|\n"));
			int   info_port = atoi(strtok(NULL, "|\n"));
			initClient(ip, fd, cmd_port, data_port, time_port, info_port);
		}
		else if (strcmp(command,"putfile") ==0){
			long fileSize = 0;
			char* filename = strtok(NULL, "|");
			sscanf(strtok(NULL, "|\n"), "%d", &fileSize);
			int data_fd = clientList.getActiveClient()->data_fd;
			putfile(filename, fileSize, fd, data_fd);
		}
		else if (strcmp(command,"startSimulation") == 0){
			char* command = strtok(NULL, "|\n");
			int timePort;
			sscanf(strtok(NULL, "|\n"), "%d", &timePort);
			startSimulation(command, false);
		}
		else if (strcmp(command,"pauseSimulation") == 0){
			pauseSimulation(strtok(NULL, "|\n"));
		}
		else if (strcmp(command,"stopSimulation") == 0){
			stopSimulation(strtok(NULL, "|\n"));
		}
		else if (strcmp(command,"resumeSimulation") == 0){
			resumeSimulation(strtok(NULL, "|\n"));
		}
		else if (strcmp(command,"abortSimulation") == 0){
			abortSimulation();
		}
		else if (strcmp(command, "getResults\n") == 0){
			getResults();
		}
/*
		else if (strcmp(command, "getFileList\n") == 0){
			getFileList();
		}
*/
		else if (strcmp(command, "getFile") == 0){
			getFile(strtok(NULL, "|\n"));
		}

		else if (strcmp(command, "reconnect") == 0){
			reconnect(strtok(NULL, "\n"), fd);			
		}
		else if (strcmp(command, "sendtoSE") == 0){
			sendtoSE("From GUI : ", strtok(NULL, "|"));
		}
		else if (strcmp(command, "console") == 0){
			commandConsole(strtok(NULL, "\n"), fd);
		}
		else if (strcmp(command, "init_remote") == 0){
			initRemote(strtok(NULL, "\n"), fd);
		}
		else
			cout << "else??\n" << flush;
	}
	else{
		if (currentSession == 0){
			abortSimulation(); 
		}else{
			closeClient();
		}
	}
}
Esempio n. 10
0
/**
 * @brief Data::initialize initilize all important containers.
 * @param mainWindow
 */
void Data::initialize(MainWindow *mainWindow) {
    changed = false;
    this->mainWindow = mainWindow;
    // connect start and stop signals
    connect(mainWindow->ui->actionRun_Mesh, SIGNAL(triggered()), this,
            SLOT(runMesh()));
    connect(mainWindow->ui->actionStop_Simulation, SIGNAL(triggered()),this,SLOT(stopSimulation()));

    //connect the on click even of items in node category list
    connect(mainWindow->ui->NodeCategories_List,SIGNAL(itemClicked(QListWidgetItem*)),
            this, SLOT(onNodeCategoryItemClicked(QListWidgetItem*)));

    /**
* Create the Nodecatalog
*/
    if (nodeCatalog) delete nodeCatalog;
    nodeCatalog = new NodeCatalog();
    /**
* Create the render object
*/
    SingletonRender::instance();
    /**
* Create the NodeFactory
*/
    if (nodeFactory) delete nodeFactory;
    this->nodeFactory = new NodeFactory();

    /**
* Initialize stored settings
*/
    SettingsHandler::setSettingsPath(QApplication::applicationDirPath() +
                                     "/settings.ini");

    /**
    * Initialize settings from .ini file
    */
    SettingsHandler::initializeSettings();

    /**
* Checks if Framework path is set
*/
    if (!SettingsHandler::contains("frameworkpath")){
        int choice = QMessageBox::information(
                    0, QString("Please, set your framework path"),
                    QString("You haven't set your framework path yet.\nChoose first!"),
                    "Choose", "Ignore");
        if (choice == 1) return;
        QString fileName = QFileDialog::getOpenFileName(
                    mainWindow, "Set your framework path", "", "");

        SettingsHandler::storeSetting("frameworkpath", fileName);
    }
    AniseCommunicator::setFrameworkPath(
                SettingsHandler::getSetting("frameworkpath"));

    /**
* Start loading node types
* Load all available NodeTypes
*/
    QString out = AniseCommunicator::getAllNodeTypes();
    JsonFileHandler::parseNodeTypesFromAnise(out);

    /**
* Render the Nodecatalog depending on Category filled with test nodes
*/
    displayNodeCategory(Data::instance()->getNodeCatalog()->getContentVector());
}
Esempio n. 11
0
void Simulation::reset() {
	stopSimulation();
	gripper_.reset();
	info_.reset();
}
Esempio n. 12
0
void MainWindow::createActions()
{
    //loadAct
    loadSceneAct = new QAction(tr("&Load Scene"), this);
    loadSceneAct->setShortcut(Qt::CTRL + Qt::Key_O);
    loadSceneAct->setStatusTip(tr("Load scene"));
    connect(loadSceneAct, SIGNAL(triggered()), this, SLOT(loadScene()));

    //quickLoadAct
    quickLoadAct = new QAction(tr("&Quick Load"), this);
    quickLoadAct->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_Q);
    quickLoadAct->setStatusTip(tr("Load last scene"));
    connect(quickLoadAct, SIGNAL(triggered()), this, SLOT(quickLoad()));

    //saveSceneAct
    saveSceneAct = new QAction(tr("&Save Scene"), this);
    saveSceneAct->setShortcut(Qt::CTRL + Qt::Key_S);
    saveSceneAct->setStatusTip(tr("Save Scene"));
    connect(saveSceneAct, SIGNAL(triggered()), this, SLOT(saveScene()));

    loadPluginFileAct = new QAction(tr("&Load Plugin"), this);
    loadPluginFileAct->setShortcut(Qt::CTRL + Qt::Key_L);
    loadPluginFileAct->setStatusTip(tr("Load plugin file"));
    connect(loadPluginFileAct, SIGNAL(triggered()), this, SLOT(loadPluginFileWithDialog()));

    loadPluginDirAct = new QAction(tr("&Load Plugin Directory"), this);
    loadPluginDirAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_L);
    loadPluginDirAct->setStatusTip(tr("Load all plugins in directory"));
    connect(loadPluginDirAct, SIGNAL(triggered()), this, SLOT(loadPluginDirWithDialog()));

    /// save workspace configuration action
    saveWorkspaceConfigurationAct = new QAction(tr("Save Workspace"), this);
    saveWorkspaceConfigurationAct->setStatusTip(tr("Save the configuration of the workspace"));
    connect(saveWorkspaceConfigurationAct, SIGNAL(triggered()), this, SLOT(saveWorkspace()));

    /// save new workspace configuration action
    saveNewWorkspaceConfigurationAct = new QAction(tr("Save Workspace As..."), this);
    saveNewWorkspaceConfigurationAct->setStatusTip(tr("Save a new workspace configuration"));
    connect(saveNewWorkspaceConfigurationAct, SIGNAL(triggered()), this, SLOT(saveNewWorkspace()));

    /// load workspace configuration action
    loadWorkspaceConfigurationAct = new QAction(tr("Load Workspace"), this);
    loadWorkspaceConfigurationAct->setStatusTip(tr("Load a workspace configuration"));
    connect(loadWorkspaceConfigurationAct, SIGNAL(triggered()), this, SLOT(loadWorkspace()));

    //closeAct
    closeSceneAct = new QAction(tr("&Close"), this);
    closeSceneAct->setShortcut(Qt::CTRL + Qt::Key_W);
    closeSceneAct->setStatusTip(tr("Close Scene"));
    connect(closeSceneAct, SIGNAL(triggered()), this, SLOT(close()));

    //exitAct
    exitAct = new QAction(tr("&Exit"), this);
    exitAct->setShortcuts(QKeySequence::Quit);
    exitAct->setStatusTip(tr("Exit the application"));
    connect(exitAct, SIGNAL(triggered()), this, SLOT(exit()));

    //frontAct
    frontAct = new QAction(tr("Front"), this);
    frontAct->setStatusTip(tr("Camera Front View"));
    connect(frontAct, SIGNAL(triggered()), this, SLOT(front()));

    //topAct
    topAct = new QAction(tr("Top"), this);
    topAct->setStatusTip(tr("Camera Top View"));
    connect(topAct, SIGNAL(triggered()), this, SLOT(top()));

    //sideAct
    sideAct = new QAction(tr("Side"), this);
    sideAct->setStatusTip(tr("Camera Side View"));
    connect(sideAct, SIGNAL(triggered()), this, SLOT(side()));

    //startSimulationAct
    startSimulationAct = new QAction(tr("Start Simulation"), this);
    startSimulationAct->setShortcut(Qt::CTRL + Qt::Key_R);
    connect(startSimulationAct, SIGNAL(triggered()), this, SLOT(startSimulation()));

    //stopSimulationAct
    stopSimulationAct = new QAction(tr("Stop Simulation"), this);
    stopSimulationAct->setShortcut(Qt::CTRL + Qt::Key_C);
    connect(stopSimulationAct, SIGNAL(triggered()), this, SLOT(stopSimulation()));

    //simulateSingleStepAct
    simulateSingleStepAct = new QAction(tr("Simulate Single Step"), this);
    simulateSingleStepAct->setStatusTip(tr("Simulates one step at a time"));
    simulateSingleStepAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_R);
    connect(simulateSingleStepAct, SIGNAL(triggered()), this, SLOT(simulateSingleStep()));

    //renderDuringSimulationAct
    renderDuringSimulationAct = new QAction(tr("Render during Simulation"), this);
    connect(renderDuringSimulationAct, SIGNAL(triggered()), this, SLOT(renderDuringSimulation()));

    //whiteAct
    whiteAct = new QAction(tr("White"), this);
    connect(whiteAct, SIGNAL(triggered()), this, SLOT(white()));

    //grayAct
    grayAct = new QAction(tr("Gray"), this);
    connect(grayAct, SIGNAL(triggered()), this, SLOT(gray()));

    //BlackAct
    blackAct = new QAction(tr("Black"), this);
    connect(blackAct, SIGNAL(triggered()), this, SLOT(black()));

    //resetCameraAct
    resetCameraAct = new QAction(tr("Reset Camera"), this);
    resetCameraAct->setStatusTip(tr("Reset Camera Angle"));
    connect(resetCameraAct, SIGNAL(triggered()), this, SLOT(resetCamera()));

    //xga1024x768Act
    xga1024x768Act = new QAction(tr("XGA 1024 x 768"), this);
    xga1024x768Act->setCheckable(true);
    xga1024x768Act->setChecked(true);
    connect(xga1024x768Act, SIGNAL(triggered()), this, SLOT(xga1024x768()));

    //vga640x480Act
    vga640x480Act = new QAction(tr("VGA 640 x 768"), this);
    vga640x480Act->setCheckable(true);
    connect(vga640x480Act, SIGNAL(triggered()), this, SLOT(vga640x480()));

    //hd1280x720Act
    hd1280x720Act = new QAction(tr("HD 1280 x 720"), this);
    hd1280x720Act->setCheckable(true);
    connect(hd1280x720Act, SIGNAL(triggered()), this, SLOT(hd1280x720()));

    //aboutAct
    aboutAct = new QAction(tr("About"), this);
    aboutAct->setShortcut(Qt::Key_F1);
    connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
}