Make the serial POWER_ON handshake optional in can_power_on.py
The serial base controller no longer powers the wheel servos now that the
wheels are on the external USB-CAN adapter, so GET_POWER/POWER_ON guards
nothing. With an unresponsive ESP32 it cost ~70 s of timeouts on every boot
before the script gave up and assumed power anyway.
Add --serial-handshake {true,false} (default true, unchanged). With false,
the serial port is still opened once, bounded to 5 s, so DTR/RTS are cleared
before the CAN link comes up, then CAN is brought up immediately.
This commit is contained in:
1 parent
e2285c46f0
commit
179606910a
1 file changed
+19
@@ -32,6 +32,9 @@ CMD_GET_POWER = 0x12
|
|||||||
# budget is non-fatal -- see main().
|
# budget is non-fatal -- see main().
|
||||||
SERIAL_READY_TIMEOUT = 60.0
|
SERIAL_READY_TIMEOUT = 60.0
|
||||||
POWER_ON_ATTEMPTS = 5
|
POWER_ON_ATTEMPTS = 5
|
||||||
|
# Without the handshake the serial port is only opened to release the ESP32 reset line,
|
||||||
|
# so don't hold up CAN bring-up for the full post-reboot CH340 window.
|
||||||
|
NO_HANDSHAKE_SERIAL_TIMEOUT = 5.0
|
||||||
|
|
||||||
|
|
||||||
def crc16_ibm(data: bytes) -> int:
|
def crc16_ibm(data: bytes) -> int:
|
||||||
@@ -192,6 +195,15 @@ def power_on(port_name: str) -> bool:
|
|||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
|
||||||
|
|
||||||
|
def release_esp32_reset(port_name: str) -> None:
|
||||||
|
"""Clear DTR/RTS (via open_serial) before CAN comes up, without any handshake."""
|
||||||
|
try:
|
||||||
|
os.close(open_serial_when_ready(port_name, NO_HANDSHAKE_SERIAL_TIMEOUT))
|
||||||
|
except (OSError, termios.error) as exc:
|
||||||
|
print(f"WARNING: could not open {port_name} to release the ESP32 ({exc}); "
|
||||||
|
"continuing to CAN bring-up", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def bring_up_can(interface: str) -> bool:
|
def bring_up_can(interface: str) -> bool:
|
||||||
if not re.match(r"^[a-zA-Z0-9_]+$", interface):
|
if not re.match(r"^[a-zA-Z0-9_]+$", interface):
|
||||||
print(f"ERROR: refusing unsafe interface name '{interface}'", file=sys.stderr)
|
print(f"ERROR: refusing unsafe interface name '{interface}'", file=sys.stderr)
|
||||||
@@ -218,8 +230,15 @@ def main() -> None:
|
|||||||
ap = argparse.ArgumentParser()
|
ap = argparse.ArgumentParser()
|
||||||
ap.add_argument("--port-name", default="/dev/agvpro_controller")
|
ap.add_argument("--port-name", default="/dev/agvpro_controller")
|
||||||
ap.add_argument("--can-interface-name", default="can0")
|
ap.add_argument("--can-interface-name", default="can0")
|
||||||
|
ap.add_argument("--serial-handshake", choices=["true", "false"], default="true",
|
||||||
|
help="false skips GET_POWER/POWER_ON (the serial board no longer controls "
|
||||||
|
"servo power) and only releases the ESP32 reset line")
|
||||||
args = ap.parse_args()
|
args = ap.parse_args()
|
||||||
|
|
||||||
|
if args.serial_handshake == "false":
|
||||||
|
release_esp32_reset(args.port_name)
|
||||||
|
sys.exit(0 if bring_up_can(args.can_interface_name) else 1)
|
||||||
|
|
||||||
# The wheel drives sit on CAN and are NOT powered by this serial board, so a dead
|
# The wheel drives sit on CAN and are NOT powered by this serial board, so a dead
|
||||||
# ESP32 link must only cost the base its IMU/voltage/IO/LED -- never its ability to
|
# ESP32 link must only cost the base its IMU/voltage/IO/LED -- never its ability to
|
||||||
# drive. Bring the CAN link up regardless.
|
# drive. Bring the CAN link up regardless.
|
||||||
|
|||||||
Reference in new issue
Block a user