Skip to content

Commit 1a8354f

Browse files
committed
Merge branch 'main' into feature-imufilter
2 parents d443fa8 + d6fbe5c commit 1a8354f

File tree

5 files changed

+118
-23
lines changed

5 files changed

+118
-23
lines changed

src/controls/controller_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ void ControllerManager::step(float macro_reference[STATE_LEN][3], float macro_es
5353
// grab the motor outputs for this controller
5454
controllers[i]->step(macro_reference, macro_estimate, micro_estimate, outputs);
5555

56-
Serial.printf("Controller %d\n", i);
56+
// Serial.printf("Controller %d\n", i);
5757

5858
// iterate through all the motors this controller sets
5959
for (size_t j = 0; j < CAN_MAX_MOTORS + 1; j++) {
6060
if (config_data->controller_info[i][j + 1] < 0) break;
61-
Serial.printf("\tMotor %d: %f\n", config_data->controller_info[i][j + 1], outputs[j]);
61+
// Serial.printf("\tMotor %d: %f\n", config_data->controller_info[i][j + 1], outputs[j]);
6262
actuator_write(config_data->controller_info[i][j + 1], outputs[j]);
6363
}
6464
}

src/main.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,13 @@ int main() {
260260
}
261261

262262
// print dr16
263-
Serial.printf("DR16:\n\t");
264-
dr16.print();
263+
// Serial.printf("DR16:\n\t");
264+
// dr16.print();
265265

266-
Serial.printf("Target state:\n");
267-
for (int i = 0; i < 8; i++) {
268-
Serial.printf("\t%d: %f %f %f\n", i, target_state[i][0], target_state[i][1], target_state[i][2]);
269-
}
266+
// Serial.printf("Target state:\n");
267+
// for (int i = 0; i < 8; i++) {
268+
// Serial.printf("\t%d: %f %f %f\n", i, target_state[i][0], target_state[i][1], target_state[i][2]);
269+
// }
270270

