Upload Ardusub code to pixhawk using waf

Hello,
I have recently started working with a BlueRov2 and I the reason I am writing this post is to get help uploading code to the pixhawk.
After downloading the ardupilot repository, I made some modifications (just some simple methods on the joystick.cpp custom cases) and now I am trying to follow the instructions to upload the code using waf. However I have some difficulties.

I first used the following line to configure the board (I think that is the px4-v2 model) and everything went well.

./waf configure --board px4-v2
->‘configure’ finished successfully (0.592s)

Now I think I should use this one to upload it to the pixhawk:
./waf configure --board --rsync-dest
In my case:
./waf configure --board px4-v2 --rsync-dest pi@192.168.2.2…???

How should I continue?

I hope my problem was correctly explained.

Finally, I would also like to know why the library is switching to using waf instead of the classic cmakelists, a common known standart tool to build code.

Thank you for your time,
Alexis

Hi Alexis,

To build ardusub, you will need to configure waf to create a pixhawk v2 binary.

  • ./waf configure --board px4-v2

After that, it will be necessary to build ardusub and not others vehicles.

  • ./waf build sub --verbose

Now, to upload ardusub, you’ll need to connect the pixhawk in your computer and do the upload.

  • ./waf --upload sub

It’s not possible to update ardusub via rsync, this argument is used for Linux boards, in BlueROV2 the raspberry is used only as a companion computer and not to control the ROV itself.

This is for historical reasons in ArduPilot project, but before waf the build system was Makefiles and not CMakeLists.

You will not be able to upload to the autopilot connected to a remote host with the build tools in the ardupilot repository alone.

You will need to transfer the file to the remote host, and then run the px_uploader.py script located in the tools directory of the arudpilot repository (transfer the script to the remote host, too).

If you are using a BlueROV2, or a Raspberry Pi with our companion computer image, then an easier way might be to use the UI at http://192.168.2.2:2770/system.

Thank you for your replies.
Patrick José I am no sure I did understand the line “./waf --upload sub”. Should I run this from inside the pixhawk? How can the command know where to upload the “sub”?

On the other hand, It may be easier to follow Jacob instructions. I should be able to send the binaries/files created by waf via scp to the raspberry pi (we are using your companion computer image) and then use the script px_uploader.py to upload it to the pixhawk. I will try to understand it’s usage.
I will also take a look at the UI you mention. I did not know that utility. Why 2770? Is it a random number defined by BlueRobotics?

Sorry for this questions which may be basic for you but I am still a student and I have difficulties finding documentation.

Hi Alexis,

Sorry for not putting this in a clear way.

All commands of my previous post should be done in the root folder of your ArduPilot source code, it’s the local of waf script. The pixhawk should be connected in your computer usb.

To do what Jacob said, related to http://192.168.2.2:2770/system webpage, you will need:

  • Build ArduSub with ./waf build sub
  • Go to the /system webpage.
  • Select Choose File, the .px4 file will be in build/px4-v2/bin inside ArduPilot root folder.
  • Click in Upload.
    After that, you will see the flash process happening.
Attempting upload from file /tmp/data/ardusub.px4
Stopping mavproxy
Flashing Pixhawk...
Loaded firmware for 9,0, size: 909212 bytes, waiting for the bootloader...
attempting reboot on /dev/ttyACM0...
Found board 9,0 bootloader rev 4 on /dev/ttyACM0
ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff 
Erase  : [====================] 100.0%
Program: [====================] 100.0%
Verify : [====================] 100.0%
Rebooting.

Waiting to restart mavproxy...
Restarting mavproxy
Complete!

Yes.

Hello Jacob and Patrick,
Sorry for the late reply. Everything now is clear and working. Thank you for your assistance.
Alexis

1 Like

Which directory should I be in to do this terminal flashing?

The usual ardupilot folder is not doing the job for me.
Let me check the GUI Flashing method.

Thanks for the info anyway.

I have an issue @patrickelectric , you commented that all the commands that you talk about were to be executed on the root folder of the ArduPilot. For this, should I insert the SD card from the pixhawk to the computer, run the commands given, which will compile and upload the (modified) firmware on it.

