diff --git a/robots/_rosbot_2_reset_mcu/reset-mcu.py b/robots/_rosbot_2_reset_mcu/reset-mcu.py new file mode 100755 index 0000000..d22f82d --- /dev/null +++ b/robots/_rosbot_2_reset_mcu/reset-mcu.py @@ -0,0 +1,48 @@ +#!/usr/bin/python3 +import sh +import time +from periphery import GPIO + +def exit_bootloader_mode(boot0_pin_number, reset_pin_number): + boot0_pin = GPIO(boot0_pin_number, "out") + reset_pin = GPIO(reset_pin_number, "out") + boot0_pin.write(False) + reset_pin.write(True) + time.sleep(0.2) + reset_pin.write(False) + time.sleep(0.2) + + +def main(): + sys_arch = sh.uname('-m') + print(f"System architecture: {sys_arch}") + + boot0_pin_number = None + reset_pin_number = None + + if sys_arch.stdout == b'armv7l\n': + # Setups ThinkerBoard pins + print("Device: ThinkerBoard\n") + boot0_pin_number = 164 + reset_pin_number = 184 + + elif sys_arch.stdout == b'x86_64\n': + # Setups UpBoard pins + print("Device: UpBoard\n") + boot0_pin_number = 17 + reset_pin_number = 18 + + elif sys_arch.stdout == b'aarch64\n': + # Setups RPi pins + print("Device: RPi\n") + boot0_pin_number = 17 + reset_pin_number = 18 + + else: + raise Exception("Unknown device...") + + exit_bootloader_mode(boot0_pin_number, reset_pin_number) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/robots/_rosbot_2_reset_mcu/reset-mcu.service b/robots/_rosbot_2_reset_mcu/reset-mcu.service new file mode 100755 index 0000000..e52f5eb --- /dev/null +++ b/robots/_rosbot_2_reset_mcu/reset-mcu.service @@ -0,0 +1,10 @@ +[Unit] +Description=Reset MCU in ROSbot 2R / 2 PRO on startup + +[Service] +Type=simple +ExecStart=/usr/local/sbin/reset-mcu.py +RemainAfterExit=no + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/robots/rosbot_2_pro/custom_config.sh b/robots/rosbot_2_pro/custom_config.sh index 09345ed..ee3ccf6 100755 --- a/robots/rosbot_2_pro/custom_config.sh +++ b/robots/rosbot_2_pro/custom_config.sh @@ -2,4 +2,10 @@ # If a particular robot requires any extra custom configuration steps, they should be included in this file. -echo "no additional custom configuration for ROSbot 2R" \ No newline at end of file +echo "enable reset MCU service" + +cp ../_rosbot_2_reset_mcu/reset-mcu.py /usr/local/sbin/reset-mcu.py +cp ../_rosbot_2_reset_mcu/reset-mcu.service /etc/systemd/system/reset-mcu.service + +systemctl enable reset-mcu.service +systemctl start reset-mcu.service diff --git a/robots/rosbot_2r/custom_config.sh b/robots/rosbot_2r/custom_config.sh index 09345ed..ee3ccf6 100755 --- a/robots/rosbot_2r/custom_config.sh +++ b/robots/rosbot_2r/custom_config.sh @@ -2,4 +2,10 @@ # If a particular robot requires any extra custom configuration steps, they should be included in this file. -echo "no additional custom configuration for ROSbot 2R" \ No newline at end of file +echo "enable reset MCU service" + +cp ../_rosbot_2_reset_mcu/reset-mcu.py /usr/local/sbin/reset-mcu.py +cp ../_rosbot_2_reset_mcu/reset-mcu.service /etc/systemd/system/reset-mcu.service + +systemctl enable reset-mcu.service +systemctl start reset-mcu.service