Skip to content

Commit 658d69c

Browse files
committed
Add shared debug macros to strip Serial prints in ROS builds
- Add firmware/shared/debug/debug.h with DEBUG_PRINT/DEBUG_PRINTLN macros that compile to no-ops under ROS - Replace Serial.print/println calls with debug macros across sensor and motor firmware - Add shared lib_extra_dirs to both platformio.ini configs - Update CI workflows to build debug environments and trigger on firmware/shared changes
1 parent 20a8c33 commit 658d69c

12 files changed

Lines changed: 138 additions & 107 deletions

File tree

.github/workflows/motor_microcontroller_CI.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ on:
77
- "**"
88
paths:
99
- "firmware/motor_microcontroller/**"
10+
- "firmware/shared/**"
1011
pull_request:
1112
branches:
1213
- "**"
1314
paths:
1415
- "firmware/motor_microcontroller/**"
16+
- "firmware/shared/**"
1517

1618
jobs:
1719
build:
@@ -42,7 +44,7 @@ jobs:
4244
mkdir -p firmware/motor_microcontroller/extra_packages
4345
cp -r src/autogiro_interfaces firmware/motor_microcontroller/extra_packages/
4446
- name: Build PlatformIO Project
45-
run: pio run -e pico -e ROS
47+
run: pio run -e pico -e ROS -e ROS-debug
4648
working-directory: firmware/motor_microcontroller
4749
- name: Upload firmware
4850
uses: actions/upload-artifact@v4

.github/workflows/sensor_microcontroller_CI.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ on:
77
- "**"
88
paths:
99
- "firmware/sensor_microcontroller/**"
10+
- "firmware/shared/**"
1011
pull_request:
1112
branches:
1213
- "**"
1314
paths:
1415
- "firmware/sensor_microcontroller/**"
16+
- "firmware/shared/**"
1517

1618
jobs:
1719
build:
@@ -42,7 +44,7 @@ jobs:
4244
mkdir -p firmware/sensor_microcontroller/extra_packages
4345
cp -r src/autogiro_interfaces firmware/sensor_microcontroller/extra_packages/
4446
- name: Build PlatformIO Project
45-
run: pio run -e regular -e ROS
47+
run: pio run -e regular -e debug -e ROS -e ROS-Debug
4648
working-directory: firmware/sensor_microcontroller
4749
- name: Upload firmware
4850
uses: actions/upload-artifact@v4

firmware/motor_microcontroller/platformio.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
; Please visit documentation for the other options and examples
99
; https://docs.platformio.org/page/projectconf.html
1010

11+
[env]
12+
lib_extra_dirs = ../shared
13+
1114
[env:pico]
1215
platform = raspberrypi
1316
board = pico

firmware/motor_microcontroller/src/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ It will also read the speed of the motor and send it to the onboard computer.
1111
#include "RefSpeed.h"
1212
#include "BatteryFunctions.h"
1313
#include "globals.h"
14+
#include "debug.h"
1415

1516
#if defined(ROS) || defined(ROS_DEBUG)
1617
#include <micro_ros_platformio.h>
@@ -85,12 +86,12 @@ void setup()
8586
// initiate the DACs
8687
while (!dacA.begin(0x62))
8788
{
88-
Serial.println("DAC A not found");
89+
DEBUG_PRINTLN("DAC A not found");
8990
delay(500);
9091
}
9192
while (!dacB.begin(0x63))
9293
{
93-
Serial.println("DAC B not found");
94+
DEBUG_PRINTLN("DAC B not found");
9495
delay(500);
9596
}
9697
// pinMode(dacClockPin,OUTPUT); // set the pins to be used as output

firmware/sensor_microcontroller/platformio.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
; Please visit documentation for the other options and examples
99
; https://docs.platformio.org/page/projectconf.html
1010

11+
[env]
12+
lib_extra_dirs = ../shared
13+
1114
[env:regular]
1215
platform = raspberrypi
1316
board = pico

firmware/sensor_microcontroller/src/ADCFunctions.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ADCFunctions.h"
66
#include <Wire.h>
77
#include <Adafruit_ADS1X15.h>
8+
#include "debug.h"
89

