Statistics
| Revision:

root / trunk / code / projects / colonet / robot / joystick / continuous_control / tankcontrol.c @ 864

History | View | Annotate | Download (1009 Bytes)

1
#include <dragonfly_lib.h>
2
#include <wireless.h>
3
#include <wl_defs.h>
4
#include "../../../common/colonet_defs.h"
5
#include <serial.h>
6
#include <stdio.h>
7
#include <xbee.h>
8

    
9
#define YCENTER 90
10
#define XCENTER 90
11

    
12
int joystick_pos (void);
13

    
14
int main (void) {
15
  int cur_pos = 0;
16
  int x_pos, y_pos;
17
  int vx, vy;
18
  char buf[100];
19

    
20
  /* init stuff */
21
  dragonfly_init(SERIAL | USB | COMM | ORB | ANALOG);
22
        ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
23
        xbee_init();
24
  orb_set_color(BLUE);
25
  
26
  
27
  while (1) {
28
    cur_pos = joystick_pos();
29
    x_pos = cur_pos & 0xFF;
30
    y_pos = (cur_pos >> 8) & 0xFF;
31
    
32
    vx = (x_pos - XCENTER) * 10;
33
    vy = (y_pos - YCENTER) * 10;
34
    
35
    sprintf(buf, "%d,%d\0", vx, vy);
36
    usb_puts(buf);
37
    usb_puts("\n");
38

    
39
    delay_ms(200);
40
  }
41
  
42
}
43

    
44

    
45
/**
46
 * Get the current X and Y axis readings.
47
 */
48
int joystick_pos (void) {
49
        char x_pos, y_pos;
50
        char buf[100];
51
  
52
  x_pos = (char) analog_get8(AN4);
53
  y_pos = (char) analog_get8(AN5);
54

    
55
  return x_pos | (y_pos << 8);
56
}