diff --git a/src/elephant_robotics/agv_pro_bringup/scripts/can_power_on.py b/src/elephant_robotics/agv_pro_bringup/scripts/can_power_on.py index 7a6b3be..cd35cbf 100755 --- a/src/elephant_robotics/agv_pro_bringup/scripts/can_power_on.py +++ b/src/elephant_robotics/agv_pro_bringup/scripts/can_power_on.py @@ -32,6 +32,9 @@ CMD_GET_POWER = 0x12 # budget is non-fatal -- see main(). SERIAL_READY_TIMEOUT = 60.0 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: @@ -192,6 +195,15 @@ def power_on(port_name: str) -> bool: 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: if not re.match(r"^[a-zA-Z0-9_]+$", interface): print(f"ERROR: refusing unsafe interface name '{interface}'", file=sys.stderr) @@ -218,8 +230,15 @@ def main() -> None: ap = argparse.ArgumentParser() ap.add_argument("--port-name", default="/dev/agvpro_controller") 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() + 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 # ESP32 link must only cost the base its IMU/voltage/IO/LED -- never its ability to # drive. Bring the CAN link up regardless.