Later on, I can insert it on the pixhawk with the changes uploaded.

Or the Arduipilot root folder can be access from the companion (raspberry)? If so, do you know about the path for it? There is a ardusub folder on the companion, but containing different information, python code, and shell scripts, looks different from the ardusub git repo.

Thanks in advance.

Hi @reimonha, welcome to the forum :slight_smile:

You may wish to look through our uploading ArduSub docs.

To clarify Patrick’s points above:

  1. configuring waf and building ArduSub should be done from the root of the ardupilot source code repository on your topside computer
  2. for uploading firmware,
    • if you want you can use waf to upload to a Pixhawk that has a direct USB connection to your topside computer, but
    • it would be most common to upload via the Companion (or BlueOS) web interface (from a browser in your topside computer), when the Pixhawk is connected via USB to the onboard (Raspberry Pi) computer
1 Like

Thanks a lot @EliotBR for your response, the process is now more clear, but I got another issue now on hands, I dont know if I should made a different post, but as it is on line with this post subject, I will keep it here.

Before running the ./waf build sub, command promt is telling me to first run ./waf configure. For this, running alone any of this work, it opens VScode with the waf code, I see it is a python code, thus, i run it with python ./waf

Python version: Python 3.10.6

It requires g++ compiler, I installed it from MinGW - Minimalist GNU for Windows download | SourceForge.net , it is recognized and on path.

