Ejemplo n.º 1
0
int main()
{
  // Initialize the encoders and specify the four input pins.
  encoders_init(IO_C2, IO_C3, IO_C4, IO_C5);

  while(1)
  {
    // Read the counts for motor 1 and print to LCD.
    lcd_goto_xy(0,0);
    print_long(encoders_get_counts_m1());
    print(" ");

    // Read the counts for motor 2 and print to LCD.
    lcd_goto_xy(4,0);
    print_long(encoders_get_counts_m2());
    print(" ");

    // Print encoder errors, if there are any.
    if(encoders_check_error_m1())
    {
      lcd_goto_xy(0,1);
      print("Error 1");
    }
    if(encoders_check_error_m2())
    {
      lcd_goto_xy(0,1);
      print("Error 2");
    }

    delay_ms(50);
  }
}
Ejemplo n.º 2
0
int main(void)
{
    adc_init();

    spi_init();

    switches_init();
    encoders_init();

    for (;;)
    {
        // Check the SS pin, if it is low, send the data through SPI.
        if (spi_slave_selected())
        {
            spi_enable();
            for (uint8_t i=0; i<ENCODER_COUNT; ++i)
            {
                spi_transfer16(g_encoderValues[i]);
            }
            spi_transfer8(g_downMask);
            spi_disable();
        }

        switches_update();
        encoders_update();
    }
}
Ejemplo n.º 3
0
/*
 * MOTOR FUNCTIONS
 */
static void motor_init()
{
  /* setup encoder (only 1 motor - motor 2) */
  encoders_init(IO_D3, IO_D2, IO_D1, IO_D0);

  /* initial data values */
  encoders_get_counts_and_reset_m2();
  g_motor_state.direction = DIRECTION_FORWARD;
  g_motor_state.enabled = true;
  g_motor_state.speed = DEFAULT_MOTOR_SPEED;
}
Ejemplo n.º 4
0
int main(void) {

	init_menu();
	
	clear();
	init_motor();
	init_timers();
	encoders_init(IO_D2, IO_D3, IO_C4, IO_C5);

	sei();
	while (1) 
	{
		if(g_pd_release) {
			pd_task();
			g_pd_release = 0;
		}

		if(g_velocity_release) {
			velocity_task();
			g_velocity_release = 0;
		}

		if(g_encoder_release) {
			encoder_task();
			g_encoder_release = 0;
		}

		if(g_log_release) {
			log_task();
			g_log_release = 0;
		}

		if(g_interpolate_release) {
			interoplate_task();
			g_interpolate_release = 0;
		}

		serial_check();
		check_for_new_bytes_received();		
	}
}
Ejemplo n.º 5
0
int main()
{
  // Initialize the encoders
  encoders_init(IO_D2, IO_D3, IO_A3, IO_A2);
  float count = 0;
  char forward = TRUE;
  int motor_speed = 100;

  //set_motors(100, 255);
  while(1)
  {
    clear();
    lcd_goto_xy(0,0);

    //Calculate the count
    count = encoders_get_counts_m1() / ENCODER_COUNT_PER_REVOLUTION;

    // Increment and decrement speed if top or bottom buttons were pressed.
    unsigned char button = get_single_debounced_button_press(ANY_BUTTON);

    if ((button & TOP_BUTTON) && motor_speed < 250) // if top button pressed
      motor_speed = motor_speed + 5;
    if ((button & BOTTOM_BUTTON) && motor_speed > 80) // if bottom button pressed
      motor_speed = motor_speed - 5;

    //If the user is holding the middle button we want to stop the motor.
    if(button_is_pressed(MIDDLE_BUTTON) & MIDDLE_BUTTON)
    {
      print("Paused ");
      set_motors(0,0);
    }
    else
    {
      // Set motor speed dependent on direction.
      if(forward)
      {
        set_motors(motor_speed, 0);
        print("Forward ");
      }
      else
      {
        set_motors(-motor_speed, 0);
        print("Reverse ");
      }

      // At 0 and 2 we need to switch directions.
      if(count >= 2 && forward)
        forward = FALSE;

      if(count <= 0 && !forward)
        forward = TRUE;
    }

    // Print the motor speed and revolutions
    print_long(motor_speed); 
    print_count(count); 

    //Delay so LCD doesn't flicker too much
    delay_ms(50);
  }
}