-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_tests.c
181 lines (138 loc) · 3.05 KB
/
main_tests.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "lowlevel/theyseemerolling.h"
#include "lowlevel/clock.h"
#include "lowlevel/eeprom.h"
#include "lowlevel/motors.h"
#include "lowlevel/uart.h"
#include "asservissement/odometry.h"
void led_blink();
void motor_blink();
void led_blink();
void test_encoders();
void test_direction_general();
void test_odometry();
int main() {
// Basic initialization
clock_setup();
gpio_setup();
uart_setup();
odometry_setup();
// motors_setup();
test_odometry();
return 0;
}
void led_blink() {
while(true) {
led_set_status(0);
delay_ms(1000);
led_set_status(1);
delay_ms(1000);
}
}
void uart_send() {
while(true) {
uart_send_string("hello world (sure ?)\n\r");
led_toggle_status();
delay_ms(300);
}
}
void motor_blink() {
double speed = 0.0;
while(true) {
speed = 0;
motor_b_set(speed);
motor_a_set(speed);
led_set_status(0);
delay_ms(1000);
speed = 1;
motor_b_set(speed);
motor_a_set(speed);
led_set_status(1);
delay_ms(1000);
speed = 0;
motor_b_set(speed);
motor_a_set(speed);
led_set_status(0);
delay_ms(1000);
speed = -1;
motor_b_set(speed);
motor_a_set(speed);
led_set_status(1);
delay_ms(1000);
}
}
void led_blink_smart() {
bool status = about_da_power();
while(true) {
led_set_status(1);
delay_ms(100);
led_set_status(0);
delay_ms(100);
if (status)
led_set_status(1);
else
led_set_status(0);
delay_ms(100);
led_set_status(0);
delay_ms(700);
}
}
void test_encoders() {
odometry odom;
while(1)
{
odom = odometry_get_position();
uart_send_int(odom.left_count);
uart_send_string(" ; ");
uart_send_int(odom.right_count);
uart_send_string("\n\r");
delay_ms(100);
}
}
void ramp_motors(double begin, double end, int delay_by_step) {
// for ()
}
void test_direction_general() {
motor_b_set(0.2);
motor_a_set(0.2);
odometry odom_old, odom_new;
odom_old = odometry_get_position();
while(1)
{
odom_old = odom_new;
odom_new = odometry_get_position();
if (odom_new.left_count > odom_old.left_count)
uart_send_string(" + ");
else if (odom_new.left_count < odom_old.left_count)
uart_send_string(" - ");
else
uart_send_string(" 0 ");
uart_send_string(";");
if (odom_new.right_count > odom_old.right_count)
uart_send_string(" + ");
else if (odom_new.right_count < odom_old.right_count)
uart_send_string(" - ");
else
uart_send_string(" 0 ");
uart_send_string("\n\r");
delay_ms(300);
}
}
void test_odometry() {
odometry odom;
while(1)
{
odom = odometry_get_position();
uart_send_string("\r\n");
uart_send_string("\r\nl=");
uart_send_int((int)odom.left_count);
uart_send_string("\t; r=");
uart_send_int((int)odom.right_count);
uart_send_string("\r\nx=");
uart_send_int((int)odom.x);
uart_send_string("\t; y=");
uart_send_int((int)odom.y);
uart_send_string("\t; theta=");
uart_send_int((int)(odom.theta*100));
delay_ms(300);
}
}