void rob_serial_set_baud_rate_usb_comm (unsigned long baud)
{
    vTaskSuspendAll();
    {
        serial_set_baud_rate (USB_COMM, baud);
    }
    xTaskResumeAll();
}
Exemple #2
0
int main()
{
	clear();	// clear the LCD
	print("Send serial");
	lcd_goto_xy(0, 1);	// go to start of second LCD row
	print("or press B");

	// Set the baud rate to 9600 bits per second.  Each byte takes ten bit
	// times, so you can get at most 960 bytes per second at this speed.
	serial_set_baud_rate(USB_COMM, 9600);

	// Start receiving bytes in the ring buffer.
	serial_receive_ring(USB_COMM, receive_buffer, sizeof(receive_buffer));

    while(1)
    {
		// USB_COMM is always in SERIAL_CHECK mode, so we need to call this
		// function often to make sure serial receptions and transmissions
		// occur.
		serial_check();

		// Deal with any new bytes received.
		check_for_new_bytes_received();

		// If the user presses the middle button, send "Hi there!"
		// and wait until the user releases the button.
		if (button_is_pressed(MIDDLE_BUTTON))
		{
			wait_for_sending_to_finish();
			memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
			serial_send(USB_COMM, send_buffer, 11);
			send_buffer[11] = 0;	// terminate the string
			clear();				// clear the LCD
			lcd_goto_xy(0, 1);		// go to start of second LCD row
			print("TX: ");
			print(send_buffer);

			// Wait for the user to release the button.  While the processor is
			// waiting, the OrangutanSerial library will not be able to receive
			// bytes from the USB_COMM port since this requires calls to the
			// serial_check() function, which could cause serial bytes to be
			// lost.  It will also not be able to send any bytes, so the bytes
			// bytes we just queued for transmission will not be sent until
			// after the following blocking function exits once the button is
			// released.  If any of this is a concern, you can replace the
			// following line with:
			// do
			// {
			//   while (button_is_pressed(MIDDLE_BUTTON))
			//     serial_check();	// receive and transmit as needed
			//   delay_ms(10);		// debounce the button press/release
			// }
			// while (button_is_pressed(MIDDLE_BUTTON));
			wait_for_button_release(MIDDLE_BUTTON);
		}
    }
}
Exemple #3
0
int main() {
    serial_set_baud_rate(BAUD);
    
    int distanceRead;
    
    while(1) {
    	set_m1_speed(255/4);
	set_m2_speed(255/4);
	MOS2
	MOS4
    }
    return 0;
}
Exemple #4
0
void initialize()
{
	play_from_program_space(welcome);

#ifdef DEBUG
	// start receiving data at 9600 baud.
	serial_set_baud_rate(9600);
	serial_receive_ring(buffer, 100);
#endif

	// initialize your QTR sensors
	//  unsigned char qtr_rc_pins[] = {IO_C0, IO_C1, IO_C2};
//	unsigned char qtr_rc_pins[] = {IO_C0, IO_C1, IO_C2, IO_C3, IO_C4, IO_C5, IO_D7, IO_D4};
	unsigned char qtr_rc_pins[] = {IO_D4, IO_D7, IO_C5, IO_C4, IO_C3, IO_C2, IO_C1, IO_C0};
	qtr_rc_init(qtr_rc_pins, 8, 2000, IO_D2);  // 800 us timeout, emitter pin PD2

#ifdef DEBUG
	serial_send_blocking("Press Button A to start calibrating...\n", 39);
#endif
	wait_for_button_press(BUTTON_A);
	// Always wait for the button to be released so that the robot doesn't
	// start moving until your hand is away from it.
	wait_for_button_release(BUTTON_A);
	delay_ms(800);

	// then start calibration phase and move the sensors over both
	// reflectance extremes they will encounter in your application:
	// We use a value of 2000 for the timeout, which
	// corresponds to 2000*0.4 us = 0.8 ms on our 20 MHz processor.
	unsigned int counter; // used as a simple timer
	for(counter = 0; counter < 82; counter++)
	{
		if(counter < 20 || counter >= 60)
			set_motors(60,-60);
		else
			set_motors(-60,60);

		qtr_calibrate(QTR_EMITTERS_ON);

		// Since our counter runs to 80, the total delay will be
		// 80*20 = 1600 ms.
		delay_ms(20);
	}
	set_motors(0,0);

#ifdef DEBUG
	serial_send_blocking("Press Button A to start line following...\n", 42);
#endif
	wait_for_button_press(BUTTON_A);
	wait_for_button_release(BUTTON_A);
}
Exemple #5
0
/*
 * Initialize the menuing system
 */
