Project

General

Profile

Revision 1389

Added by Rich Hong over 14 years ago

Encoders unit test

View differences:

test_encoders.c
1
#include <dragonfly_lib.h>
2
#include "spi.h"
1
/**
2
 * @file encoders unit test
3
 */
4
#include "serial.h"
5
#include "time.h"
6
#include "dio.h"
3 7
#include "encoders.h"
4 8

  
5
#define MODE 0
6
#define TEST 0
9
/**
10
 * @brief Test encoders by outputting values to usb
11
 *
12
 * @test  Tester should start a program to read data from the robot via usb
13
 *        (e.g. gtkterm). Turn on the robot on then turn each wheel manually.
14
 *        Make sure the output on the screen makes sense.
15
 *        Pressing button 1 resets total distance and time count
16
 * @pre   Depends on serial and dio to work correctly
17
 */
7 18

  
8
extern char spi_status;
9

  
10 19
int testencoders(void)
11 20
{
12 21
	usb_init();
13 22
	encoders_init();
14 23
	int encoder_left,encoder_right;
15
	while(1){
16
		
24
	int dx_left, dx_right;
25
	int tc;
26
	while(1) {
27
		/* button1 is pressed */
28
		if (button1_read()) {
29
			/* reset dx and tc */
30
			encoder_rst_dx(LEFT);
31
			encoder_rst_dx(RIGHT);
32
			encoder_rst_tc();
33
		}
34

  
17 35
		encoder_left = encoder_read(LEFT);
18 36
		encoder_right = encoder_read(RIGHT);
19 37
		usb_puts("Encoder values (left, right): ");
20 38
		usb_puti(encoder_left); 
21 39
		usb_puts(", ");
22 40
		usb_puti(encoder_right); 
41
		usb_puts("\n");
42

  
43
		dx_left = encoder_get_dx(LEFT);
44
		dx_right = encoder_get_dx(RIGHT);
45
		usb_puts("Total Distance (left, right): ");
46
		usb_puti(dx_left);
47
		usb_puts(", ");
48
		usb_puti(dx_right);
49
		usb_puts("\n");
50

  
51
		tc = encoder_get_tc();
52
		usb_puts("Time count: ");
53
		usb_puti(tc);
23 54
		usb_puts("\n\r");
55

  
24 56
		delay_ms(500);
25 57
	}
26 58
	return 0;

Also available in: Unified diff