Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / diagnostic_station / station / test_encoders.c @ 1900

History | View | Annotate | Download (3.67 KB)

1 1151 deffi
#include "test_encoders.h"
2
#include "global.h"
3 1182 deffi
#include "comm_robot.h"
4 1151 deffi
5 1215 deffi
#include "hardware.h"
6
7
// ******************
8
// ** Data sending **
9
// ******************
10
11
static void send_encoder_data (uint8_t num, uint8_t direction,
12 1297 deffi
        int16_t *data_station, int16_t *data_robot, uint8_t num_measurements)
13 1215 deffi
{
14
        if (direction!=motor_direction_off)
15
        {
16
                usb_puts ("data encoder ");
17
                usb_puti (num);
18
                usb_puts (" ");
19
                usb_puts (motor_direction_string (direction));
20
                usb_puts (" ");
21
22
                for (uint8_t i=0; i<num_measurements; ++i)
23
                {
24
                        usb_putc (' ');
25
                        usb_puti (data_station[i]);
26
                        usb_putc ('/');
27
                        usb_puti (data_robot[i]);
28
                }
29
30
                usb_puts (NL);
31
        }
32
}
33
34
35
// ************************
36
// ** Internal functions **
37
// ************************
38
39 1297 deffi
static void test_encoders_direction (uint8_t direction1, uint8_t direction2, uint8_t num_measurements, uint8_t velocity, uint16_t on_delay, uint16_t off_delay)
40 1203 deffi
{
41 1215 deffi
        // Allocate space for the data on the stack
42 1318 bneuman
        // Seems like we've got a stack overflow...see test_motors.c
43
//        int16_t *data_station_l  =malloc (num_measurements*sizeof (uint16_t));
44
//        int16_t *data_station_r  =malloc (num_measurements*sizeof (uint16_t));
45
//        int16_t *data_robot_l    =malloc (num_measurements*sizeof (uint16_t));
46
//        int16_t *data_robot_r    =malloc (num_measurements*sizeof (uint16_t));
47 1226 deffi
        usb_puts ("# Resetting encoders" NL);
48 1251 deffi
        dynamos_reset ();
49 1219 deffi
        robot_reset_encoders ();
50 1318 bneuman
51
        int16_t station_l=11, station_r=22, robot_l=33, robot_r=44;
52 1215 deffi
53 1159 deffi
        for (uint8_t m=0; m<num_measurements; ++m)
54
        {
55
                robot_set_motors (direction1, velocity, direction2, velocity);
56 1164 deffi
                delay_ms (on_delay);
57
                robot_set_motors_off ();
58
                delay_ms (off_delay);
59
60 1251 deffi
                // Read the station dynamos
61 1318 bneuman
                dynamos_read (&station_l, &station_r);
62
//                data_station_l[m]=station_l;
63
//                data_station_r[m]=station_r;
64 1219 deffi
65
                // Read the robot encoders
66 1318 bneuman
                robot_read_encoders (&robot_l, &robot_r);
67
//                data_robot_l[m]=robot_l;
68
//                data_robot_r[m]=robot_r;
69 1305 deffi
70
                //usb_puts ("# I readed teh encoders: ");
71
                //usb_puti (data_robot_l[m]);
72
                //usb_puts (" ");
73
                //usb_puti (data_robot_r[m]);
74
                //usb_puts (NL);
75
76 1318 bneuman
        send_encoder_data (0, direction1, &station_l, &robot_l, 1);
77
        send_encoder_data (1, direction2, &station_r, &robot_r, 1);
78 1159 deffi
        }
79
80 1318 bneuman
//        send_encoder_data (0, direction1, data_station_l, data_robot_l, num_measurements);
81
//        send_encoder_data (1, direction2, data_station_r, data_robot_r, num_measurements);
82 1215 deffi
83 1318 bneuman
//        free (data_robot_r);
84
//        free (data_robot_l);
85
//        free (data_station_r);
86
//        free (data_station_l);
87 1159 deffi
}
88
89 1215 deffi
90
// **********************
91
// ** Public functions **
92
// **********************
93
94 1305 deffi
// Encoder readings seem to be unreliable with these values (on too long?)
95
//#define NUM 4
96
//#define VEL 200
97
//#define ON_DELAY 500
98
//#define OFF_DELAY 800
99
100
// Testing values
101
#define NUM 8
102 1295 deffi
#define VEL 200
103 1305 deffi
#define ON_DELAY 150
104
#define OFF_DELAY 400
105 1295 deffi
106 1202 deffi
void test_encoder_all (void)
107 1151 deffi
{
108 1166 deffi
        usb_puts("# Testing encoders" NL);
109 1159 deffi
110 1297 deffi
        test_encoders_direction (motor_direction_forward , motor_direction_backward, NUM, VEL, ON_DELAY, OFF_DELAY);
111
        test_encoders_direction (motor_direction_backward, motor_direction_forward , NUM, VEL, ON_DELAY, OFF_DELAY);
112 1159 deffi
113 1166 deffi
        usb_puts("# Testing encoders finished" NL);
114 1151 deffi
}
115
116 1202 deffi
void test_encoder (uint8_t num)
117
{
118 1205 deffi
        if (num==1)
119
        {
120 1297 deffi
                test_encoders_direction (motor_direction_forward , motor_direction_off, NUM, VEL, ON_DELAY, OFF_DELAY);
121
                test_encoders_direction (motor_direction_backward, motor_direction_off, NUM, VEL, ON_DELAY, OFF_DELAY);
122 1205 deffi
        }
123
        else if (num==2)
124
        {
125 1297 deffi
                test_encoders_direction (motor_direction_off, motor_direction_forward , NUM, VEL, ON_DELAY, OFF_DELAY);
126
                test_encoders_direction (motor_direction_off, motor_direction_backward, NUM, VEL, ON_DELAY, OFF_DELAY);
127 1205 deffi
        }
128 1202 deffi
}