910

1011
/**
@@ -17,13 +18,13 @@
1718

1819
//Initialize ADC
1920
while(!adc.begin(i2c_addr)){ // Initialize ads1115 at address 0x49
20-
Serial.println("Failed to find ADS1115 chip at address " + String(i2c_addr, HEX));
21+
DEBUG_PRINTLN("Failed to find ADS1115 chip at address " + String(i2c_addr, HEX));
2122
if (adc_count > 10) {
2223
return true;
2324
}
2425
adc_count++;
2526
}
26-
Serial.println("ADS1115 Found!");
27+
DEBUG_PRINTLN("ADS1115 Found!");
2728
adc.setGain(GAIN_ONE); //Setting the gain to +/- 4.096V 1 bit = 2mV for more precise readings
2829
return false;
2930
}
@@ -41,9 +42,9 @@ void printADC(Adafruit_ADS1115 &adc){
4142
adc1 = adc.readADC_SingleEnded(1);
4243
adc2 = adc.readADC_SingleEnded(2);
4344
adc3 = adc.readADC_SingleEnded(3);
44-
Serial.print("AIN0: "); Serial.println(adc0);
45-
Serial.print("AIN1: "); Serial.println(adc1);
46-
Serial.print("AIN2: "); Serial.println(adc2);
47-
Serial.print("AIN3: "); Serial.println(adc3);
48-
Serial.println();
45+
DEBUG_PRINT("AIN0: "); DEBUG_PRINTLN(adc0);
46+
DEBUG_PRINT("AIN1: "); DEBUG_PRINTLN(adc1);
47+
DEBUG_PRINT("AIN2: "); DEBUG_PRINTLN(adc2);
48+
DEBUG_PRINT("AIN3: "); DEBUG_PRINTLN(adc3);
49+
DEBUG_PRINTLN();
4950
}

firmware/sensor_microcontroller/src/FingerprintFunctions.cpp

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "FingerprintFunctions.h"
77
#include <Arduino.h>
88
#include <Adafruit_Fingerprint.h>
9+
#include "debug.h"
910

1011
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
1112
// pin #2 is IN from sensor (GREEN wire)
@@ -26,106 +27,108 @@ uint8_t getFingerprintID() {
2627
uint8_t p = finger.getImage();
2728
switch (p) {
2829
case FINGERPRINT_OK:
29-
Serial.println("Image taken");
30+
DEBUG_PRINTLN("Image taken");
3031
break;
3132
case FINGERPRINT_NOFINGER:
32-
Serial.println("No finger detected");
33+
DEBUG_PRINTLN("No finger detected");
3334
return p;
3435
case FINGERPRINT_PACKETRECIEVEERR:
35-
Serial.println("Communication error");
36+
DEBUG_PRINTLN("Communication error");
3637
return p;
3738
case FINGERPRINT_IMAGEFAIL:
38-
Serial.println("Imaging error");
39+
DEBUG_PRINTLN("Imaging error");
3940
return p;
4041
default:
41-
Serial.println("Unknown error");
42+
DEBUG_PRINTLN("Unknown error");
4243
return p;
4344
}
4445
// OK success!
4546
p = finger.image2Tz();
4647
switch (p) {
4748
case FINGERPRINT_OK:
48-
Serial.println("Image converted");
49+
DEBUG_PRINTLN("Image converted");
4950
break;
5051
case FINGERPRINT_IMAGEMESS:
51-
Serial.println("Image too messy");
52+
DEBUG_PRINTLN("Image too messy");
5253
return p;
5354
case FINGERPRINT_PACKETRECIEVEERR:
54-
Serial.println("Communication error");
55+
DEBUG_PRINTLN("Communication error");
5556
return p;
5657
case FINGERPRINT_FEATUREFAIL:
57-
Serial.println("Could not find fingerprint features");
58+
DEBUG_PRINTLN("Could not find fingerprint features");
5859
return p;
5960
case FINGERPRINT_INVALIDIMAGE:
60-
Serial.println("Could not find fingerprint features");
61+
DEBUG_PRINTLN("Could not find fingerprint features");
6162
return p;
6263
default:
63-
Serial.println("Unknown error");
64+
DEBUG_PRINTLN("Unknown error");
6465
return p;
6566
}
6667
// OK converted!
6768
p = finger.fingerSearch();
6869
if (p == FINGERPRINT_OK) {
69-
Serial.println("Found a print match!");
70+
DEBUG_PRINTLN("Found a print match!");
7071
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
71-
Serial.println("Communication error");
72+
DEBUG_PRINTLN("Communication error");
7273
return p;
7374
} else if (p == FINGERPRINT_NOTFOUND) {
74-
Serial.println("Did not find a match");
75+
DEBUG_PRINTLN("Did not find a match");
7576
return p;
7677
} else {
77-
Serial.println("Unknown error");
78+
DEBUG_PRINTLN("Unknown error");
7879
return p;
7980
}
8081

8182
// found a match!
82-
Serial.print("Found ID #"); Serial.print(finger.fingerID);
83-
Serial.print(" with confidence of "); Serial.println(finger.confidence);
83+
DEBUG_PRINT("Found ID #"); DEBUG_PRINT(finger.fingerID);
84+
DEBUG_PRINT(" with confidence of "); DEBUG_PRINTLN(finger.confidence);
8485

8586
return finger.fingerID;
8687
}
8788

8889
bool setupFingerprint()
8990
{
91+
#if !defined(ROS) && !defined(ROS_DEBUG)
9092
while (!Serial); // For Yun/Leo/Micro/Zero/...
93+
#endif
9194
delay(100);
92-
Serial.println("\n\nAdafruit finger detect test");
95+
DEBUG_PRINTLN("\n\nAdafruit finger detect test");
9396

9497
// set the data rate for the sensor serial port
9598
finger.begin(57600);
9699
delay(5);
97100
if (finger.verifyPassword()) {
98-
Serial.println("Found fingerprint sensor!");
101+
DEBUG_PRINTLN("Found fingerprint sensor!");
99102
} else {
100103
int init_count = 0;
101-
Serial.println("Did not find fingerprint sensor :(");
104+
DEBUG_PRINTLN("Did not find fingerprint sensor :(");
102105
while (!finger.verifyPassword()) {
103-
Serial.println(init_count);
106+
DEBUG_PRINTLN(init_count);
104107
if (init_count > 10) {
105108
return true;
106109
}
107110
init_count++;
108111
}
109112
}
110113

111-
Serial.println(F("Reading sensor parameters"));
114+
DEBUG_PRINTLN(F("Reading sensor parameters"));
112115
finger.getParameters();
113-
Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
114-
Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
115-
Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
116-
Serial.print(F("Security level: ")); Serial.println(finger.security_level);
117-
Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
118-
Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
119-
Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);
116+
DEBUG_PRINT(F("Status: 0x")); DEBUG_PRINTLN(finger.status_reg, HEX);
117+
DEBUG_PRINT(F("Sys ID: 0x")); DEBUG_PRINTLN(finger.system_id, HEX);
118+
DEBUG_PRINT(F("Capacity: ")); DEBUG_PRINTLN(finger.capacity);
119+
DEBUG_PRINT(F("Security level: ")); DEBUG_PRINTLN(finger.security_level);
120+
DEBUG_PRINT(F("Device address: ")); DEBUG_PRINTLN(finger.device_addr, HEX);
121+
DEBUG_PRINT(F("Packet len: ")); DEBUG_PRINTLN(finger.packet_len);
122+
DEBUG_PRINT(F("Baud rate: ")); DEBUG_PRINTLN(finger.baud_rate);
120123

121124
finger.getTemplateCount();
122125

123126
if (finger.templateCount == 0) {
124-
Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
127+
DEBUG_PRINT("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
125128
}
126129
else {
127-
Serial.println("Waiting for valid finger...");
128-
Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
130+
DEBUG_PRINTLN("Waiting for valid finger...");
131+
DEBUG_PRINT("Sensor contains "); DEBUG_PRINT(finger.templateCount); DEBUG_PRINTLN(" templates");
129132
}
130133
return false;
131134
}

0 commit comments

Comments
 (0)