271271
// override temp state if needed
272272
if (incoming->get_hive_override_request() == 1) {
@@ -285,25 +285,25 @@ int main() {
285285
count_one++;
286286
}
287287

288-
Serial.printf("Estimated state:\n");
289-
for (int i = 0; i < 8; i++) {
290-
Serial.printf("\t%d: %f %f %f\n", i, temp_state[i][0], temp_state[i][1], temp_state[i][2]);
291-
}
288+
// Serial.printf("Estimated state:\n");
289+
// for (int i = 0; i < 8; i++) {
290+
// Serial.printf("\t%d: %f %f %f\n", i, temp_state[i][0], temp_state[i][1], temp_state[i][2]);
291+
// }
292292

293293
// reference govern
294294
governor.set_estimate(temp_state);
295295
governor.step_reference(target_state, config->governor_types);
296296
governor.get_reference(temp_reference);
297297

298-
Serial.printf("Reference state:\n");
299-
for (int i = 0; i < 8; i++) {
300-
Serial.printf("\t%d: %f %f %f\n", i, temp_reference[i][0], temp_reference[i][1], temp_reference[i][2]);
301-
}
298+
// Serial.printf("Reference state:\n");
299+
// for (int i = 0; i < 8; i++) {
300+
// Serial.printf("\t%d: %f %f %f\n", i, temp_reference[i][0], temp_reference[i][1], temp_reference[i][2]);
301+
// }
302302

303303
// generate motor outputs from controls
304304
controller_manager.step(temp_reference, temp_state, temp_micro_state);
305305

306-
can.print_state();
306+
// can.print_state();
307307

308308
// construct sensor data packet
309309
SensorData sensor_data;
@@ -349,12 +349,12 @@ int main() {
349349
if (dr16.is_connected() && (dr16.get_l_switch() == 2 || dr16.get_l_switch() == 3) && config_layer.is_configured() && !is_slow_loop) {
350350
// SAFETY OFF
351351
can.write();
352-
Serial.printf("Can write\n");
352+
// Serial.printf("Can write\n");
353353
} else {
354354
// SAFETY ON
355355
// TODO: Reset all controller integrators here
356356
can.issue_safety_mode();
357-
Serial.printf("Can zero\n");
357+
// Serial.printf("Can zero\n");
358358
}
359359

360360
// LED heartbeat -- linked to loop count to reveal slowdowns and freezes.

src/sensors/SensorManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void SensorManager::init(const Config* config_data) {
7373
void SensorManager::read() {
7474
for (int i = 0; i < buff_sensor_count; i++) {
7575
buff_encoders[i]->read();
76-
buff_encoders[i]->print();
76+
// buff_encoders[i]->print();
7777
}
7878
for (int i = 0; i < icm_sensor_count; i++) {
7979
icm_sensors[i]->read();
@@ -83,7 +83,7 @@ void SensorManager::read() {
8383

8484
for (int i = 0; i < rev_sensor_count; i++) {
8585
rev_sensors[i].read();
86-
rev_sensors[i].print();
86+
// rev_sensors[i].print();
8787
}
8888
if (lidar_sensor_count > 0) {
8989

@@ -97,7 +97,7 @@ void SensorManager::read() {
9797
ref->read();
9898
for (int i = 0; i < tof_sensor_count; i++) {
9999
tof_sensors[i]->read();
100-
tof_sensors[i]->print();
100+
// tof_sensors[i]->print();
101101
}
102102
}
103103
BuffEncoder* SensorManager::get_buff_encoder(int index) {

src/sensors/can/can_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <map>
77

88
/// @brief Debug flag to enable verbose logging. This can get quite noisy so it is off by default. Critical errors are still printed regardless of flag
9-
#define CAN_MANAGER_DEBUG
9+
// #define CAN_MANAGER_DEBUG
1010

1111
/// @brief The maximum number of motors that can be connected to a single bus
1212
constexpr uint32_t CAN_MAX_MOTORS_PER_BUS = 8u;

tools/tcm_blame.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import re
2+
import os
3+
import sys
4+
5+
"""
6+
python script to parse the map file (generated by build process) and find what symbols are using the most ITCM/DTCM
7+
8+
from firmware/:
9+
python tools/tcm_blame.py ./build/firmware.map 20
10+
python3 tools/tcm_blame.py ./build/firmware.map 20
11+
12+
from firmware/tools:
13+
python tcm_blame.py ../build/firmware.map 20
14+
python3 tcm_blame.py ../build/firmware.map 20
15+
"""
16+
17+
# origin and end addresses for tcm (Teensy 4.1)
18+
ITCM_START, ITCM_END = 0x00000000, 0x0007FFFF
19+
DTCM_START, DTCM_END = 0x20000000, 0x2007FFFF
20+
21+
if len(sys.argv) != 3:
22+
print(f"Usage: {sys.argv[0]} <map_file_path> <top_n>")
23+
sys.exit(1)
24+
25+
map_file_path = sys.argv[1]
26+
n = int(sys.argv[2])
27+
28+
symbols = []
29+
line_num = 0
30+
is_discarded = False
31+
is_debug = False
32+
33+
# parse map file
34+
with open(map_file_path, "r") as map_file:
35+
for line in map_file:
36+
# skip the discarded input section
37+
if (line.strip() == "Discarded input sections"):
38+
is_discarded = True
39+
# end of the discarded input section
40+
if (line.strip() == "Memory Configuration"):
41+
is_discarded = False
42+
43+
line_num += 1
44+
if (is_discarded):
45+
continue
46+
47+
# skip the debug sections
48+
debug_match = re.match(r'^\s*\.debug_', line)
49+
if (debug_match):
50+
is_debug = True
51+
# end of the debug sections
52+
if (line == "Cross Reference Table\n"):
53+
is_debug = False
54+
55+
if (is_debug):
56+
continue
57+
58+
# regex from hell
59+
match = re.match(r"\s*(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+)\s+(\S+)", line)
60+
61+
# if we get a match for this line, parse it
62+
if match:
63+
address = int(match.group(1), 16) # <- int base 16 lol
64+
size = int(match.group(2), 16)
65+
symbol = match.group(3)
66+
67+
# infer the region by address
68+
if ITCM_START <= address <= ITCM_END:
69+
region = "ITCM"
70+
elif DTCM_START <= address <= DTCM_END:
71+
region = "DTCM"
72+
else:
73+
# skip things that arent TCM
74+
continue
75+
76+
symbols.append((region, address, size, symbol, line_num))
77+
78+
# sort by size and get the top n
79+
dtcm_symbols = sorted([s for s in symbols if s[0] == "DTCM"], key=lambda x: -x[2])[:n]
80+
itcm_symbols = sorted([s for s in symbols if s[0] == "ITCM"], key=lambda x: -x[2])[:n]
81+
82+
# thank you chat
83+
def print_table(title, symbol_list):
84+
print(f"\nTop {n} {title} Memory Users:\n")
85+
print(f"{'Region':<6} {'Addr':>10} {'Size':>8} {'Symbol':<30} {'Line'}")
86+
print("-" * 80)
87+
for region, address, size, symbol, line_num in symbol_list:
88+
filename = os.path.basename(symbol)
89+
print(
90+
f"{region:<6} {address:#010x} {size:8} {filename:<30} {map_file_path}:{line_num}"
91+
)
92+
93+
94+
print_table("DTCM", dtcm_symbols)
95+
print_table("ITCM", itcm_symbols)

0 commit comments

Comments
 (0)