From 8e8e3a4b3c61ebbb51f95e8d4fab7597316477bf Mon Sep 17 00:00:00 2001 From: dominikn Date: Fri, 29 Dec 2023 11:18:17 +0100 Subject: [PATCH 1/9] working SHM communication betweeen host and docker (compose.build.yaml) --- Dockerfile.hardware | 1 + demo/compose.build.yaml | 28 ++++++++++++++++++++++++++++ demo/shm-only.xml | 17 +++++++++++++++++ ros_entrypoint.sh | 9 +++++++-- 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 demo/compose.build.yaml create mode 100644 demo/shm-only.xml diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 98f292f..74443b3 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -106,6 +106,7 @@ RUN apt-get update && apt-get install -y \ python3-pip \ python3-rosdep \ stm32flash \ + gosu \ ros-$ROS_DISTRO-teleop-twist-keyboard && \ pip3 install pyftdi && \ rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \ diff --git a/demo/compose.build.yaml b/demo/compose.build.yaml new file mode 100644 index 0000000..a958ba9 --- /dev/null +++ b/demo/compose.build.yaml @@ -0,0 +1,28 @@ +# Quick Start +# +# 1. run `docker compose up` on the robot +# 2. run `ROS_DOMAIN_ID=10 ros2 run teleop_twist_keyboard teleop_twist_keyboard` in the robot termianl + +x-common-config: + &common-config + network_mode: host + ipc: host + environment: + - FASTRTPS_DEFAULT_PROFILES_FILE=/shm-only.xml + - ROS_DOMAIN_ID=10 + - USER + +services: + + rosbot: + build: + context: .. + dockerfile: Dockerfile.hardware + <<: *common-config + devices: + - ${SERIAL_PORT:?err} + command: > + ros2 launch rosbot_bringup combined.launch.py + mecanum:=${MECANUM:-False} + serial_port:=$SERIAL_PORT + serial_baudrate:=576000 diff --git a/demo/shm-only.xml b/demo/shm-only.xml new file mode 100644 index 0000000..9b9149d --- /dev/null +++ b/demo/shm-only.xml @@ -0,0 +1,17 @@ + + + + + shm_transport + SHM + + + + + + shm_transport + + false + + + \ No newline at end of file diff --git a/ros_entrypoint.sh b/ros_entrypoint.sh index d785c50..9bbfd75 100755 --- a/ros_entrypoint.sh +++ b/ros_entrypoint.sh @@ -19,6 +19,11 @@ source "/opt/ros/$ROS_DISTRO/setup.bash" source "/ros2_ws/install/setup.bash" source "/ros2_ws_healthcheck/install/setup.bash" -ros2 run healthcheck_pkg healthcheck_node & +if [ -z "$USER" ]; then + export USER=root +elif ! id "$USER" &>/dev/null; then + useradd -ms /bin/bash "$USER" +fi -exec "$@" +gosu $USER bash -c "ros2 run healthcheck_pkg healthcheck_node &" +exec gosu $USER "$@" From 63389a45d340ae599fee2094a5202cb4c53fa546 Mon Sep 17 00:00:00 2001 From: dominikn Date: Fri, 29 Dec 2023 12:11:55 +0100 Subject: [PATCH 2/9] make ros_entrypoint universal --- Dockerfile.hardware | 5 +++++ ros_entrypoint.sh | 12 +----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 74443b3..778ff04 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -135,3 +135,8 @@ ENV ROS_NAMESPACE= HEALTHCHECK --interval=5s --timeout=2s --start-period=10s --retries=6 \ CMD ["/healthcheck.sh"] + +RUN new_content1='source "/ros2_ws_healthcheck/install/setup.bash"' && \ + new_content2='gosu $USER bash -c "ros2 run healthcheck_pkg healthcheck_node &"' && \ + sed -i "/exec/i $new_content1" /ros_entrypoint.sh && \ + sed -i "/exec/i $new_content2" /ros_entrypoint.sh diff --git a/ros_entrypoint.sh b/ros_entrypoint.sh index 9bbfd75..bebe56c 100755 --- a/ros_entrypoint.sh +++ b/ros_entrypoint.sh @@ -6,18 +6,9 @@ if [[ "$HUSARNET_DDS_DEBUG" == "TRUE" ]]; then echo "$output" fi -# Check if XRCE_DOMAIN_ID_OVERRIDE is unset or empty -if [ -z "$XRCE_DOMAIN_ID_OVERRIDE" ]; then - # If ROS_DOMAIN_ID is set and not empty, set XRCE_DOMAIN_ID_OVERRIDE to its value - if [ -n "$ROS_DOMAIN_ID" ]; then - export XRCE_DOMAIN_ID_OVERRIDE="$ROS_DOMAIN_ID" - fi -fi - # setup ros environment source "/opt/ros/$ROS_DISTRO/setup.bash" -source "/ros2_ws/install/setup.bash" -source "/ros2_ws_healthcheck/install/setup.bash" +test -f "/ros2_ws/install/setup.bash" && source "/ros2_ws/install/setup.bash" if [ -z "$USER" ]; then export USER=root @@ -25,5 +16,4 @@ elif ! id "$USER" &>/dev/null; then useradd -ms /bin/bash "$USER" fi -gosu $USER bash -c "ros2 run healthcheck_pkg healthcheck_node &" exec gosu $USER "$@" From e41fd94a92e5142d4fe08546748f71178015d908 Mon Sep 17 00:00:00 2001 From: dominikn Date: Fri, 29 Dec 2023 12:51:41 +0100 Subject: [PATCH 3/9] simplify the Dockerfile thanks to new husarion/ros images --- Dockerfile.gazebo | 8 ++- Dockerfile.hardware | 7 ++- flash-firmware.py | 110 --------------------------------------- ros_entrypoint.sh | 19 ------- vulcanexus_entrypoint.sh | 24 --------- 5 files changed, 9 insertions(+), 159 deletions(-) delete mode 100644 flash-firmware.py delete mode 100755 ros_entrypoint.sh delete mode 100755 vulcanexus_entrypoint.sh diff --git a/Dockerfile.gazebo b/Dockerfile.gazebo index d281b69..0da3f75 100644 --- a/Dockerfile.gazebo +++ b/Dockerfile.gazebo @@ -104,9 +104,13 @@ RUN apt-get update && apt-get install -y \ rm -rf src && \ rm -rf /var/lib/apt/lists/* -COPY ros_entrypoint.sh / -COPY vulcanexus_entrypoint.sh / COPY healthcheck.sh / HEALTHCHECK --interval=5s --timeout=2s --start-period=5s --retries=4 \ CMD ["/healthcheck.sh"] + +RUN new_content1='source "/ros2_ws_healthcheck/install/setup.bash"' && \ + new_content2='gosu $USER bash -c "ros2 run healthcheck_pkg healthcheck_node &"' && \ + file=$(ls /*_entrypoint.sh | head -n 1) && \ + sed -i "/exec/i $new_content1" $file && \ + sed -i "/exec/i $new_content2" $file diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 778ff04..398fb07 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -125,8 +125,6 @@ RUN apt-get update && apt-get install -y \ COPY --from=cpu_id_builder /read_cpu_id/.pio/build/olimex_e407/firmware.bin /firmware_read_cpu_id.bin -COPY ros_entrypoint.sh / -COPY vulcanexus_entrypoint.sh / COPY healthcheck.sh / COPY print-serial-number.py /usr/bin/ @@ -138,5 +136,6 @@ HEALTHCHECK --interval=5s --timeout=2s --start-period=10s --retries=6 \ RUN new_content1='source "/ros2_ws_healthcheck/install/setup.bash"' && \ new_content2='gosu $USER bash -c "ros2 run healthcheck_pkg healthcheck_node &"' && \ - sed -i "/exec/i $new_content1" /ros_entrypoint.sh && \ - sed -i "/exec/i $new_content2" /ros_entrypoint.sh + file=$(ls /*_entrypoint.sh | head -n 1) && \ + sed -i "/exec/i $new_content1" $file && \ + sed -i "/exec/i $new_content2" $file diff --git a/flash-firmware.py b/flash-firmware.py deleted file mode 100644 index 27c0f1b..0000000 --- a/flash-firmware.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/python3 - -import sh -import time -import sys -import argparse -from periphery import GPIO - - -class FirmwareFlasher: - def __init__(self, sys_arch, binary_file): - self.binary_file = binary_file - self.sys_arch = sys_arch - - self.max_approach_no = 3 - - print(f"System architecture: {self.sys_arch}") - - if self.sys_arch.stdout == b"armv7l\n": - # Setups ThinkerBoard pins - print("Device: ThinkerBoard\n") - self.port = "/dev/ttyS1" - boot0_pin_no = 164 - reset_pin_no = 184 - - elif self.sys_arch.stdout == b"x86_64\n": - # Setups UpBoard pins - print("Device: UpBoard\n") - self.port = "/dev/ttyS4" - boot0_pin_no = 17 - reset_pin_no = 18 - - elif self.sys_arch.stdout == b"aarch64\n": - # Setups RPi pins - print("Device: RPi\n") - self.port = "/dev/ttyAMA0" - boot0_pin_no = 17 - reset_pin_no = 18 - - else: - print("Unknown device...") - - self.boot0_pin = GPIO(boot0_pin_no, "out") - self.reset_pin = GPIO(reset_pin_no, "out") - - def enter_bootloader_mode(self): - self.boot0_pin.write(True) - self.reset_pin.write(True) - time.sleep(0.2) - self.reset_pin.write(False) - time.sleep(0.2) - - def exit_bootloader_mode(self): - self.boot0_pin.write(False) - self.reset_pin.write(True) - time.sleep(0.2) - self.reset_pin.write(False) - time.sleep(0.2) - - def try_flash_operation(self, operation_name, flash_command, flash_args): - for i in range(self.max_approach_no): - try: - flash_command(self.port, *flash_args, _out=sys.stdout) - time.sleep(0.2) - break - except Exception as e: - print(f"{operation_name} error! Trying again.") - print(f"Error: {e}") - print("---------------------------------------") - else: - print(f"WARNING! {operation_name} went wrong.") - - def flash_firmware(self): - self.enter_bootloader_mode() - - # Disable the flash write-protection - self.try_flash_operation("Write-UnProtection", sh.stm32flash, ["-u"]) - - # Disable the flash read-protection - self.try_flash_operation("Read-UnProtection", sh.stm32flash, ["-k"]) - - # Flashing the firmware - flash_args = ["-v", "-w", self.binary_file, "-b", "115200"] - self.try_flash_operation("Flashing", sh.stm32flash, flash_args) - - self.exit_bootloader_mode() - - -def main(): - parser = argparse.ArgumentParser( - description="Flashing the firmware on STM32 microcontroller in ROSbot" - ) - - parser.add_argument( - "file", - nargs="?", - default="/root/firmware.bin", - help="Path to a firmware file. Default = /root/firmware.bin", - ) - - binary_file = parser.parse_args().file - sys_arch = sh.uname("-m") - - flasher = FirmwareFlasher(sys_arch, binary_file) - flasher.flash_firmware() - print("Done!") - - -if __name__ == "__main__": - main() diff --git a/ros_entrypoint.sh b/ros_entrypoint.sh deleted file mode 100755 index bebe56c..0000000 --- a/ros_entrypoint.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -set -e - -output=$(husarnet-dds singleshot) || true -if [[ "$HUSARNET_DDS_DEBUG" == "TRUE" ]]; then - echo "$output" -fi - -# setup ros environment -source "/opt/ros/$ROS_DISTRO/setup.bash" -test -f "/ros2_ws/install/setup.bash" && source "/ros2_ws/install/setup.bash" - -if [ -z "$USER" ]; then - export USER=root -elif ! id "$USER" &>/dev/null; then - useradd -ms /bin/bash "$USER" -fi - -exec gosu $USER "$@" diff --git a/vulcanexus_entrypoint.sh b/vulcanexus_entrypoint.sh deleted file mode 100755 index a1d99ff..0000000 --- a/vulcanexus_entrypoint.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -set -e - -output=$(husarnet-dds singleshot) || true -if [[ "$HUSARNET_DDS_DEBUG" == "TRUE" ]]; then - echo "$output" -fi - -# Check if XRCE_DOMAIN_ID_OVERRIDE is unset or empty -if [ -z "$XRCE_DOMAIN_ID_OVERRIDE" ]; then - # If ROS_DOMAIN_ID is set and not empty, set XRCE_DOMAIN_ID_OVERRIDE to its value - if [ -n "$ROS_DOMAIN_ID" ]; then - export XRCE_DOMAIN_ID_OVERRIDE="$ROS_DOMAIN_ID" - fi -fi - -# setup ros environment -source "/opt/vulcanexus/$ROS_DISTRO/setup.bash" -source "/ros2_ws/install/setup.bash" -source "/ros2_ws_healthcheck/install/setup.bash" - -ros2 run healthcheck_pkg healthcheck_node & - -exec "$@" From 3cdeeae39bf637ea825f57f524d077d42671b4e8 Mon Sep 17 00:00:00 2001 From: dominikn Date: Fri, 29 Dec 2023 15:32:41 +0100 Subject: [PATCH 4/9] building docker image --- Dockerfile.hardware | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 398fb07..e77e35b 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -1,5 +1,6 @@ ARG ROS_DISTRO=humble ARG PREFIX= +ARG ROS_PKG_RELEASE=0.11.1 ## =========================== Firmware CPU ID ================================ @@ -56,6 +57,7 @@ FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder ARG ROS_DISTRO ARG PREFIX +ARG ROS_PKG_RELEASE SHELL ["/bin/bash", "-c"] @@ -67,7 +69,7 @@ COPY ./healthcheck.cpp / RUN apt-get update && apt-get install -y \ python3-pip -RUN git clone --depth 1 -b humble https://github.com/husarion/rosbot_ros.git src && \ +RUN git clone --depth 1 -b ${ROS_PKG_RELEASE} https://github.com/husarion/rosbot_ros.git src && \ vcs import src < src/rosbot/rosbot_hardware.repos && \ cp -r src/ros2_controllers/diff_drive_controller src/ && \ cp -r src/ros2_controllers/imu_sensor_broadcaster src/ && \ @@ -82,6 +84,7 @@ RUN git clone --depth 1 -b humble https://github.com/husarion/rosbot_ros.git src MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \ source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \ colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release && \ + echo $(cat /ros2_ws/src/rosbot/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \ rm -rf build log ## =========================== Final Stage =============================== @@ -95,6 +98,7 @@ SHELL ["/bin/bash", "-c"] WORKDIR /ros2_ws COPY --from=ros_builder /ros2_ws /ros2_ws +COPY --from=ros_builder /version.txt /version.txt COPY --from=healthcheck_builder /ros2_ws /ros2_ws_healthcheck # for backward compatibility @@ -113,8 +117,6 @@ RUN apt-get update && apt-get install -y \ rosdep init && \ rosdep update --rosdistro $ROS_DISTRO && \ rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \ - # Save version - echo $(cat /ros2_ws/src/rosbot/package.xml | grep '' | sed -r 's/.*([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \ # Size optimalization apt-get remove -y \ python3-rosdep \ From 7b3cb6c69614370720cbd727ec9dcf86f40786ad Mon Sep 17 00:00:00 2001 From: dominikn Date: Fri, 29 Dec 2023 19:18:04 +0100 Subject: [PATCH 5/9] calculate the serial number from ros service --- Dockerfile.hardware | 22 ----- print-serial-number.py | 181 ++++++++++++------------------------- read_cpu_id/platformio.ini | 27 ------ read_cpu_id/src/main.cpp | 26 ------ 4 files changed, 56 insertions(+), 200 deletions(-) delete mode 100644 read_cpu_id/platformio.ini delete mode 100644 read_cpu_id/src/main.cpp diff --git a/Dockerfile.hardware b/Dockerfile.hardware index e77e35b..1b7bc17 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -2,26 +2,6 @@ ARG ROS_DISTRO=humble ARG PREFIX= ARG ROS_PKG_RELEASE=0.11.1 -## =========================== Firmware CPU ID ================================ - -FROM ubuntu:20.04 AS cpu_id_builder - -SHELL ["/bin/bash", "-c"] - -# official releases are only for intel archs, so we need to build stm32flash from sources -RUN apt-get update && apt-get install -y \ - curl \ - python3 \ - python3-pip - -# build a binary for reading the CPU ID -COPY read_cpu_id/ /read_cpu_id - -RUN pip3 install -U platformio && \ - cd /read_cpu_id && \ - pio run && \ - chmod -x .pio/build/olimex_e407/firmware.bin - ## =========================== Healthcheck builder =============================== FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS healthcheck_builder @@ -125,8 +105,6 @@ RUN apt-get update && apt-get install -y \ rm -rf src && \ rm -rf /var/lib/apt/lists/* -COPY --from=cpu_id_builder /read_cpu_id/.pio/build/olimex_e407/firmware.bin /firmware_read_cpu_id.bin - COPY healthcheck.sh / COPY print-serial-number.py /usr/bin/ diff --git a/print-serial-number.py b/print-serial-number.py index 01a34bf..e353cd2 100755 --- a/print-serial-number.py +++ b/print-serial-number.py @@ -1,130 +1,61 @@ #!/usr/bin/env python3 +import subprocess +import json import hashlib -import serial import string -import sh -import argparse -import sys -from periphery import GPIO - - -class SerialNumberGenerator: - def __init__(self, sys_arch, binary_file): - self.binary_file = binary_file - self.sys_arch = sys_arch - - print(f"System architecture: {self.sys_arch}") - - if self.sys_arch.stdout == b"armv7l\n": - # Setups ThinkerBoard pins - print("Device: ThinkerBoard\n") - self.port = "/dev/ttyS1" - boot0_pin_no = 164 - reset_pin_no = 184 - - elif self.sys_arch.stdout == b"x86_64\n": - # Setups UpBoard pins - print("Device: UpBoard\n") - self.port = "/dev/ttyS4" - boot0_pin_no = 17 - reset_pin_no = 18 - - elif self.sys_arch.stdout == b"aarch64\n": - # Setups RPi pins - print("Device: RPi\n") - self.port = "/dev/ttyAMA0" - boot0_pin_no = 17 - reset_pin_no = 18 - +import re + +def get_cpu_id_from_ros_service(): + try: + # Run the ROS service call command + result = subprocess.run(['ros2', 'service', 'call', '/get_cpu_id', 'std_srvs/srv/Trigger'], + capture_output=True, text=True, timeout=30) + + # Regular expression to extract JSON from the response + match = re.search(r"message='(\{.*\})'", result.stdout) + if match: + json_str = match.group(1) + json_data = json.loads(json_str) + cpu_id = json_data['cpu_id'] + return cpu_id else: - print("Unknown device...") - - self.boot0_pin = GPIO(boot0_pin_no, "out") - self.reset_pin = GPIO(reset_pin_no, "out") - - def hex_to_num(self, hex_str): - # Check if the hex string is valid - if not all(c in string.hexdigits for c in hex_str): - raise ValueError("Invalid hex string") - - # Convert the hex string to bytes - try: - hex_bytes = bytes.fromhex(hex_str) - except ValueError: - raise ValueError("Invalid hex string") - - # Compute the SHA-256 hash of the hex bytes - hash = hashlib.sha256(hex_bytes).hexdigest() - - # Truncate the hash to 6 characters - hash = hash[:6] - - # Return the hash as an ASCII string - return hash - - def to_two_digit_hex(self, hex_str): - # Pad the hex string with a leading zero if it is a single-digit string - if len(hex_str) == 1: - hex_str = "0" + hex_str - return hex_str - - def convert_hex_string(self, hex_str): - # Split the hex string into a list of hexadecimal values - hex_values = hex_str.split() - # Convert each hexadecimal value to a two-digit string - hex_values = [self.to_two_digit_hex(x) for x in hex_values] - # Join the list of hexadecimal values into a single string - hex_str = "".join(hex_values) - return hex_str - - def generate(self): - print("flash the firmware that prints STM32 unique ID") - sh.python3("/usr/bin/flash-firmware.py", self.binary_file) - print("done") - print("") - - # Open the serial port - with serial.Serial(self.port, baudrate=9600, timeout=1) as stm32_serial: - # Read a line of input from the serial port - hex_str = stm32_serial.readline().decode("utf-8").strip() - hex_str = self.convert_hex_string(hex_str) - - print(f"CPU ID = 0x{hex_str}") - - # Remove the spaces in the hex string - hex_str = hex_str.replace(" ", "") - - # Convert the hex string to a 6-character ASCII string - result = self.hex_to_num(hex_str) - # Print the result to the console - print(f"Serial Number = {result}") - print() - - # Close the serial port - stm32_serial.close() - return result - - -def main(): - parser = argparse.ArgumentParser(description="Printing ROSbot 2R / 2 PRO serial number") - - parser.add_argument( - "-f", - "--file", - nargs="?", - default="/firmware_read_cpu_id.bin", - help="Path to a firmware file. Default: /firmware_read_cpu_id.bin", - ) - - binary_file = parser.parse_args().file - sys_arch = sh.uname("-m") - - sn = SerialNumberGenerator(sys_arch, binary_file) - serialNumber = sn.generate() - - sys.exit(serialNumber) - - -if __name__ == "__main__": - main() + print("JSON response not found in the output.") + return None + except subprocess.SubprocessError as e: + print(f"Error during ROS service call: {e}") + return None + except json.JSONDecodeError as e: + print(f"JSON parsing error: {e}") + return None + +def hex_to_num(hex_str): + # Check if the hex string is valid + if not all(c in string.hexdigits for c in hex_str): + raise ValueError("Invalid hex string") + + # Convert the hex string to bytes + hex_bytes = bytes.fromhex(hex_str) + + # Compute the SHA-256 hash of the hex bytes + hash = hashlib.sha256(hex_bytes).hexdigest() + + # Truncate the hash to 6 characters + hash = hash[:6] + + # Return the hash as an ASCII string + return hash + +try: + # Obtain CPU ID from ROS service + cpu_id = get_cpu_id_from_ros_service() + + if cpu_id: + # Calculate the serial number + serial_number = hex_to_num(cpu_id) + print(f"CPU ID: 0x{cpu_id}") + print(f"Serial Number: {serial_number}") + else: + print("Failed to obtain CPU ID.") +except Exception as e: + print(f"An error occurred: {e}") diff --git a/read_cpu_id/platformio.ini b/read_cpu_id/platformio.ini deleted file mode 100644 index d9a534b..0000000 --- a/read_cpu_id/platformio.ini +++ /dev/null @@ -1,27 +0,0 @@ -[env:olimex_e407] -platform = ststm32 -framework = arduino - -platform_packages = - platformio/toolchain-gccarmnoneeabi@^1.100301.220327 - -board = olimex_e407 -; board = black_f407zg - -; change microcontroller -board_build.mcu = stm32f407zgt6 - -; change MCU frequency -board_build.f_cpu = 168000000L - -; change upload protocol (stlink or serial) -upload_protocol = stlink -; upload_protocol = serial - -monitor_speed = 460800 - -build_flags = - -D SERIAL_UART_INSTANCE=1 - -D TARGET_STM32F4 - -debug_tool = stlink diff --git a/read_cpu_id/src/main.cpp b/read_cpu_id/src/main.cpp deleted file mode 100644 index f7ccf23..0000000 --- a/read_cpu_id/src/main.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -const uint32_t ADDRESS = 0x1FFF7A10; -const uint8_t NUM_BYTES = 12; -uint8_t buffer[NUM_BYTES]; - -void setup() { - Serial1.setRx(PA10); - Serial1.setTx(PA9); - Serial1.begin(9600); - - // Read the bytes from the specified address into the buffer - memcpy(buffer, (void *)ADDRESS, NUM_BYTES); -} - -void loop() { - // Print the bytes to the terminal - for (int i = 0; i < NUM_BYTES; i++) { - Serial1.print(buffer[i], HEX); - Serial1.print(" "); - } - Serial1.println(); - - // Wait for a second before printing again - delay(1000); -} From 9d493bf0785ca0581aa8bb496b2ecf440324df10 Mon Sep 17 00:00:00 2001 From: dominikn Date: Tue, 2 Jan 2024 16:38:56 +0100 Subject: [PATCH 6/9] working healthcheck --- Dockerfile.hardware | 12 ++++-------- demo/compose.build.yaml | 6 ++++++ healthcheck.sh | 1 - run_healthcheck_node.sh | 2 ++ 4 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 run_healthcheck_node.sh diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 1b7bc17..28664db 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -1,6 +1,5 @@ ARG ROS_DISTRO=humble ARG PREFIX= -ARG ROS_PKG_RELEASE=0.11.1 ## =========================== Healthcheck builder =============================== @@ -37,7 +36,6 @@ FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder ARG ROS_DISTRO ARG PREFIX -ARG ROS_PKG_RELEASE SHELL ["/bin/bash", "-c"] @@ -49,7 +47,7 @@ COPY ./healthcheck.cpp / RUN apt-get update && apt-get install -y \ python3-pip -RUN git clone --depth 1 -b ${ROS_PKG_RELEASE} https://github.com/husarion/rosbot_ros.git src && \ +RUN git clone --depth 1 -b humble https://github.com/husarion/rosbot_ros.git src && \ vcs import src < src/rosbot/rosbot_hardware.repos && \ cp -r src/ros2_controllers/diff_drive_controller src/ && \ cp -r src/ros2_controllers/imu_sensor_broadcaster src/ && \ @@ -106,6 +104,7 @@ RUN apt-get update && apt-get install -y \ rm -rf /var/lib/apt/lists/* COPY healthcheck.sh / +COPY run_healthcheck_node.sh / COPY print-serial-number.py /usr/bin/ @@ -114,8 +113,5 @@ ENV ROS_NAMESPACE= HEALTHCHECK --interval=5s --timeout=2s --start-period=10s --retries=6 \ CMD ["/healthcheck.sh"] -RUN new_content1='source "/ros2_ws_healthcheck/install/setup.bash"' && \ - new_content2='gosu $USER bash -c "ros2 run healthcheck_pkg healthcheck_node &"' && \ - file=$(ls /*_entrypoint.sh | head -n 1) && \ - sed -i "/exec/i $new_content1" $file && \ - sed -i "/exec/i $new_content2" $file +RUN sed -i "/# /r /run_healthcheck_node.sh" /ros_entrypoint.sh && \ + sed -i "/# /d" /ros_entrypoint.sh diff --git a/demo/compose.build.yaml b/demo/compose.build.yaml index a958ba9..50afa6a 100644 --- a/demo/compose.build.yaml +++ b/demo/compose.build.yaml @@ -19,10 +19,16 @@ services: context: .. dockerfile: Dockerfile.hardware <<: *common-config + privileged: true devices: - ${SERIAL_PORT:?err} + environment: + - ROS_NAMESPACE=rosbot + # command: tail -f /dev/null + # command: ros2 run rosbot_utils flash_firmware --usb command: > ros2 launch rosbot_bringup combined.launch.py mecanum:=${MECANUM:-False} serial_port:=$SERIAL_PORT serial_baudrate:=576000 + namespace:=rosbot diff --git a/healthcheck.sh b/healthcheck.sh index 7cae7a1..aeb59ae 100755 --- a/healthcheck.sh +++ b/healthcheck.sh @@ -2,7 +2,6 @@ HEALTHCHECK_FILE="/var/tmp/health_status.txt" - # Now check the health status if [ -f "$HEALTHCHECK_FILE" ]; then status=$(cat "$HEALTHCHECK_FILE") diff --git a/run_healthcheck_node.sh b/run_healthcheck_node.sh new file mode 100644 index 0000000..5ed31ae --- /dev/null +++ b/run_healthcheck_node.sh @@ -0,0 +1,2 @@ +source "/ros2_ws_healthcheck/install/setup.bash" +gosu $USER bash -c "ros2 run healthcheck_pkg healthcheck_node &" From f35e1b69a7404bd47e47e6660f67e4aa89eb6ef6 Mon Sep 17 00:00:00 2001 From: dominikn Date: Tue, 2 Jan 2024 16:51:04 +0100 Subject: [PATCH 7/9] fix also gazebo dockerfile --- Dockerfile.gazebo | 8 +++----- demo/compose.gazebo.yaml | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Dockerfile.gazebo b/Dockerfile.gazebo index 0da3f75..ef3af09 100644 --- a/Dockerfile.gazebo +++ b/Dockerfile.gazebo @@ -105,12 +105,10 @@ RUN apt-get update && apt-get install -y \ rm -rf /var/lib/apt/lists/* COPY healthcheck.sh / +COPY run_healthcheck_node.sh / HEALTHCHECK --interval=5s --timeout=2s --start-period=5s --retries=4 \ CMD ["/healthcheck.sh"] -RUN new_content1='source "/ros2_ws_healthcheck/install/setup.bash"' && \ - new_content2='gosu $USER bash -c "ros2 run healthcheck_pkg healthcheck_node &"' && \ - file=$(ls /*_entrypoint.sh | head -n 1) && \ - sed -i "/exec/i $new_content1" $file && \ - sed -i "/exec/i $new_content2" $file +RUN sed -i "/# /r /run_healthcheck_node.sh" /ros_entrypoint.sh && \ + sed -i "/# /d" /ros_entrypoint.sh diff --git a/demo/compose.gazebo.yaml b/demo/compose.gazebo.yaml index 8e67483..aa903d4 100644 --- a/demo/compose.gazebo.yaml +++ b/demo/compose.gazebo.yaml @@ -24,7 +24,7 @@ services: build: context: ../ dockerfile: Dockerfile.gazebo - <<: [ *cpu-config] + <<: [ *gpu-config] volumes: - /tmp/.X11-unix:/tmp/.X11-unix:rw command: ros2 launch rosbot_gazebo simulation.launch.py mecanum:=${MECANUM:-False} From 5517f87d3c42f1ed1adbf5c8ff4b7d244d6f452d Mon Sep 17 00:00:00 2001 From: dominikn Date: Tue, 2 Jan 2024 17:27:35 +0100 Subject: [PATCH 8/9] using *_entrypoint --- Dockerfile.gazebo | 4 ++-- Dockerfile.hardware | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile.gazebo b/Dockerfile.gazebo index ef3af09..c1b1694 100644 --- a/Dockerfile.gazebo +++ b/Dockerfile.gazebo @@ -110,5 +110,5 @@ COPY run_healthcheck_node.sh / HEALTHCHECK --interval=5s --timeout=2s --start-period=5s --retries=4 \ CMD ["/healthcheck.sh"] -RUN sed -i "/# /r /run_healthcheck_node.sh" /ros_entrypoint.sh && \ - sed -i "/# /d" /ros_entrypoint.sh +RUN sed -i "/# /r /run_healthcheck_node.sh" /*_entrypoint.sh && \ + sed -i "/# /d" /*_entrypoint.sh diff --git a/Dockerfile.hardware b/Dockerfile.hardware index 28664db..ad4833f 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -113,5 +113,5 @@ ENV ROS_NAMESPACE= HEALTHCHECK --interval=5s --timeout=2s --start-period=10s --retries=6 \ CMD ["/healthcheck.sh"] -RUN sed -i "/# /r /run_healthcheck_node.sh" /ros_entrypoint.sh && \ - sed -i "/# /d" /ros_entrypoint.sh +RUN sed -i "/# /r /run_healthcheck_node.sh" /*_entrypoint.sh && \ + sed -i "/# /d" /*_entrypoint.sh From 9f156b66c9f6d9af38cb7690854fd8acc26b49bd Mon Sep 17 00:00:00 2001 From: dominikn Date: Thu, 4 Jan 2024 12:46:25 +0100 Subject: [PATCH 9/9] replace ROS_NAMESPACE with ROBOT_NAMESPACE --- Dockerfile.hardware | 2 +- demo/compose.build.yaml | 8 ++++---- healthcheck.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile.hardware b/Dockerfile.hardware index ad4833f..0fbee4a 100644 --- a/Dockerfile.hardware +++ b/Dockerfile.hardware @@ -108,7 +108,7 @@ COPY run_healthcheck_node.sh / COPY print-serial-number.py /usr/bin/ -ENV ROS_NAMESPACE= +ENV ROBOT_NAMESPACE= HEALTHCHECK --interval=5s --timeout=2s --start-period=10s --retries=6 \ CMD ["/healthcheck.sh"] diff --git a/demo/compose.build.yaml b/demo/compose.build.yaml index 50afa6a..4731532 100644 --- a/demo/compose.build.yaml +++ b/demo/compose.build.yaml @@ -9,7 +9,7 @@ x-common-config: ipc: host environment: - FASTRTPS_DEFAULT_PROFILES_FILE=/shm-only.xml - - ROS_DOMAIN_ID=10 + # - ROS_DOMAIN_ID=10 - USER services: @@ -22,8 +22,8 @@ services: privileged: true devices: - ${SERIAL_PORT:?err} - environment: - - ROS_NAMESPACE=rosbot + # environment: + # - ROS_NAMESPACE=rosbot # command: tail -f /dev/null # command: ros2 run rosbot_utils flash_firmware --usb command: > @@ -31,4 +31,4 @@ services: mecanum:=${MECANUM:-False} serial_port:=$SERIAL_PORT serial_baudrate:=576000 - namespace:=rosbot +# namespace:=rosbot diff --git a/healthcheck.cpp b/healthcheck.cpp index 8218c90..7b516cb 100644 --- a/healthcheck.cpp +++ b/healthcheck.cpp @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) { rclcpp::init(argc, argv); std::string topic = "odometry/filtered"; - if(const char* ns = std::getenv("ROS_NAMESPACE")) { + if(const char* ns = std::getenv("ROBOT_NAMESPACE")) { topic = std::string(ns) + "/" + topic; }