-
Notifications
You must be signed in to change notification settings - Fork 0
/
cave-crawler-mcu.ino
106 lines (82 loc) · 2.38 KB
/
cave-crawler-mcu.ino
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
/*
* cave-crawler-mcu firmware sketch for Teensy 3.5
*
* Copyright (C) 2018-2019 Bartosz Meglicki <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
* kind, whether express or implied; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "cc-common.h"
#include "cc-odometry.h"
//#include "cc-xv11lidar.h"
#include "cc-rplidar.h"
#include "cc-usb-protocol.h"
void timeStats();
//temp time measure
unsigned long last_loop_time_us;
unsigned long last_print_time_us;
unsigned long max_loop_time_us;
//end temp
//temp
#define MEM_LEN 256
char databuf[MEM_LEN];
//endtemp
void setup()
{
DEBUG_SERIAL.begin(115200);
CAVECRAWLER_SERIAL.begin(115200);
while(!CAVECRAWLER_SERIAL);
DEBUG_SERIAL.println("setup...");
DEBUG_SERIAL.println("setup odometry");
setupOdometry();
//DEBUG_SERIAL.println("setup XV11 Lidar");
//setupXV11Lidar();
DEBUG_SERIAL.println("setup RPLidar (vertical)");
setupRPLidarVertical();
DEBUG_SERIAL.println("setup RPLidar (horizontal)");
setupRPLidarHorizontal();
//temp
last_loop_time_us=micros();
last_print_time_us=micros();
//end temp
}
void loop()
{
odometry_usb_packet odometry_packet;
//xv11lidar_usb_packet xv11lidar_packet;
rplidar_usb_packet rplidar_packet;
//get data from devices
if ( processOdometry(odometry_packet) )
serialPush(odometry_packet);
//if ( processXV11Lidar(xv11lidar_packet) )
//serialPush(xv11lidar_packet);
if ( processRPLidarVertical(rplidar_packet) )
serialPush(rplidar_packet);
if ( processRPLidarHorizontal(rplidar_packet) )
serialPush(rplidar_packet);
serialSend();
timeStats();
}
void timeStats()
{
unsigned long loop_time, now_us;
now_us=micros();
loop_time=now_us-last_loop_time_us;
last_loop_time_us=now_us;
if(loop_time>max_loop_time_us)
max_loop_time_us=loop_time;
if(now_us-last_print_time_us > 1000000)
{
last_print_time_us=now_us;
DEBUG_SERIAL.print("c ");
DEBUG_SERIAL.print(loop_time, DEC);
DEBUG_SERIAL.print(" m ");
DEBUG_SERIAL.println(max_loop_time_us, DEC);
max_loop_time_us=0;
}
}