コード例 #1
0
ファイル: test_threads.c プロジェクト: animotron/animos
static errno_t threads_test()
{

    hal_cond_init(&c, "threadTest");
    hal_mutex_init(&m, "threadTest");
    hal_sem_init(&s, "threadTest");

    int i = 40;
    n_t_empty = i;
    while(i-- > 0)
        phantom_create_thread( t_empty, "Empty", 0 );

    pressEnter("will create thread");
    phantom_create_thread( thread1, "__T1__", 0 );
    phantom_create_thread( thread1, "__T2__", 0 );
    //phantom_create_thread( thread1, "__T3__" );

    //phantom_create_thread( t_wait, "__TW__" );
    int tid = hal_start_kernel_thread_arg( t_wait, "__TW__" );

    i = 40;
    while(i-- > 0)
    {
        if(TEST_CHATTY) pressEnter("will yield");
        YIELD();

        if(TEST_CHATTY) printf("!! back in main\n");
    }

    t_kill_thread( tid );
    hal_sleep_msec( 30 );

    thread_stop_request = 1;
    hal_sleep_msec( 10 );

    thread_activity_counter = 0;
    hal_sleep_msec( 1000 );
    if( thread_activity_counter )
    {
        SHOW_ERROR0( 0, "Can't stop thread" );
        return -1;
    }

    while(n_t_empty > 0)
    {
        SHOW_FLOW( 0, "wait for %d threads", n_t_empty );
        hal_sleep_msec(500);
    }

    if(p._ah.refCount != 1)
    {
        SHOW_ERROR( 0, "p._ah.refCount = %d", p._ah.refCount );
        test_fail_msg( -1, "refcount" );
    }
    else
        SHOW_ERROR( 0, "p._ah.refCount = %d, SUCCESS", p._ah.refCount );

    return 0;
}
コード例 #2
0
ファイル: ex9_waypoints.cpp プロジェクト: utexas-bwi/segbot
int main(int argc, char **argv) {
    // Intialize ROS with this node name
    ros::init(argc, argv, "ex9_waypoints");
    
    ros::NodeHandle n;

    //register ctrl-c
    signal(SIGINT, sig_handler);

    bool success = false;
    segbot_arm_manipulation::Mico mico(n);

    mico.move_home();

    pressEnter("Press enter to move through waypoints with Kinova firmware...");


    geometry_msgs::Pose pose;

    tf::Quaternion quat;
    quat.setX(0.58);
    quat.setY(0.39);
    quat.setZ(0.37);
    quat.setW(0.61);
    quat.normalize();
    tf::quaternionTFToMsg(quat, pose.orientation);

    geometry_msgs::Pose to_add;
    std::vector<geometry_msgs::Pose> waypoints;
    pose.position.x = 0.2;
    pose.position.y = -0.25;
    pose.position.z = 0.5;
    to_add = pose;
    waypoints.push_back(to_add);
    pose.position.x = 0.4;
    pose.position.y = -0.25;
    pose.position.z = 0.5;
    to_add = pose;
    waypoints.push_back(to_add);
    pose.position.x = 0.2;
    pose.position.y = -0.25;
    pose.position.z = 0.5;
    to_add = pose;
    waypoints.push_back(to_add);
    mico.move_through_waypoints(waypoints);
    mico.move_home();

    pressEnter("Press enter to move through waypoints with MoveIt...");
    success = mico.move_through_waypoints_moveit(waypoints);
    ROS_INFO("Waypoint traversal status: %s", success ? "true": "false");
    mico.move_home();
    ros::shutdown();
}
コード例 #3
0
ファイル: concentration.cpp プロジェクト: davemachado/Games
void callConcentrationRules(){
    
    clearScreen();
    cout << "                ----------------------- CONCENTRATION RULES AND GUIDELINES -----------------------";
    cout << endl << endl;
    cout << "All of the cards must have a mate (pairs).";
    cout << endl;
    cout << endl;
    
    cout << "Each turn, two cards are flipped over.  If the cards do not match, they are both turned back face down.  If the cards match, they are left face up and the person who made the match receives a point.";
    cout << endl;
    cout << endl;
    
    cout << "With a regular deck of cards, the pair is considered the card with the same color and number (so the ace of hearts matches the ace of diamonds).";
    cout << endl;
    cout << endl;
    
    cout << "Concentration can be played with regular playing cards or with special themed cards.  It can be played by 1, 2, 3 or 4 people.  More than 4 people can be divided into teams.";
    cout << endl;
    cout << endl;
    cout << endl;
    
    pressEnter();
    
}
コード例 #4
0
int main(int argc, char **argv) {
	// Intialize ROS with this node name
	ros::init(argc, argv, "ex4_cartesian_vel_control");
	
	ros::NodeHandle n;
	segbot_arm_manipulation::Mico mico(n);

	//publish cartesian tool velocities
	ros::Publisher pub_velocity = n.advertise<kinova_msgs::PoseVelocity>("/m1n6s200_driver/in/cartesian_velocity", 10);
	
	//register ctrl-c
	signal(SIGINT, sig_handler);

	pressEnter("Press [Enter] to move hand up and down");
	
	//construct message
	kinova_msgs::PoseVelocity cartesian_vel;
	cartesian_vel.twist_linear_x = 0.0;
	cartesian_vel.twist_linear_y = 0.0;
	cartesian_vel.twist_linear_z = 0.2;
	cartesian_vel.twist_angular_x = 0.0;
	cartesian_vel.twist_angular_y = 0.0;
	cartesian_vel.twist_angular_z = 0.0;

	double duration = 1.0;
	double elapsed_time = 0.0;
	
	double pub_rate = 100.0;
	ros::Rate r(pub_rate);
	
	while (ros::ok()){
		//collect messages
		ros::spinOnce();
		
		//publish velocity message
		pub_velocity.publish(cartesian_vel);
		
		r.sleep();
		
		elapsed_time += (1.0/pub_rate);
		
		if (elapsed_time > duration)
			break;
	}


	// Be sure to manually stop or we'll overshoot
	cartesian_vel.twist_linear_z = 0.0;
	pub_velocity.publish(cartesian_vel);

	// Now with much less code
	cartesian_vel.twist_linear_z = -0.2;
	mico.move_with_cartesian_velocities(cartesian_vel, 1);

	

	//the end
	ros::shutdown();
}
コード例 #5
0
ファイル: main.cpp プロジェクト: thenonameguy/adsaday
int main()
{
	Queue q;
	q.enqueue(10);
	q.enqueue(4);
	q.enqueue(6);
	printf("Size of queue: %i\n",q.getSize());
	q.display();
	pressEnter();
	printf("Dequeueing.\n");
	q.dequeue();
	printf("Size of queue: %i\n",q.getSize());
	q.display();
	pressEnter();
	printf("That's all folks!\n");
	return 0;
}
コード例 #6
0
void ShutdownManager::initConnect()
{
    connect(this, SIGNAL(DirectKeyLeft()) , m_content, SIGNAL(OutKeyLeft()));
    connect(this, SIGNAL(DirectKeyRight()), m_content, SIGNAL(OutKeyRight()));
    connect(this, SIGNAL(pressEnter()), m_content, SIGNAL(pressEnterAction()));

    connect(m_content->m_shutdownFrame, &ShutDownFrame::ShutDownFrameActions, this, &ShutdownManager::powerAction);
//    connect(qApp, &QApplication::aboutToQuit, [this]{
//        m_hotZoneInterface->EnableZoneDetected(true);
//    });
}
コード例 #7
0
void ShutdownManager::keyPressEvent(QKeyEvent *e)
{

    switch (e->key()) {
    case Qt::Key_Escape:        hideToplevelWindow(); break; // must break;
    case Qt::Key_Return:        /* same as enter */
    case Qt::Key_Enter:         emit pressEnter();              break;
    case Qt::Key_Left:          emit DirectKeyLeft();           break;
    case Qt::Key_Right:         emit DirectKeyRight();          break;
    default:;
    }
}
コード例 #8
0
/*************************************************************
 * Function: printGameRules ()                               *
 * Date Created: September 29, 2012                          *
 * Date Last Modified: September 30, 2012                    *
 * Description: This function clears the screen then jprints *
 *              the title of the game and prints the rules   *
 *              on how to play the game.                     *
 * Input parameters: void                                    *
 * Returns: void                                             *
 * Preconditions: system () is part of the compiler's        *
 *                library and user using Windows OS          *
 * Postconditions: User understand the rules of the game     *
 *************************************************************/
