Exemple #1
0
int main() 
{
	char inp;
	ClearTick();

	result = BrickPiSetup();
	// printf("BrickPiSetup: %d\n", result);
	if(result)
	return 0;

	BrickPi.Address[0] = 1;
	BrickPi.Address[1] = 2;

	motor1=PORT_B;	//Select the ports to be used by the motors
	motor2=PORT_C; 
	BrickPi.MotorEnable[motor1] = 1;	//Enable the motors
	BrickPi.MotorEnable[motor2] = 1;
	result = BrickPiSetupSensors();		//Set up the properties of sensors for the BrickPi
	//printf("BrickPiSetupSensors: %d\n", result); 
	BrickPi.Timeout=3000;				//Set timeout value for the time till which to run the motors after the last command is pressed
	BrickPiSetTimeout();				//Set the timeout
	if(!result)
	{
		while(1)
		{
			scanf("%c",&inp);		//Take input from the terminal
			move_bot(inp);			//Move the bot
			if(inp=='t')			//Increase the speed
			{
				printf("Speed: %d\n",speed);
				if(speed >234)
					speed=255;
				else
					speed=speed+10;
				move_bot(cmd);		//call move_bot() to update the motor values
			}
			else if(inp=='g')		//Decrease the speed
			{
				printf("Speed: %d\n",speed);
				if(speed<11)
					speed=0;
				else
					speed=speed-10;
				move_bot(cmd);
			}
			BrickPiUpdateValues();	//Update the motor values
			usleep(10000);			//sleep for 10 ms
		}
	}
	return 0;
}
Exemple #2
0
int	check_axe(t_terrain* button, t_terrain* terrain)
{
    if (check_left(button, terrain))
    {
        move_left(button, terrain);
        return (1);
    }
    else if (check_right(button, terrain))
    {
        move_right(button, terrain);
        return (1);
    }
    else if (check_top(button, terrain))
    {
        move_top(button, terrain);
        return (1);
    }
    else if (check_bot(button, terrain))
    {
        move_bot(button, terrain);
        return (1);
    }
    return (0);
}
//Main Function
int main()
{
	init_devices();
	init_encoders();
	lcd_set_4bit();
	lcd_init();
	int value=0;
	forward();
	velocity(130,130);
	lcd_print(2,1,130,3);
	lcd_print(2,5,130,3);
	lcd_print(2,9,pathindex,2);
	lcd_print(2,13,dirn,3);


	while(1)
	{	
		read_sensor();
		follow();
		
		if(isPlus())
		{	
			read_sensor();
			value = path[pathindex++];
			
			// Code inserted for calculation of actual location wrt initial starting point , 
			// It will consider direction also.

			if (value == F)
			{
				// Move the bot forward, for location only , No movement on ground.
				move_bot(FR);
			}
			else if (value == L)
			{
				// Move the bot left , for location only , No movement on ground.
				move_bot(LT);
			}
			else if (value == R)
			{
				// Move the bot right, for location only , No movement on ground.
				move_bot(RT);
			}
			else if (value == M)
			{
				// To stop the Bot and then break out
				stop();
				break;
			}
					
			orient(value);

/*			lcd_print(2,9,pathindex,2);
			lcd_print(2,13,dirn,3);
			lcd_print(1,13,turnL,1);
			lcd_print(1,15,turnR,1);
*/
			
		}
		
		if(turnL == 1)
		{/*
		lcd_print(1,13,turnL,1);
		forward_mm(20);
		stop();
		velocity(180,180);
		left_degrees(95);
		//_delay_ms(120);
		read_sensor();
		//	 while(Left_white_line <0x40)
		// {
		//	read_sensor();
		//	left();
		// }
		 stop();
	 	 forward();
		velocity(180,180);
		 turnL = 0;
		 */

		 back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		left_degrees(50);
		rotate_left_slowly();
	 	forward();
		velocity(130,130);
		turnL = 0;
		}
		
		if(turnR == 1)
		{
		/*
		lcd_print(1,15,turnR,1);
		forward_mm(20);
		stop();
		velocity(180,180);
		right_degrees(95);
		//_delay_ms(200);
		read_sensor();
		// while(Right_white_line <0x30)
		// {
		// read_sensor();
		// right();
		// }
		stop();
		forward();
		//follow();
		velocity(180,180);
		 turnR = 0;
		*/

		back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		right_degrees(50);
		rotate_right_slowly();
	 	forward();
		velocity(130,130);
		turnR = 0;
		}
	
	}


	// Three Beeps for Interval
	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	//code to head-back to starting position , i.e. Origin
	return_path_counter = reach_origin();
	
	forward();
	velocity(130,130);
	int counter = 0;
	int intermediate_value = 0;

	while(counter < return_path_counter)
	{	
		read_sensor();
		follow();
		
		if(isPlus())
		{	
			read_sensor();
			value = path_to_origin[counter];
			counter++;
			
			// Code inserted for calculation of actual location wrt initial starting point , 
			// It will consider direction also.

			if (intermediate_value == FR)
			{
				// Move the bot forward, for location only , No movement on ground.
				value = F;
			}
			else if (value == LT)
			{
				// Move the bot left , for location only , No movement on ground.
				value = L;
			}
			else if (value == RT)
			{
				// Move the bot right, for location only , No movement on ground.
				value = R;
			}
			else if (value == ST)
			{
				value = M;
				// specially inserted as break will not allow the bot to stop using "orient(value)".
				orient(value);
				break;
			}
					
			orient(value);
		
		}
		
		if(turnL == 1)
		{
		 back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		left_degrees(50);
		rotate_left_slowly();
	 	forward();
		velocity(130,130);
		turnL = 0;
		}
		
		if(turnR == 1)
		{
		back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		right_degrees(50);
		rotate_right_slowly();
	 	forward();
		velocity(130,130);
		turnR = 0;
		}
	
	}


	// Three beeps for Finish
	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

}
void run(void)
{
    data='w';
    while(1)
    {
        while(data == 'w') //waiting for signal
        {
        }
        while(data == '\0' )
        {
            stop();
            _delay_ms(4000);
            comintersection();
            _delay_ms(100);
        }
        if(data=='f') // forward
        {
            data='\0';
        }
        if(data=='r') // right
        {
            data='\0';
            turn_right();
        }
        if(data=='l') // left
        {
            data='\0';
            turn_left();
        }
        if(data == 'h') // halt
        {
            data='\0';
            stop();
            _delay_ms(100);
            continue;

        }
        if(data == 'o') // origin
        {
            data='w';
            stop();
            _delay_ms(100);
            continue;
        }
        if(data == 'c') //collect item data -> i when the bot is trying to pick up an rfid
        {
            data='w';
            arm_down();
            _delay_ms(4200);
            stop_arm();
            _delay_ms(2000);
            grab();
            arm_up();
            _delay_ms(4750);
            stop_arm();
            _delay_ms(2000);
            lcd_cursor(2,1);
            lcd_string("Collecting");
            _delay_ms(3500);
            readrfidtag();
            clearrfid();
            continue;

        }
        if(data == 'd') //drop_item
        {
            data='w';
            go_down();
            release();
            go_up();
            lcd_cursor(2,1);
            lcd_string("Dropping");
            _delay_ms(3500);
            senddroppedsig();
            continue;
        }

        while(1)
        {
            if(move_bot() == 1)
            {
                continue;
            }
            else
            {
                break;
            }
        }
    }
}