Revision 1250
Improved motors test
test_motors.c | ||
---|---|---|
39 | 39 |
// ** Internal functions ** |
40 | 40 |
// ************************ |
41 | 41 |
|
42 |
#define velocity_steady_delay 400 |
|
43 |
|
|
42 | 44 |
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) |
43 | 45 |
{ |
44 | 46 |
// Allocate space for the data on the stack |
... | ... | |
50 | 52 |
for (uint8_t i=0; i<num_steps; ++i) |
51 | 53 |
{ |
52 | 54 |
robot_set_motors (direction1, pwm, direction2, pwm); |
53 |
// TODO better |
|
54 |
#define vel_delay 400 |
|
55 |
delay_ms (vel_delay); // TODO wait steady |
|
56 | 55 |
|
56 |
// Wait some fixed time for the velocity to reach steady state. This could be improved. |
|
57 |
delay_ms (velocity_steady_delay); |
|
58 |
|
|
57 | 59 |
data_pwm[i]=pwm; |
58 | 60 |
|
61 |
// Reset the encoders, wait some time, then read the encoders. |
|
62 |
// Nothing else should go between encoders_reset and encoders_read. |
|
63 |
// Note that we are currently using busy waiting which will be totally wrong if there are any interrupts. |
|
59 | 64 |
encoders_reset (); |
60 |
// TODO delay
|
|
65 |
delay_ms (500);
|
|
61 | 66 |
encoders_read (&(data_velocity_l[i]), &(data_velocity_r[i])); |
67 |
|
|
68 |
// Velocity readings are encoder ticks per second. |
|
69 |
data_velocity_l[i]*=2; |
|
70 |
data_velocity_r[i]*=2; |
|
62 | 71 |
|
63 | 72 |
pwm+=pwm_step; |
64 | 73 |
} |
... | ... | |
75 | 84 |
|
76 | 85 |
static void test_motors_direction (uint8_t direction1, uint8_t direction2) |
77 | 86 |
{ |
87 |
// The following equation must be true: vel_min+(vel_steps-1)*vel_inc=vel_max |
|
88 |
// Note that we're setting vel_max twice, once going up and once going down. It's not important for vel_max, but |
|
89 |
// vel_min is also reached twice, once at the beginning of accelerating and once at the end of decelerating, and |
|
90 |
// this one is important. |
|
91 |
|
|
78 | 92 |
#define vel_inc 10 |
79 |
#define vel_steps 10
|
|
93 |
#define vel_steps 12
|
|
80 | 94 |
#define vel_min 140 |
81 | 95 |
#define vel_max 250 |
82 | 96 |
|
Also available in: Unified diff