Skip to content

Commit 6ec5245

Browse files
committed
Add list of possible vid and pid pairs
1 parent da8b115 commit 6ec5245

4 files changed

Lines changed: 38 additions & 17 deletions

File tree

src/shared/constants.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,22 @@ static const unsigned int NUM_TIMES_SEND_STOP = 10;
213213
// disconnected
214214
static const double DISCONNECT_DURATION_MS = 1 * MILLISECONDS_PER_SECOND;
215215

216-
// product and vendor id for Arduino Uno Rev3 (retrieved from
217-
// http://www.linux-usb.org/usb.ids )
218-
#define ARDUINO_ID_LENGTH 5
219-
static const char ARDUINO_VENDOR_ID[ARDUINO_ID_LENGTH] = "2341";
220-
static const char ARDUINO_PRODUCT_ID[ARDUINO_ID_LENGTH] = "0043";
216+
// Vendor and product id pairs for the USB-to-serial adapters used by the
217+
// physical estop. Multiple pairs are supported since estop units may use
218+
// different adapters. IDs retrieved from http://www.linux-usb.org/usb.ids
219+
struct EstopUsbId
220+
{
221+
const char* vendor_id;
222+
const char* product_id;
223+
};
224+
225+
constexpr EstopUsbId ESTOP_USB_DEVICE_IDS[] = {
226+
{"2341", "0043"}, // Arduino Uno Rev3
227+
{"1a86", "7523"}, // CH340-based Arduino clones
228+
};
229+
230+
constexpr int NUM_ESTOP_USB_DEVICE_IDS =
231+
sizeof(ESTOP_USB_DEVICE_IDS) / sizeof(ESTOP_USB_DEVICE_IDS[0]);
221232

222233
// Number of times thunderloop should tick per second
223234
static const unsigned THUNDERLOOP_HZ = 300u;

src/software/estop/arduino_util.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ std::optional<std::string> ArduinoUtil::getArduinoPort()
2121
std::optional<HwInfo> hwInfo = getInfo(device);
2222
if (hwInfo.has_value())
2323
{
24-
if (hwInfo.value().vendor == ARDUINO_VENDOR_ID &&
25-
hwInfo.value().product == ARDUINO_PRODUCT_ID)
24+
for (const auto& id : ESTOP_USB_DEVICE_IDS)
2625
{
27-
std::string device_path = (boost::format("/dev/%1%") % device).str();
28-
return device_path;
26+
if (hwInfo.value().vendor == id.vendor_id &&
27+
hwInfo.value().product == id.product_id)
28+
{
29+
std::string device_path =
30+
(boost::format("/dev/%1%") % device).str();
31+
return device_path;
32+
}
2933
}
3034
}
3135
}

src/software/py_constants.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <pybind11/pybind11.h>
2+
#include <pybind11/stl.h>
23

34
#include "shared/constants.h"
45
#include "software/constants.h"
@@ -170,7 +171,12 @@ PYBIND11_MODULE(py_constants, m)
170171
m.attr("AUTO_KICK_SPEED_DEFAULT_M_PER_S") = AUTO_KICK_SPEED_DEFAULT_M_PER_S;
171172
m.attr("WHEEL_ROTATION_MAX_SPEED_M_PER_S") = WHEEL_ROTATION_MAX_SPEED_M_PER_S;
172173

173-
// Estop Arduino USB identifiers
174-
m.attr("ARDUINO_VENDOR_ID") = std::string(ARDUINO_VENDOR_ID);
175-
m.attr("ARDUINO_PRODUCT_ID") = std::string(ARDUINO_PRODUCT_ID);
174+
// Estop USB-to-serial adapter identifiers, as a list of
175+
// (vendor_id, product_id) pairs
176+
std::vector<std::pair<std::string, std::string>> estop_usb_device_ids;
177+
for (const auto& id : ESTOP_USB_DEVICE_IDS)
178+
{
179+
estop_usb_device_ids.emplace_back(id.vendor_id, id.product_id);
180+
}
181+
m.attr("ESTOP_USB_DEVICE_IDS") = estop_usb_device_ids;
176182
}

src/software/thunderscope/estop_helpers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from serial.tools import list_ports
33

4-
from software.py_constants import ARDUINO_VENDOR_ID, ARDUINO_PRODUCT_ID
4+
from software.py_constants import ESTOP_USB_DEVICE_IDS
55
from software.thunderscope.constants import EstopMode, ESTOP_PATH_1, ESTOP_PATH_2
66

77

@@ -13,13 +13,13 @@ def get_estop_path() -> str | None:
1313
1414
:return: the estop's serial port path, or None if no estop was found
1515
"""
16+
estop_usb_ids = {
17+
(vendor.lower(), product.lower()) for vendor, product in ESTOP_USB_DEVICE_IDS
18+
}
1619
for port in list_ports.comports():
1720
if port.vid is None or port.pid is None:
1821
continue
19-
if (
20-
f"{port.vid:04x}".lower() == ARDUINO_VENDOR_ID.lower()
21-
and f"{port.pid:04x}".lower() == ARDUINO_PRODUCT_ID.lower()
22-
):
22+
if (f"{port.vid:04x}".lower(), f"{port.pid:04x}".lower()) in estop_usb_ids:
2323
return port.device
2424

2525
# Fall back to linux device paths

0 commit comments

Comments
 (0)