使用旧版候选区寻找方式。
This commit is contained in:
12
main.cpp
12
main.cpp
@@ -33,23 +33,11 @@ int mark = 0;
|
|||||||
|
|
||||||
void uartReceive(Uart* uart);
|
void uartReceive(Uart* uart);
|
||||||
|
|
||||||
thread* create_data_recv_thread(Uart *uart){
|
|
||||||
thread *thread1 = new thread([uart](){
|
|
||||||
LOGM("Start receiving!");
|
|
||||||
while(1){
|
|
||||||
uart->debugUart();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return thread1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
process_options(argc, argv);
|
process_options(argc, argv);
|
||||||
Uart uart;
|
Uart uart;
|
||||||
thread receive(uartReceive, &uart);
|
thread receive(uartReceive, &uart);
|
||||||
bool flag = true;
|
bool flag = true;
|
||||||
// create_data_recv_thread(&uart);
|
|
||||||
while (flag){
|
while (flag){
|
||||||
int ally_color = ALLY_RED;
|
int ally_color = ALLY_RED;
|
||||||
int energy_part_rotation = CLOCKWISE;
|
int energy_part_rotation = CLOCKWISE;
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ public:
|
|||||||
|
|
||||||
uint8_t receive();
|
uint8_t receive();
|
||||||
void receive_data();
|
void receive_data();
|
||||||
bool debugUart();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -121,9 +121,6 @@ int Uart::set_opt(int fd, int nSpeed, int nBits, char nEvent, int nStop) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *send_info=fopen("send.info", "w");
|
|
||||||
FILE *recv_info=fopen("recv.info", "w");
|
|
||||||
|
|
||||||
void Uart::sendTarget(float x, float y, float z) {
|
void Uart::sendTarget(float x, float y, float z) {
|
||||||
static short x_tmp, y_tmp, z_tmp;
|
static short x_tmp, y_tmp, z_tmp;
|
||||||
|
|
||||||
@@ -149,48 +146,12 @@ void Uart::sendTarget(float x, float y, float z) {
|
|||||||
buff[6] = static_cast<char>((z_tmp >> 0) & 0xFF);
|
buff[6] = static_cast<char>((z_tmp >> 0) & 0xFF);
|
||||||
buff[7] = 'e';
|
buff[7] = 'e';
|
||||||
|
|
||||||
timeval ts;
|
|
||||||
gettimeofday(&ts, NULL);
|
|
||||||
fprintf(send_info, "%lf %f %f\n",
|
|
||||||
ts.tv_sec + ts.tv_usec / 1e6,
|
|
||||||
x, y
|
|
||||||
);
|
|
||||||
|
|
||||||
write(fd, buff, 8);
|
write(fd, buff, 8);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 's' + (x) ( 8bit + 8bit ) + (y) ( 8bit + 8bit ) + (z) ( 8bit + 8bit ) + 'e'
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t Uart::receive() {
|
uint8_t Uart::receive() {
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
while(read(fd, &data, 1) < 1);
|
while(read(fd, &data, 1) < 1);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void readall(int fd, void* buff, int size) {
|
|
||||||
int cnt = 0;
|
|
||||||
while ((cnt += read(fd, (char*)buff + cnt, size - cnt)) < size);
|
|
||||||
}
|
|
||||||
|
|
||||||
char readone(int fd){
|
|
||||||
char val;
|
|
||||||
while(read(fd, &val, 1) < 1);
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Uart::debugUart() {
|
|
||||||
float val[3];
|
|
||||||
//while(readone(fd) != 's');
|
|
||||||
readall(fd, val, sizeof(val));
|
|
||||||
timeval ts;
|
|
||||||
gettimeofday(&ts, NULL);
|
|
||||||
fprintf(recv_info, "%lf %f %f %f\n",
|
|
||||||
ts.tv_sec + ts.tv_usec / 1e6,
|
|
||||||
val[0], val[1], val[2]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user