void printGameRules (void)
{
	system ("cls");
	printTitle ();
	printf ("              HOW TO PLAY\n");
	printf ("> Player rolls two dice\n");
	printf ("> After the dice have come to rest, the\n  sum of the spots on the two upward faces\n  is calculated.\n");
	printf ("> If the sum is 7 or 11 on the first throw,\n  the PLAYER WINS!\n");
	printf ("> If the sum is 2, 3 or 12 on the first\n  throw, CRAPS... The PLAYER LOSES!\n");
	printf ("> If the sum is 4, 5, 6, 8, 9, or 10 on\n  the first throw, then the sum becomes\n  the PLAYER'S POINT.\n");
	printf ("> To win, you must continue rolling the\n  dice until you make your POINT. The\n  player loses by rolling a 7 before\n  making the point.\n");
	printf ("       <Press ENTER to continue>");
	pressEnter ();
}
コード例 #9
0
ファイル: main.cpp プロジェクト: thenonameguy/adsaday
int main()
{
	Stack s;
	printf("Populating stack...\n");
	s.push(10);
	s.push(15);
	s.push(3);
	printf("Populated.\n");
	s.display();
	pressEnter();
	printf("Popping...\n");
	s.pop();
	s.display();
	printf("That's all folks!\n");
	return 0;
}
コード例 #10
0
ファイル: concentration.cpp プロジェクト: davemachado/Games
int playConcentrationTurn(Card board [], int & currentPlayer)
{
    int num1 = 0, num2 = 0;
    
    cout << endl << endl << endl;
    drawBoardNum(num1, num1, board);
    cout << endl << endl << endl;
    
    cout << "------------- Player " << currentPlayer << " -------------" << endl << endl;
    cout << "Please enter a space to view card: ";
    cin >> num1;
    cout << "Please enter another space: ";
    cin >> num2;
    
    clearScreen();
    
    Card card1 = board[num1], card2 = board[num2];
    
    if(ifCardsMatch(card1, card2)){
        drawBoardNum(num1, num2, board);
        cout << "Good job! The ";
        displayCard(card1);
        cout << " matches the ";
        displayCard(card2);
        cout << "! Go again!" << endl;
        if(currentPlayer == 1) currentPlayer = 1;
        else currentPlayer = 2;
        
        board[num1 - 1].inDeck = false;
        board[num2 - 1].inDeck = false;
        cout << endl << endl;
        pressEnter();
    }
    else{
        drawBoardNum(num1, num2, board);
        cout << "Too bad! The ";
        displayCard(card1);
        cout << " does not match the ";
        displayCard(card2);
        if(currentPlayer == 1) currentPlayer = 2;
        else currentPlayer = 1;
        usleep(3000000);
    }
    return 0;
}
コード例 #11
0
ファイル: concentration.cpp プロジェクト: davemachado/Games
void playConcentration()
{
    int currentPlayer = 1;
    
    Card deck[DECK_SIZE];
    Card board[CONCEN_DECK_SIZE];
    initDeck(deck);
    initConcentrationDeck(deck, board);
    
    for(;;)
    {
        clearScreen();
        cout << "-- Player " << currentPlayer << " 's Turn --" << endl;
        pressEnter();
        clearScreen();
        playConcentrationTurn(board, currentPlayer);
    }
}
コード例 #12
0
/*************************************************************
 * Function: playAgain ()                                    *
 * Date Created: September 29, 2012                          *
 * Date Last Modified: September 30, 2012                    *
 * Description: This function prints out the current balance *
 *              and prompts player to play more or not.      *
 * Input parameters: player's current balance on hand        *
 * Returns: status indicator, 1 for play more & 0 otherwise  *
 * Preconditions: current balance is not equal to zero,      *
 *                function should not be called if player    *
 *                does not have any money on hand            *
 * Postconditions: Status indicator returned                 *
 *************************************************************/
int playAgain (double currentBalance)
{
	char ch = '\0';        /* input for Y/N option */
	int playMore = -1;	   /* status indicator to play again */

	do {
		/* clears the screen */
		system ("cls");

		/* prints title on top of the screen */
		printTitle ();

		/* prints current balance */
		printf ("Current Balance: $%.2lf\n", currentBalance);

		/* prompts user if he wants to play more or not */
		printf ("Do you want to play more (Y/N)? ");
		fflush (stdin);  /* flushes previous escape characters */
		scanf ("%c", &ch);

		if (ch == 'y' || ch == 'Y')
		{
			/* indicates player chooses to play more */
			playMore = TRUE;
		}
		else if (ch == 'n' || ch == 'N')
		{
			/* indicates player doesn't want to play any more */
			playMore = FALSE;
		}
		else
		{
			/* warns user of invalid input */
			printf ("Invalid Input! Press ENTER to continue.\n");
			pressEnter ();
		}

	} while (playMore == -1);

	return playMore;
}
コード例 #13
0
ファイル: test_threads.c プロジェクト: animotron/animos
static void thread1(void *a)
{
    char *name = a;
    while(!thread_stop_request)
    {
        thread_activity_counter++;

        if(TEST_CHATTY) printf("--- thread %s runs ---\n", name);
        pressEnter("");

        if(TEST_CHATTY) printf("Will lock mutex\n");
        hal_mutex_lock(&m);
        if(TEST_CHATTY) printf("locked mutex\n");
        checkEnterMutex();
        YIELD();
        if(TEST_CHATTY) printf("Will unlock mutex\n");
        checkLeaveMutex();
        hal_mutex_unlock(&m);
        if(TEST_CHATTY) printf("unlocked mutex\n");

        if( random() & 1 )
            hal_sem_acquire( &s );

        counter++;
        if(counter >7)
        {
            counter = 0;
            if(TEST_CHATTY) printf("Will signal cond\n");
            hal_cond_signal(&c);
            if(TEST_CHATTY) printf("Signalled cond\n");
        }
        YIELD();

    }
    FINISH();
}
コード例 #14
0
ファイル: main.cpp プロジェクト: Andy11235813/GNUPlot
int main(int argc, char* argv[])
{
	g_clockFrequency = getCpuClockFrequencyMHz()*(1000000);
	long long startTime, endTime;

	/* Create gnuplotinterface class object */
	GNUPlotInterface gpi;

	/* Create the read/write pipes */
	gpi.CreatePipes();
	/* Start the gnuplot.exe process with rerouted input/output using pipes */
	gpi.StartProcess();
	/* This is the intialization of realtime plotting as well as title and 
	*	line type. Be sure to use \" to send the " character. */
	std::string gnuplotOutput = gpi.Init("lines","GNUplot Pipe Interface Test");
	std::cout<<"Initialization - gnuplot output:\n"<<gnuplotOutput.c_str()<<std::endl;
	Sleep(1000);	//Just to slow it down so user can read message

	std::cout<<std::endl<<"Test1: simple plotting [y=x^2]."<<std::endl;
	startTime = GetCpuClocks();
	gnuplotOutput = gpi.Plot("1 1\n2 4\n3 9\n4 16\n5 25\n6 36\n7 49\n8 64\n9 81\n10 100\n",0);
	endTime = GetCpuClocks();
	std::cout<<"Test1 - gnuplot output:\n"<<gnuplotOutput.c_str()<<std::endl;
	std::cout<<"Test1 time taken = "<<((double)endTime-startTime)/g_clockFrequency<<std::endl;
	pressEnter();

	std::cout<<std::endl<<"Test2: vector of doubles data plot [y=sqrt(x)]."<<std::endl;
	const int dims = 2;
	const int length = 200;
	std::vector<double> values[dims];
	values[0].resize(length);
	values[1].resize(length);
	for(int i = 0; i<length; i++){
		values[0][i] = (double) i;
		values[1][i] = sqrt((double) i);
	}
	startTime = GetCpuClocks();
	gnuplotOutput = gpi.Plot(values,dims,length);
	endTime = GetCpuClocks();
	std::cout<<"Test2 - gnuplot output:\n"<<gnuplotOutput.c_str()<<std::endl;
	std::cout<<"Test2 time taken = "<<((double)endTime-startTime)/g_clockFrequency<<std::endl;
	pressEnter();

	/*RTLength: Real-time data length - this value used for similar comparison of 
	*	different real-time plot methods */
	const int RTLength = 300; 
	std::cout<<std::endl<<"Test3: \"realtime\" fast char array data plot [y=sin(sqrt(x))]."<<std::endl;
	std::cout<<"Test3 - gnuplot output:"<<std::endl;
	std::string input;
	long long diffTime = 0;
	for(int i = 0; i<RTLength; i++){
		double dVal = sin(sqrt((double) i));
		Sleep(30);
		CHAR chVal[20];
		sprintf(chVal,"%d",i); input.append(chVal); input.append(" ");
		sprintf(chVal,"%.5f",dVal);	input.append(chVal); input.append("\n");
		startTime = GetCpuClocks();
		gnuplotOutput = gpi.Plot(input.c_str(),0);
		endTime = GetCpuClocks();
		diffTime += (endTime - startTime);
		if(gnuplotOutput.length() > 0)
			std::cout<<gnuplotOutput.c_str()<<std::endl;
	}
	double ddiffTime = (double) diffTime;
	std::cout<<"Test3 time taken = "<<ddiffTime/(double)g_clockFrequency<<std::endl;
	pressEnter();

	std::cout<<std::endl<<"Test4: \"realtime\" vector of doubles data plot [y=sin(sqrt(x))]."<<std::endl;
	std::cout<<"Test4 - gnuplot output:"<<std::endl;
	input.clear();
	diffTime = 0;
	std::vector<double> dVals[2];
	dVals[0].resize(RTLength);
	dVals[1].resize(RTLength);
	for(int i = 0; i<RTLength; i++){
		dVals[0][i] = (double) i;
		dVals[1][i] = sin(sqrt((double) i));
		startTime = GetCpuClocks();
		gnuplotOutput = gpi.Plot(dVals,2,i);
		endTime = GetCpuClocks();
		diffTime += (endTime - startTime);
		if(gnuplotOutput.length() > 0)
			std::cout<<gnuplotOutput.c_str()<<std::endl;
	}
	ddiffTime = (double) diffTime;
	std::cout<<"Test4 time taken = "<<ddiffTime/g_clockFrequency<<std::endl;
	std::cout<<std::endl<<"*** end of gnuplot tests ***"<<std::endl;
	pressEnter();

	std::cout<<std::endl<<"Test5: \"realtime\" x-array/y-array data plot [y=sin(sqrt(x))]."<<std::endl;
	std::cout<<"Test5 - gnuplot output:"<<std::endl;
	input.clear();
	diffTime = 0;
	double xVal[RTLength];
	double yVal[RTLength];
	for(int i = 0; i<RTLength; i++){
		xVal[i] = (double) i;
		yVal[i] = sin(sqrt((double) i));
		startTime = GetCpuClocks();
		gnuplotOutput = gpi.Plot(xVal,yVal,i);
		endTime = GetCpuClocks();
		diffTime += (endTime - startTime);
		if(gnuplotOutput.length() > 0)
			std::cout<<gnuplotOutput.c_str()<<std::endl;
	}
	ddiffTime = (double) diffTime;
	std::cout<<"Test5 time taken = "<<ddiffTime/g_clockFrequency<<std::endl;
	pressEnter();

	std::cout<<std::endl<<"Test6: \"realtime\" y-array (no x-array) data plot [y=sin(sqrt(x))]."<<std::endl;
	std::cout<<"Test6 - gnuplot output:"<<std::endl;
	input.clear();
	diffTime = 0;
	for(int i = 0; i<RTLength; i++){
		yVal[i] = sin(sqrt((double) i));
		startTime = GetCpuClocks();
		gnuplotOutput = gpi.Plot(yVal,i);
		endTime = GetCpuClocks();
		diffTime += (endTime - startTime);
		if(gnuplotOutput.length() > 0)
			std::cout<<gnuplotOutput.c_str()<<std::endl;
	}
	ddiffTime = (double) diffTime;
	std::cout<<"Test6 time taken = "<<ddiffTime/g_clockFrequency<<std::endl;

	std::cout<<std::endl<<"*** end of gnuplot tests ***"<<std::endl;
	pressEnter();

	/* Close all the handles to pipes, process and thread as well as sending 
	*	"quit" command to gnuplot.exe */
	gpi.CloseAll();
	return 0;
}
コード例 #15
0
/*************************************************************
 * Function: play ()                                         *
 * Date Created: September 29, 2012                          *
 * Date Last Modified: September 30, 2012                    *
 * Description: This function is the main function called to *
 *              start a game of craps.                       *
 * Input parameters: void                                    *
 * Returns: void                                             *
 * Preconditions: User knows the rules of the game of craps  *
 * Postconditions: User has doesn't want to continue playing *
 *                 or player is bankrupt.                    *
 *************************************************************/
void play (void)
{
	int dieOne = 0, dieTwo = 0,     /* values for two dice */
		sumDice = 0,                /* sum of two dice */
		playerPoint = 0,            /* player's point */
		gameStatus = 0,             /* status of game */
		numberOfRolls = 0,          /* tracks number of rolls */
		playMore = 0;               /* status indicator for more game */

	double initialBankBalance = 0.0,	/* value for initial bank balance */
		   balance = 0.0,               /* value for current bank balance */
		   wager = 0.0;                 /* value for wager or bet */


	/* Prompts user for inital bank balance */
	initialBankBalance = getBankBalance ();
	balance = initialBankBalance;
	
	do
	{
		do
		{
			/* Before each rool, prompt user for a wager */
			wager = getWagerAmount ();
		} while (!(checkWagerAmount (wager, balance)));


		/* A player rolls two dice. */
		printf ("<Press ENTER to roll the dice>");
		pressEnter ();

		/* Gets two random values from 1-6, and are 
		   saved on the variables dieOne and dieTwo */
		dieOne = rollDie ();
		dieTwo = rollDie ();

		/* Shows in the screen two animated die and 
		   then the the actual values of the dice */
		animateDices (dieOne, dieTwo);

		/* After the dice have come to rest, the sum 
		   of the spots on the two upward faces is 
		   calculated. */
		sumDice = calculateSumDice (dieOne, dieTwo);

		switch (isWinLossOrPoint (sumDice))
		{
			case WINS:
				/* If the sum is 7 or 11 on the first throw, 
				   the player wins. */
				gameStatus = WINS;
				break;

			case POINT:
				/* If the sum is 4, 5, 6, 8, 9, or 10 on the 
				   first throw, then the sum becomes the player's 
				   "point." */
				gameStatus = POINT;
				playerPoint = sumDice;

				do
				{
					/* Prompts player to roll die until player gets the point or craps */
					printf ("Continue rolling the dice until you get a sum of %d\n", playerPoint);
					printf ("<Press ENTER to roll the dice>");
					pressEnter ();

					/* gets two random values for dieOne and dieTwo */
					dieOne = rollDie ();
					dieTwo = rollDie ();

					/* animates two dice on the screen */
					animateDices (dieOne, dieTwo);

					/* gets the sum of the two dice */
					sumDice = calculateSumDice (dieOne, dieTwo);

					/* checks if user wins, craps or neither */
					gameStatus = isPointLossOrNeither (sumDice, playerPoint);

				} while (gameStatus == POINT);

				break;

			case CRAPS:
				/* If the sum is 2, 3, or 12 on the first throw 
				   (called "craps"), the player loses (i.e. the 
				   "house" wins). */
				gameStatus = CRAPS;
				break;
		}

		/* Once a game is loss or won, the bank 
		   balance should be adjusted. */
		balance = adjustBankBalance (balance, wager, gameStatus);
		
		/* Keeps track of the number of plays */
		numberOfRolls++;

		/* Prints out messages on screen */
		chatterMessages (numberOfRolls, gameStatus, initialBankBalance, balance);
		printf ("<Press ENTER to continue>");
		pressEnter ();

		if (balance > 0)
		{
			/* If balance is greater than 0,
			   Prompts player to play more or not */
			playMore = playAgain (balance);
		}
		else
		{
			playMore = 0;
		}

	} while (playMore);
	
}