g++.exe (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Nevertheless, when run python ./waf configure it print this:

Setting top to                           : C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot 
Setting out to                           : C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\build
Autoconfiguration                        : enabled
Setting board to                         : sitl
Using toolchain                          : native
Checking for 'g++' (C++ compiler)        : Traceback (most recent call last):
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\modules\waf\waflib\Scripting.py", line 158, in waf_entry_point
    run_commands()
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\modules\waf\waflib\Scripting.py", line 251, in run_commands
    ctx = run_command(cmd_name)
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\modules\waf\waflib\Scripting.py", line 235, in run_command
    ctx.execute()
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\modules\waf\waflib\Configure.py", line 159, in execute
    super(ConfigurationContext, self).execute()
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\modules\waf\waflib\Context.py", line 204, in execute
    self.recurse([os.path.dirname(g_module.root_path)])
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\modules\waf\waflib\Context.py", line 286, in recurse
    user_function(self)
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\wscript", line 441, in configure
    cfg.get_board().configure(cfg)
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\Tools/ardupilotwaf\boards.py", line 41, in configure
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\modules\waf\waflib\Tools\gxx.py", line 152, in configure
    conf.find_gxx()
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\modules\waf\waflib\Configure.py", line 316, in fun
    return f(*k, **kw)
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\Tools/ardupilotwaf\toolchain.py", line 32, in find_gxx
    conf.get_cc_version(cxx, gcc=True)
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\modules\waf\waflib\Configure.py", line 316, in fun
    return f(*k, **kw)
  File "C:\Users\ramon\Documents\Stan\ROV\ArduSub\ardupilot\modules\waf\waflib\Tools\c_config.py", line 1014, in get_cc_version
    out, err = conf.cmd_and_log(cmd, output=0, stdin=open('/dev/null','r'), env=env)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/null'

I ran all this from the ardupilot root folder on the topside computer.

Thanks.

Are you following the build instructions, or something else? Configure should be run with a specified board, and the build environment should be set up beforehand.

Yes, I have follow the instruction step by step.

About that problem, i already solved it, installing again the g++ and gcc compilers. Some errors have pop out but i was able to solve them, nevertheless now I am facing an issue that I dont even know what it is doing.

I attach the screenshot with the issue, this comes when running the waf configure.

Everything was going good, but it tries to open a file, I see the path is no right because it is a path inside a path, that is why the argument (path) is invalid, and is understandable why it is failing, the issue is that I am not so sure how to fix that path, or in which script that command is getting executed.

I am working with Windows 10, Python 3.10.7, gcc and g++ (MinGW.org GCC-6.3.0-1) 6.3.0 (from my last post I change laptop).

Glad to hear it! :slight_smile:

I’m also not sure why or where it’s doing that. Given the error message specifies there’s a complete log in C:\Users\stan\Documents\ardupilot\build\config.log can you check there to see if there’s a more complete error message, before we try digging into the internals of waf?

Yes, sorry i didn’t attach that, but even though for me that log was not of much help, hope you can understand it better.
config_220926.txt (32.9 KB)

Hi @EliotBR , a little update.

I dig more into the code, i had to modify it a little but, but i was able to configure it, but now, when i run “./waf build sub” i get the next:

I already try opening cmd as administrator and even using gsudo for the permissions, but no luck.

Thanks.

Good to hear! :slight_smile:

Not sure what’s going on here, so I’ve asked our software team in case they have some ideas :slight_smile:

Following up:

That also matches the ArduPilot docs, which note that

If you don’t want to use WSL, perhaps someone in the general ArduPilot forum has some more experience with waf on Windows with Cygwin :slight_smile:

Hi @EliotBR , thanks for the response, i have follow more the WSL installation, and now i am running it with it.

image
image

Configuration is done correctly, but now build command now breaks somewhere else:

rov@GWTN156-7:/mnt/c/Users/stan/ardupilot$ sudo python3 waf build sub
Setting top to                           : /mnt/c/Users/stan/ardupilot
Setting out to                           : /mnt/c/Users/stan/ardupilot/build
Autoconfiguration                        : enabled
Setting board to                         : Pixhawk1
Using toolchain                          : arm-none-eabi
Checking for 'g++' (C++ compiler)        : /usr/bin/arm-none-eabi-g++
Checking for 'gcc' (C compiler)          : /usr/bin/arm-none-eabi-gcc
Checking for c flags '-MMD'              : yes
Checking for cxx flags '-MMD'            : yes
CXX Compiler                             : g++ 10.3.1
Checking for program 'make'              : /usr/bin/make
Checking for program 'arm-none-eabi-objcopy' : /usr/bin/arm-none-eabi-objcopy
Including /mnt/c/Users/stan/ardupilot/libraries/AP_HAL_ChibiOS/hwdef/fmuv3/hwdef.dat
Setup for MCU STM32F427xx
Writing hwdef setup in /mnt/c/Users/stan/ardupilot/build/Pixhawk1/hwdef.h
Writing DMA map
Generating ldscript.ld
No default parameter file found
Checking for env.py
env set WITH_FATFS=1
env set PROCESS_STACK=0x1C00
env set MAIN_STACK=0x600
env set IOMCU_FW=0
env set PERIPH_FW=0
env set HAL_NUM_CAN_IFACES=2
env set BOARD_FLASH_SIZE=2048
env set CPU_FLAGS=['-mcpu=cortex-m4', '-mfpu=fpv4-sp-d16', '-mfloat-abi=hard', '-DARM_MATH_CM4', '-u_printf_float']
env set CORTEX=cortex-m4
env set APJ_BOARD_ID=9
env set APJ_BOARD_TYPE=STM32F427xx
env set USBID=0x1209/0x5741
env set BOOTLOADER_EMBED=1
env set FLASH_RESERVE_START_KB=16
env set FLASH_TOTAL=2080768
env set CHIBIOS_BUILD_FLAGS=USE_FATFS=yes CHIBIOS_STARTUP_MK=os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk CHIBIOS_PLATFORM_MK=os/hal/ports/STM32/STM32F4xx/platform.mk MCU=cortex-m4 ENV_UDEFS=-DCHPRINTF_USE_FLOAT=1
Enabling ChibiOS asserts                     : no
Enabling malloc guard                        : no
Enabling ChibiOS thread statistics           : no
Enabling -Werror                             : no
Checking for intelhex module:                : disabled
Checking for HAVE_CMATH_ISFINITE             : yes
Checking for HAVE_CMATH_ISINF                : yes
Checking for HAVE_CMATH_ISNAN                : yes
Checking for NEED_CMATH_ISFINITE_STD_NAMESPACE : yes
Checking for NEED_CMATH_ISINF_STD_NAMESPACE    : yes
Checking for NEED_CMATH_ISNAN_STD_NAMESPACE    : yes
Checking for header endian.h                   : not found
Checking for header byteswap.h                 : not found
Checking for HAVE_MEMRCHR                      : no
Checking for program 'python'                  : /usr/bin/python3
Checking for python version >= 2.7.0           : 3.10.6
Checking for program 'python'                  : /usr/bin/python3
Checking for python version >= 2.7.0           : 3.10.6
Source is git repository                       : yes
Update submodules                              : yes
Checking for program 'git'                     : /usr/bin/git
Gtest                                          : STM32 boards currently don't support compiling gtest
Checking for program 'arm-none-eabi-size'      : /usr/bin/arm-none-eabi-size
Benchmarks                                     : disabled
Unit tests                                     : disabled
Scripting                                      : enabled
Scripting runtime checks                       : enabled
Debug build                                    : disabled
Coverage build                                 : disabled
Checking for program 'rsync'                   : /usr/bin/rsync
Waf: Entering directory `/mnt/c/Users/stan/ardupilot/build/Pixhawk1'
Checking for env.py
env added WITH_FATFS=1
env added PROCESS_STACK=0x1C00
env added MAIN_STACK=0x600
env added IOMCU_FW=0
env added PERIPH_FW=0
env added HAL_NUM_CAN_IFACES=2
env added BOARD_FLASH_SIZE=2048
env appended CPU_FLAGS=['-mcpu=cortex-m4', '-mfpu=fpv4-sp-d16', '-mfloat-abi=hard', '-DARM_MATH_CM4', '-u_printf_float']
env added CORTEX=cortex-m4
env added APJ_BOARD_ID=9
env added APJ_BOARD_TYPE=STM32F427xx
env added USBID=0x1209/0x5741
env added BOOTLOADER_EMBED=1
env added FLASH_RESERVE_START_KB=16
env added FLASH_TOTAL=2080768
env added CHIBIOS_BUILD_FLAGS=USE_FATFS=yes CHIBIOS_STARTUP_MK=os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk CHIBIOS_PLATFORM_MK=os/hal/ports/STM32/STM32F4xx/platform.mk MCU=cortex-m4 ENV_UDEFS=-DCHPRINTF_USE_FLOAT=1
Embedding file bootloader.bin:/mnt/c/Users/stan/ardupilot/Tools/bootloaders/Pixhawk1_bl.bin
Embedding file hwdef.dat:/mnt/c/Users/stan/ardupilot/build/Pixhawk1/hw.dat
Embedding file io_firmware.bin:Tools/IO_Firmware/iofirmware_lowpolh.bin
[ 6/10] Processing modules/mavlink/message_definitions/v1.0/ardupilotmega.xml
Waf: Leaving directory `/mnt/c/Users/stan/ardupilot/build/Pixhawk1'
Build failed
Traceback (most recent call last):
  File "/mnt/c/Users/stan/ardupilot/modules/waf/waflib/Task.py", line 348, in process
    ret = self.run()
  File "/mnt/c/Users/stan/ardupilot/Tools/ardupilotwaf/mavgen.py", line 55, in run
    from pymavlink.generator import mavgen
  File "/mnt/c/Users/stan/ardupilot/modules/mavlink/pymavlink/generator/mavgen.py", line 26, in <module>
    from future import standard_library
ModuleNotFoundError: No module named 'future'

I already try installing that module, using pip install future, pip3 install future, python3 -m pip install future, inside and outside the WSL (PowerShell and CMD), but no luck.
If I open a file and import it, it is recognize, in WSL and PowerShell, and I have even run a test code where I import that module, but have no luck with the build.

I see that in the Task class on “/ardupilot/Tools/ardupilotwaf/mavgen.py”, you set a PATH, an env PATH, thus i dont know if somewhere there is messing with the Python path.

PD: I re-run waf configure after pip installation future. I also use waf clean to clean configuration, and re-run configure, both methods without any luck.

I know this is a weird case, but thanks for the help.

waf is expected to be run with ./waf <args>, whereas you’re using sudo python3 waf args (which is likely in a different environment, that future is presumably not installed into). I’d suggest you try running normally :slight_smile: