Skip to content

Commit d8c8033

Browse files
committed
merged main
2 parents a679d83 + d6fbe5c commit d8c8033

File tree

5 files changed

+119
-24
lines changed

5 files changed

+119
-24
lines changed

src/controls/controller_manager.cpp

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

57-
logger.printf("Controller %d\n", i);
57+
// logger.printf("Controller %d\n", i);
5858

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

src/main.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,13 @@ int main() {
263263
}
264264

265265
// print dr16
266-
logger.printf("DR16:\n\t");
267-
dr16.print();
266+
// Serial.printf("DR16:\n\t");
267+
// dr16.print();
268268

269-
logger.printf("Target state:\n");
270-
for (int i = 0; i < 8; i++) {
271-
logger.printf("\t%d: %f %f %f\n", i, target_state[i][0], target_state[i][1], target_state[i][2]);
272-
}
269+
// Serial.printf("Target state:\n");
270+
// for (int i = 0; i < 8; i++) {
271+
// Serial.printf("\t%d: %f %f %f\n", i, target_state[i][0], target_state[i][1], target_state[i][2]);
272+
// }
273273

274274
// override temp state if needed
275275
if (incoming->get_hive_override_request() == 1) {
@@ -288,25 +288,25 @@ int main() {
288288
count_one++;
289289
}
290290

291-
logger.printf("Estimated state:\n");
292-
for (int i = 0; i < 8; i++) {
293-
logger.printf("\t%d: %f %f %f\n", i, temp_state[i][0], temp_state[i][1], temp_state[i][2]);
294-
}
291+
// Serial.printf("Estimated state:\n");
292+
// for (int i = 0; i < 8; i++) {
293+
// Serial.printf("\t%d: %f %f %f\n", i, temp_state[i][0], temp_state[i][1], temp_state[i][2]);
294+
// }
295295

296296
// reference govern
297297
governor.set_estimate(temp_state);
298298
governor.step_reference(target_state, config->governor_types);
299299
governor.get_reference(temp_reference);
300300

301-
logger.printf("Reference state:\n");
302-
for (int i = 0; i < 8; i++) {
303-
logger.printf("\t%d: %f %f %f\n", i, temp_reference[i][0], temp_reference[i][1], temp_reference[i][2]);
304-
}
301+
// Serial.printf("Reference state:\n");
302+
// for (int i = 0; i < 8; i++) {
303+
// Serial.printf("\t%d: %f %f %f\n", i, temp_reference[i][0], temp_reference[i][1], temp_reference[i][2]);
304+
// }
305305

306306
// generate motor outputs from controls
307307
controller_manager.step(temp_reference, temp_state, temp_micro_state);
308308

309-
can.print_state();
309+
// can.print_state();
310310

311311
// construct sensor data packet
312312
SensorData sensor_data;
@@ -352,12 +352,12 @@ int main() {
352352
if (dr16.is_connected() && (dr16.get_l_switch() == 2 || dr16.get_l_switch() == 3) && config_layer.is_configured() && !is_slow_loop) {
353353
// SAFETY OFF
354354
can.write();
355-
logger.printf("Can write\n");
355+
// logger.printf("Can write\n");
356356
} else {
357357
// SAFETY ON
358358
// TODO: Reset all controller integrators here
359359
can.issue_safety_mode();
360-
logger.printf("Can zero\n");
360+
// logger.printf("Can zero\n");
361361
}
362362

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

src/sensors/SensorManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ void SensorManager::init(const Config* config_data) {
7575
void SensorManager::read() {
7676
for (int i = 0; i < buff_sensor_count; i++) {
7777
buff_encoders[i]->read();
78-
buff_encoders[i]->print();
78+
// buff_encoders[i]->print();
7979
}
8080
for (int i = 0; i < icm_sensor_count; i++) {
8181
icm_sensors[i]->read();
82-
icm_sensors[i]->print();
82+
// icm_sensors[i]->print();
8383
}
8484

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

@@ -98,7 +98,7 @@ void SensorManager::read() {
9898
ref->read();
9999
for (int i = 0; i < tof_sensor_count; i++) {
100100
tof_sensors[i]->read();
101-
tof_sensors[i]->print();
101+
// tof_sensors[i]->print();
102102
}
103103
}
104104
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)