Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / diagnostic_station / station / hardware_turntable.c @ 1289

History | View | Annotate | Download (1.22 KB)

1
#include "hardware_turntable.h"
2
#include <encoders.h>
3

    
4
void turntable_init ()
5
{
6
  int e;
7
  encoders_init();
8

    
9
  // get a reading to check alignment
10
  e = encoder_read(LEFT);
11
  if(e==ENCODER_MAGNET_FAILURE)
12
    usb_puts("# ERROR: turntable encoder magnet failure!!" NL);
13
  else if(e==ENCODER_MISALIGNED)
14
    usb_puts("# ERROR: turntable encoder misaligned!!" NL);
15
  else if(e==ENCODER_DATA_NOT_READY)
16
    usb_puts("# ERROR: turntable encoder data not ready!!" NL);
17
  else
18
    usb_puts("# Turntable encoder initialized" NL);
19

    
20
  motors_init();
21
}
22

    
23
void turntable_rotate_to_position (int16_t position)
24
{
25
  uint16_t turntable;
26

    
27
  return;
28

    
29
  usb_puts ("# Turntable rotating to ");
30
  usb_puti (position);
31
  usb_puts (NL);
32
        
33
  //TODO: p control
34
  //TODO: proper direction
35
  motor1_set(1, 180);
36

    
37
  while((turntable = turntable_get_position()) <= position)
38
  {
39
    delay_ms(1);
40
    usb_puti(turntable);
41
    usb_puts(NL);
42

    
43
    if(turntable >= 1024)
44
    {
45
      usb_puts("# ERROR: magnetic encoder error!" NL);
46
      break;
47
    }
48
  }
49

    
50
  motor1_set(1, 0);
51
        
52
  usb_puts ("# Turntable position reached" NL);
53
}
54

    
55
uint16_t turntable_get_position (void)
56
{
57
  //TODO: convert units
58
  return encoder_read(RIGHT);
59
}