int cli_init(void)
{
    // Set the baud rate to 9600 bits per second.  Each byte takes ten bit
    // times, so you can get at most 960 bytes per second at this speed.
    serial_set_baud_rate(USB_COMM, 9600);
    serial_set_mode(USB_COMM, SERIAL_CHECK);
    serial_receive_ring(
            USB_COMM, g_receive_buffer.ring_buffer,
            sizeof(g_receive_buffer.ring_buffer));
    LOG("USB Serial Initialized\r\n");
    LOG("#> ");
    CLI_REGISTER({"?", "Show Commands", clicmd_show_commands});
    return 0;
}
Exemple #6
0
void serial_init( )
{
	// Set the baud rate to 9600 bits per second.  Each byte takes ten bit
	// times, so you can get at most 960 bytes per second at this speed.
	serial_set_baud_rate(USB_COMM, 9600);

	// Start receiving bytes in the ring buffer.
	serial_receive_ring(USB_COMM, receive_buffer, sizeof(receive_buffer));
	
	memset( my_received_buffer, 0, sizeof(my_received_buffer));
	
	serial_print_string( "USB Serial Initialized" );
	serial_print_string( "" );
	print_menu();
}
Exemple #7
0
//------------------------------------------------------------------------------------------
// Initialize serial communication through USB and print menu options
// This immediately readies the board for serial comm
void init_menu() {
	
	//char printBuffer[32];
	
	// Set the baud rate to 9600 bits per second.  Each byte takes ten bit
	// times, so you can get at most 960 bytes per second at this speed.
	serial_set_baud_rate(USB_COMM, 9600);

	// Start receiving bytes in the ring buffer.
	serial_receive_ring(USB_COMM, receive_buffer, sizeof(receive_buffer));

	//memcpy_P( send_buffer, PSTR("USB Serial Initialized\r\n"), 24 );
	//snprintf( printBuffer, 24, "USB Serial Initialized\r\n");
	//print_usb( printBuffer, 24 );
	print_usb( "\r\n\nUSB Serial Initialized\r\n" );

	//memcpy_P( send_buffer, MENU, MENU_LENGTH );
	print_usb( MENU );
}
Exemple #8
0
/*==========la fonction main()=======*/
int main(void) {

    lcd_init_printf();
    pololu_3pi_init(2000);  
    play_mode(PLAY_CHECK);
    clear();
    print("Hello!");
    play("L16 ceg>c");
    // start receiving data at 9600 baud
    serial_set_baud_rate(9600);
    serial_receive_ring(buffer, 100);
      
    int i=0;
    char dirct,chaine[4], comp='C',*recuper = NULL, *ok;
    long val, veri=0;
    char command;
	/* la boucle qui permet de recuperer la trame caractere par caractere */
    while(1){
	
        for(i=0;i<4;i++){
            command = read_next_byte();
            if (command)
            {
                chaine[i] = command;
            }
        }
         /*recuperation de la lettre recu dans la trame */ 
        dirct = chaine[0];
        
        /*recuperation du reste de la trame en chaine de caractere */
        recuper = strchr(chaine,chaine[1]);
        
        /*conversion de cette chaine recuperer en entier (type long)*/
        val = strtol(recuper, &ok,10);
        
	    /* cette condition permet d'eviter l'execution de la meme trame plusieurs fois*/        
        if(dirct != comp || veri != val)
        {
        clear();
        printf("%s",chaine);
        switch(dirct)
        {
            case 'A':
                avancer(val);
                break;
            case 'R':
                reculer(val);
                break;
            case 'D':
                droit(val);
                break;
            case 'G':
                gauche(val);
                break;
            case 'M':
                melodie();
                break;
            default:
                set_motors(0,0);
                break;
            }
            comp = dirct;
            veri = val;
        }
    }
return 0;
}
Exemple #9
0
int main()
{
	pololu_3pi_init(2000);  
	play_mode(PLAY_CHECK);
	clear();

	// start receiving data at 115.2 kbaud
	serial_set_baud_rate(115200);
	serial_receive_ring(buffer, 100);

	while(1)
	{
		// wait for a command
		char command = read_next_byte();

		// The list of commands is below: add your own simply by
		// choosing a command byte and introducing another case
		// statement.
		switch(command)
		{
		case (char)0x00:
			// silent error - probable master resetting
			break;

		case (char)0x81:
			send_signature();
			break;
		case (char)0x86:
			send_raw_sensor_values();
			break;
		case (char)0x87:
			send_calibrated_sensor_values(1);
			break;
		case (char)0xB0:
			send_trimpot();
			break;
		case (char)0xB1:
			send_battery_millivolts();
			break;
		case (char)0xB3:
			do_play();
			break;
		case (char)0xB4:
			calibrate_line_sensors(IR_EMITTERS_ON);
			send_calibrated_sensor_values(1);
			break;
		case (char)0xB5:
			line_sensors_reset_calibration();
			break;
		case (char)0xB6:
			send_line_position();
			break;
		case (char)0xB7:
			do_clear();
			break;
		case (char)0xB8:
			do_print();
			break;
		case (char)0xB9:
			do_lcd_goto_xy();
			break;
		case (char)0xBA:
			auto_calibrate();
			break;
		case (char)0xBB:
			set_pid();
			break;
		case (char)0xBC:
			stop_pid();
			break;

		case (char)0xC1:
			m1_forward();
			break;
		case (char)0xC2:
			m1_backward();
			break;
		case (char)0xC5:
			m2_forward();
			break;
		case (char)0xC6:
			m2_backward();
			break;

		default:
			clear();
			print("Bad cmd");
			lcd_goto_xy(0,1);
			print_hex_byte(command);

			play("o7l16crc");
			continue; // bad command
		}
	}
}
Exemple #10
0
int main()
{
	char buffer[20];

	// load the bar graph
	load_custom_characters();

	// configure serial clock for 115.2 kbaud
	serial_set_baud_rate(115200);

	// wait for the device to show up
	while(1)
	{
		clear();
		print("Master");
		delay_ms(100);
		serial_send("\x81",1);

		if(serial_receive_blocking(buffer, 6, 50))
			continue;
		
		clear();
		print("Connect");
		lcd_goto_xy(0,1);
		buffer[6] = 0;
		print(buffer);

		// clear the slave's LCD and display "Connect" and "OK" on two lines
		// Put OK in the center to test x-y positioning
		slave_clear();
		slave_print("Connect");
		slave_lcd_goto_xy(3,1);
		slave_print("OK");

		// play a tune
		char tune[] = "\xB3 l16o6gab>c";
		tune[1] = sizeof(tune)-3;
		serial_send_blocking(tune,sizeof(tune)-1);

		// wait
		wait_for_button(ANY_BUTTON);

		// reset calibration
		slave_reset_calibration();
		
		time_reset();

		slave_auto_calibrate();

		unsigned char speed1 = 0, speed2 = 0;

		// read sensors in a loop
		while(1)
		{
			serial_send("\x87",1); // returns calibrated sensor values
      
			// read 10 characters
			if(serial_receive_blocking(buffer, 10, 100))
				break;

			// get the line position
			serial_send("\xB6", 1);

			int line_position[1];
			if(serial_receive_blocking((char *)line_position, 2, 100))
				break;

			// get the battery voltage
						serial_send("\xB1",1);
      
			// read 2 bytes
			int battery_millivolts[1];
			if(serial_receive_blocking((char *)battery_millivolts, 2, 100))
				break;

			// display readings
			display_levels((unsigned int*)buffer);

			lcd_goto_xy(5,0);
			line_position[0] /= 4; // to get it into the range of 0-1000
			if(line_position[0] == 1000)
				line_position[0] = 999; // to keep it to a maximum of 3 characters 
			print_long(line_position[0]);
			print("   ");

			lcd_goto_xy(0,1);
			print_long(battery_millivolts[0]);
			print(" mV  ");
      
			delay_ms(10);

			// if button A is pressed, increase motor1 speed
			if(button_is_pressed(BUTTON_A) && speed1 < 127)
				speed1 ++;
			else if(speed1 > 1)
				speed1 -= 2;
			else if(speed1 > 0)
				speed1 = 0;

			// if button C is pressed, control motor2
			if(button_is_pressed(BUTTON_C) && speed2 < 127)
				speed2 ++;
			else if(speed2 > 1)
				speed2 -= 2;
			else if(speed2 > 0)
				speed2 = 0;

			// if button B is pressed, do PID control
			if(button_is_pressed(BUTTON_B))
				slave_set_pid(40, 1, 20, 3, 2);
			else
			{
				slave_stop_pid();
				slave_set_motors(speed1, speed2);
			}
		}
	}

	while(1);
}