Esempio n. 1
0
ServoTestWizardPage::ServoTestWizardPage(QWidget *parent)
	: OnOffWizardPage(parent),
	m_theta(0.0),
	m_timer(new QTimer(this))
{
	setTitle(tr("Servo Test"));
	connect(this, SIGNAL(on(quint16)), SLOT(servoOn(quint16)));
	connect(this, SIGNAL(off(quint16)), SLOT(servoOff(quint16)));
}
Esempio n. 2
0
void find_first_well() {
  //first we make sure we're on an open space
  long open_space=0;//automatically intialized to zero
  //printf("looking for a good start\n");
  servoOn(1); //1 sets DIR to clockwise
  do {
    _delay_us(100);
    if ( PIND & _BV(PD2) ) {
      open_space += 100; //more open_space 
      // printf("%ld \n", open_space);
    } else {
      open_space = 0;  //if no open space then reset counter
      // printf("%ld \n", open_space);
    }
  } while (open_space < 400000L);

  servoOff();
//  printf("let us begin our adventure\n");

  //_delay_ms(1000);

  //begin first dot sequence


  servoOn(1);
  int counter = 0;
  while (counter < 1000)
  {

    if ( PIND & _BV(PD2) ) {
      _delay_us(10); // this is what happens if nothing detected. (detection events give low value)
      counter = 0;
    } else {
      counter++;
      //printf("counter is %d \n", counter); // don't use printf it slows everything down ruining timing measurement
    }
  }
  servoOff();
//  printf("what do we have here -- a well?\n");

  //_delay_ms(1000);
  go_to_next_dot(); //begin counting dots
}
Esempio n. 3
0
void go_to_next_edge(void) {

  servoOn(1);
  int counter = 0;
  while (counter < 10)
  {

    if ( !(PIND & _BV(PD2)) ) {
      _delay_ms(1); // this is what happens if nothing detected. (detection events give low value)
      counter = 0;
    } else {
      counter++;
      //printf("counter is %d \n", counter); // don't use printf it slows everything down ruining timing measurement
    }
  }
  servoOff();

}
Esempio n. 4
0
void go_to_next_dot() {
  int count_dots=0;
  int last_dot=0;

  int there_is_a_dot=3;

  while (last_dot==0) { //wait why 11? oh if misaligned and detects too many dots
    //look for dot, but with a time limit

//    printf("there is a dot preresult %d \n", there_is_a_dot);
    servoOn(1);
    there_is_a_dot =  check_if_there_is_a_dot_there( 500000L ); //DONE --  replaced this with a check_if_there_is_a_dot_there function
    //servoOff();
    //_delay_ms(1000);
    //printf("there is a dot result %d \n", there_is_a_dot);
    //printf("how many dots %d \n", count_dots);

    if (there_is_a_dot == 1)
    {
      count_dots++;
      //printf("how many dots %d \n", count_dots);
      //go to space right after the dot then begin the loop again
      go_to_next_edge();
      //printf("how many dots %d \n", count_dots);
    } else if (there_is_a_dot==0) {
      servoOff(); // stop
      _delay_ms(100); //wait for stop
      servoOn(0); // go reverse
      //printf("is this the real mistake? %d\n", count_dots);
      check_if_there_is_a_dot_there( 1000000L ); //check for the dot
      servoOff(); // found the dot, next we will go a bit further to center pic
      //_delay_ms(1000);
      //printf("found the edge, hopefully not more dots %d\n", count_dots);

      servoOn(0);
      _delay_ms(600); // hopefully this is long enough
      servoOff();
      last_dot = 1; //break loop as we found last dot
    } else {
      //printf("count them dots %d\n", count_dots);
    }
  }

  // send back the number of dots to pythonSerial.py
  switch (count_dots) {
    case 1:
      printf("%d\r\n", 7);
      break;
    case 2:
      printf("%d\r\n", 8);
      break;
    case 3:
      printf("%d\r\n", 9);
      break;
    case 4:
      printf("%d\r\n", 10);
      break;
    default:
      break;
  }

  PORTB |= _BV(LED); // TODO Test LED ON
  _delay_ms(2000); // wait for camera to take photo
  PORTB &= ~_BV(LED); // TODO Test LED OFF
  servoOn(1);
  _delay_ms(1000);

  count_dots = 0; // reset our global dot counter for next well
}