Revision 1318
Martin updated some of the tests
test_motors is working with higher resolution
test_encoders is not working
trunk/code/projects/diagnostic_station/station/test_motors.c | ||
---|---|---|
40 | 40 |
// ************************ |
41 | 41 |
|
42 | 42 |
// One way to do it |
43 |
// #define vel_inc 10 |
|
43 |
/* #define vel_inc 10 */ |
|
44 |
/* #define vel_steps 12 */ |
|
45 |
/* #define vel_min 140 */ |
|
46 |
/* #define vel_max 250 */ |
|
47 |
/* #define velocity_steady_delay 400 */ |
|
48 |
|
|
49 |
// More steps at smaller intervals. We don't need so much delay here. |
|
50 |
#define vel_inc 2 |
|
51 |
#define vel_steps 56 |
|
52 |
#define vel_min 140 |
|
53 |
#define vel_max 250 |
|
54 |
#define velocity_steady_delay 50 |
|
55 |
|
|
56 |
// #define vel_inc 2 |
|
44 | 57 |
// #define vel_steps 12 |
45 |
// #define vel_min 140
|
|
46 |
// #define vel_max 250
|
|
47 |
// #define velocity_steady_delay 400
|
|
58 |
// #define vel_min 150
|
|
59 |
// #define vel_max 172
|
|
60 |
// #define velocity_steady_delay 50
|
|
48 | 61 |
|
49 |
// More steps at smaller intervals. We don't need so much delay here. |
|
50 |
#define vel_inc 2 |
|
51 |
#define vel_steps 56 |
|
52 |
#define vel_min 140 |
|
53 |
#define vel_max 250 |
|
54 |
#define velocity_steady_delay 50 |
|
55 | 62 |
|
56 | 63 |
|
64 |
|
|
57 | 65 |
static void test_motors_direction_acceleration (uint8_t direction1, uint8_t direction2, uint8_t pwm_start, uint8_t num_steps, int8_t pwm_step, char *acceleration_string) |
58 | 66 |
{ |
59 | 67 |
// Allocate space for the data on the stack |
60 |
uint8_t *data_pwm =malloc (num_steps*sizeof (uint8_t )); |
|
61 |
int16_t *data_velocity_l =malloc (num_steps*sizeof (uint16_t)); |
|
62 |
int16_t *data_velocity_r =malloc (num_steps*sizeof (uint16_t)); |
|
68 |
// uint8_t *data_pwm =malloc (num_steps*sizeof (uint8_t ));
|
|
69 |
// int16_t *data_velocity_l =malloc (num_steps*sizeof (uint16_t));
|
|
70 |
// int16_t *data_velocity_r =malloc (num_steps*sizeof (uint16_t));
|
|
63 | 71 |
|
64 | 72 |
uint8_t pwm=pwm_start; |
73 |
int16_t left; |
|
74 |
int16_t right; |
|
75 |
|
|
65 | 76 |
for (uint8_t i=0; i<num_steps; ++i) |
66 | 77 |
{ |
67 | 78 |
robot_set_motors (direction1, pwm, direction2, pwm); |
... | ... | |
69 | 80 |
// Wait some fixed time for the velocity to reach steady state. This could be improved. |
70 | 81 |
delay_ms (velocity_steady_delay); |
71 | 82 |
|
72 |
data_pwm[i]=pwm; |
|
83 |
// Store it |
|
84 |
//data_pwm[i]=pwm; |
|
73 | 85 |
|
74 | 86 |
// Reset the dynamos, wait some time, then read the dynamos. |
75 | 87 |
// Nothing else should go between dynamos_reset and dynamos_read. |
76 | 88 |
// Note that we are currently using busy waiting which will be totally wrong if there are any interrupts. |
77 | 89 |
dynamos_reset (); |
78 | 90 |
delay_ms (500); |
79 |
dynamos_read (&(data_velocity_l[i]), &(data_velocity_r[i])); |
|
91 |
dynamos_read (&left, &right); |
|
92 |
|
|
93 |
// Velocity readings are dynamo ticks per second. |
|
94 |
left*=2; |
|
95 |
right*=2; |
|
96 |
|
|
97 |
// Store it |
|
98 |
//dynamos_read (&(data_velocity_l[i]), &(data_velocity_r[i])); |
|
80 | 99 |
|
81 |
// Velocity readings are dynamo ticks per second. |
|
82 |
data_velocity_l[i]*=2; |
|
83 |
data_velocity_r[i]*=2; |
|
84 |
|
|
100 |
|
|
101 |
// Bad things happening. Methinks it's a stack overflow. Print one data line |
|
102 |
// per measurement. The plotting script can probably handle it. Not sure about |
|
103 |
// the server. |
|
104 |
send_motor_data (0, direction1, acceleration_string, 1, &pwm, &left); |
|
105 |
send_motor_data (1, direction2, acceleration_string, 1, &pwm, &right); |
|
106 |
|
|
107 |
//usb_puts ("# "); |
|
108 |
//usb_puti (i); |
|
109 |
//usb_puts (" "); |
|
110 |
//usb_puti (pwm); |
|
111 |
//usb_puts (" "); |
|
112 |
//usb_puti (data_velocity_l[i]); |
|
113 |
//usb_puts (" "); |
|
114 |
//usb_puti (data_velocity_r[i]); |
|
115 |
//usb_puts (NL); |
|
116 |
|
|
85 | 117 |
pwm+=pwm_step; |
86 | 118 |
} |
87 | 119 |
|
88 |
send_motor_data (0, direction1, acceleration_string, num_steps, data_pwm, data_velocity_l); |
|
89 |
send_motor_data (1, direction2, acceleration_string, num_steps, data_pwm, data_velocity_r); |
|
120 |
// send_motor_data (0, direction1, acceleration_string, num_steps, data_pwm, data_velocity_l);
|
|
121 |
// send_motor_data (1, direction2, acceleration_string, num_steps, data_pwm, data_velocity_r);
|
|
90 | 122 |
|
91 | 123 |
robot_set_motors (motor_direction_off, 0, motor_direction_off, 0); |
92 | 124 |
|
93 |
free (data_velocity_r); |
|
94 |
free (data_velocity_l); |
|
95 |
free (data_pwm); |
|
125 |
// free (data_velocity_r);
|
|
126 |
// free (data_velocity_l);
|
|
127 |
// free (data_pwm);
|
|
96 | 128 |
} |
97 | 129 |
|
98 | 130 |
static void test_motors_direction (uint8_t direction1, uint8_t direction2) |
trunk/code/projects/diagnostic_station/station/Makefile | ||
---|---|---|
15 | 15 |
USE_WIRELESS = 1 |
16 | 16 |
|
17 | 17 |
# com1 = serial port. Use lpt1 to connect to parallel port. |
18 |
AVRDUDE_PORT = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'COM4:'; else echo '/dev/ttyUSB0'; fi)
|
|
18 |
AVRDUDE_PORT = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'COM4:'; else echo '/dev/ttyUSB1'; fi)
|
|
19 | 19 |
# |
20 | 20 |
# |
21 | 21 |
################################### |
trunk/code/projects/diagnostic_station/station/test_encoders.c | ||
---|---|---|
39 | 39 |
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 | 40 |
{ |
41 | 41 |
// Allocate space for the data on the stack |
42 |
int16_t *data_station_l =malloc (num_measurements*sizeof (uint16_t)); |
|
43 |
int16_t *data_station_r =malloc (num_measurements*sizeof (uint16_t)); |
|
44 |
int16_t *data_robot_l =malloc (num_measurements*sizeof (uint16_t)); |
|
45 |
int16_t *data_robot_r =malloc (num_measurements*sizeof (uint16_t)); |
|
46 |
+ // Seems like we've got a stack overflow...see test_motors.c |
|
42 |
// int16_t *data_station_l =malloc (num_measurements*sizeof (uint16_t)); |
|
43 |
// int16_t *data_station_r =malloc (num_measurements*sizeof (uint16_t)); |
|
44 |
// int16_t *data_robot_l =malloc (num_measurements*sizeof (uint16_t)); |
|
45 |
// int16_t *data_robot_r =malloc (num_measurements*sizeof (uint16_t)); |
|
47 | 46 |
usb_puts ("# Resetting encoders" NL); |
48 | 47 |
dynamos_reset (); |
49 | 48 |
robot_reset_encoders (); |
49 |
|
|
50 |
int16_t station_l=11, station_r=22, robot_l=33, robot_r=44; |
|
50 | 51 |
|
51 | 52 |
for (uint8_t m=0; m<num_measurements; ++m) |
52 | 53 |
{ |
... | ... | |
56 | 58 |
delay_ms (off_delay); |
57 | 59 |
|
58 | 60 |
// Read the station dynamos |
59 |
dynamos_read (&(data_station_l[m]), &(data_station_r[m])); |
|
61 |
dynamos_read (&station_l, &station_r); |
|
62 |
// data_station_l[m]=station_l; |
|
63 |
// data_station_r[m]=station_r; |
|
60 | 64 |
|
61 | 65 |
// Read the robot encoders |
62 |
robot_read_encoders (&(data_robot_l[m]), &(data_robot_r[m])); |
|
66 |
robot_read_encoders (&robot_l, &robot_r); |
|
67 |
// data_robot_l[m]=robot_l; |
|
68 |
// data_robot_r[m]=robot_r; |
|
63 | 69 |
|
64 | 70 |
//usb_puts ("# I readed teh encoders: "); |
65 | 71 |
//usb_puti (data_robot_l[m]); |
... | ... | |
67 | 73 |
//usb_puti (data_robot_r[m]); |
68 | 74 |
//usb_puts (NL); |
69 | 75 |
|
76 |
send_encoder_data (0, direction1, &station_l, &robot_l, 1); |
|
77 |
send_encoder_data (1, direction2, &station_r, &robot_r, 1); |
|
70 | 78 |
} |
71 | 79 |
|
72 |
send_encoder_data (0, direction1, data_station_l, data_robot_l, num_measurements); |
|
73 |
send_encoder_data (1, direction2, data_station_r, data_robot_r, num_measurements); |
|
80 |
// 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);
|
|
74 | 82 |
|
75 |
free (data_robot_r); |
|
76 |
free (data_robot_l); |
|
77 |
free (data_station_r); |
|
78 |
free (data_station_l); |
|
83 |
// free (data_robot_r);
|
|
84 |
// free (data_robot_l);
|
|
85 |
// free (data_station_r);
|
|
86 |
// free (data_station_l);
|
|
79 | 87 |
} |
80 | 88 |
|
81 | 89 |
|
Also available in: Unified diff