-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Welcome to the NUS ROBOMASTERS PX4-Autopilot wiki!
For our development, Ubuntu is the best environment. It is highly encouraged that all members use Ubuntu as the following instructions were tested successfully on Ubuntu.
This setup is a long process so be patient and follow each command diligently.
-
Gperf installation
sudo apt-get install -y gperf -
Install qt5 and qt5 default
sudo apt-get install qt5-default -
From Nuttx apache homepage, follow the installation commands for Ubuntu:
sudo apt install \ bison flex gettext texinfo libncurses5-dev libncursesw5-dev \ gperf automake libtool pkg-config build-essential gperf genromfs \ libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \ libexpat-dev gcc-multilib g++-multilib picocom u-boot-tools util-linux
If the command doesn't work go to this link and copy the same command: link
`sudo apt install kconfig-frontends` - gives you the interactive frontend for configuration.
`sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi` - the toolchain to aid our development for ARM architecture.
Now make directory called _nuttx_ anywhere you feel it should be.
`cd`
`mkdir nuttx`
Move into that directory
`cd nuttx`
Now we are going to close two repositories into the current folder:
`git clone https://github.com/apache/incubator-nuttx.git nuttx`
`git clone https://github.com/apache/incubator-nuttx-apps apps`
`git clone https://bitbucket.org/nuttx/tools.git tools`
You should be able to see three folders inside nuttx : nuttx, apps and tools
Prepare the kconfig-frontends. Run the following commands in sequence:
`cd tools/kconfig-frontends`
`./configure --enable-mconf --disable-nconf --disable-gconf --enable-qconf --prefix=/usr`
`make`
`sudo make install`
`sudo ldconfig`
`cd ../..` -- you should now be in the nuttx folder.
We now have all the essentials for building the `.bin` file. This file will flash the operating system onto the board.
Move into the nuttx repository. (Yes there are two folders named nuttx).
`cd nuttx`
We are working on the stm32f4discovery board. So we will configure the command shell for that board.
`./tools/configure.sh -l stm32f4discovery:nsh`
Now make the _bin_ file.
`make`
The build will complete by generating the binary outputs inside nuttx directory. Typically this includes the nuttx ELF file (suitable for debugging using gdb) and a nuttx.bin file that can be flashed to the board.
To clean the build:
`make clean`
-
To flash the bin file, and future bin files, we'll be using a tool called openocd. To install it:
sudo apt install openocdMove out out the folders and repository before moving on to the next command.
cd ../... -- this will move you out of both the nuttx folders. The commandlsshould only show one nuttx folder -
Git clone official px4 github Preparing px4 environment from px4 website. This will take some time, so document every process along the way.
Downloading the PX4 source code:
git clone https://github.com/PX4/PX4-Autopilot.git --recursiveMove into the folder:
cd PX4-AutopilotThen run the following command. It will perform the installation for you.
bash ./Tools/setup/ubuntu.shNow you'll have to restart your computer.
We will now make a cross-compiler. This means that we are making code for a platform different from the one you're currently developing. We'll be using the GCC compiler. Follow the commands below for installation:
sudo apt-get install -y gcc-8-arm-linux-gnueabihf g++-8-arm-linux-gnueabihfsudo apt-get install -y gcc-8-aarch64-linux-gnu g++-8-aarch64-linux-gnusudo update-alternatives --install /usr/bin/aarch64-linux-gnu-gcc aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-gnu-gcc-8 100 --slave /usr/bin/aarch64-linux-gnu-g++ aarch64-linux-gnu-g++ /usr/bin/aarch64-linux-gnu-g++-8sudo update-alternatives --config aarch64-linux-gnu-gccIf the last command returns saying that no configuration is possible or something, it's fine.
sudo apt-get install clangThis will install the Robot Operating System and Gazebo simulation.
To install the development toolchain:
- Download the script in a bash shell:
wget https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim_ros_melodic.sh2. Run the script:bash ubuntu_sim_ros_melodic.shYou may need to acknowledge some prompts as the script progresses. Press Enter.
-
Now is the tricky part. If this step goes wrong the debugging of errors is very tedious.
You might already have the following packages but do install just to make sure.
sudo apt install cmake g++ python3-pip wget gitsudo apt install libasio-dev libtinyxml2-devsudo apt install libssl-devpip3 install -U colcon-common-extensions vcstoolCreate a Fast-DDS directory and download the repos file that will be used to install eProsima Fast DDS and its dependencies:
mkdir ~/Fast-DDS---- Don't worry about the file location, the '~' character takes care of itcd ~/Fast-DDSwget https://raw.githubusercontent.com/eProsima/Fast-DDS/master/fastrtps.reposmkdir srcvcs import src < fastrtps.reposcolcon buildecho 'source ~/Fast-DDS/install/setup.bash' >> ~/.bashrc---- this will run a colcon instance every time the terminal is open.This requires Java version 11 and gradle.
Installing Java:
sudo apt install default-jdkConfiguring it to version 11:
update-alternatives --config javaThis will bring up an interactive shell. Press the number that corresponds to version 11 and press Enter.
#Gradle Installation
Follow the following commands:
VERSION=6.5.1wget https://services.gradle.org/distributions/gradle-${VERSION}-bin.zip -P /tmpsudo unzip -d /opt/gradle /tmp/gradle-${VERSION}-bin.zipsudo ln -s /opt/gradle/gradle-${VERSION} /opt/gradle/latestWe will setup the environment variable. We will use a traditional text editor vim. You can use any text editor that you're familiar with too, just take note of the file locations.
sudo apt install vimsudo vim /etc/profile.d/gradle.sh----- This will take you inside the vim editor interface.This editor is very old and can only be operated by keyboard commands.
Press the key i on your keyboard to enter edit mode.
Now paste the following configuration:
export GRADLE_HOME=/opt/gradle/latestexport PATH=${GRADLE_HOME}/bin:${PATH}Press the Esc key to exit edit mode.
Now type
:wqand hitEnter. This will write and quit the file, meaning that it's saved.We give the script execute rights, so that it can be run.
sudo chmod +x /etc/profile.d/gradle.sh. ---- chmod modifies the permission of files and folders.Lastly source the file:
source /etc/profile.d/gradle.shTo verify:
gradle -v. ---- it should return the version your using.Remember that we are still in the Fast DDS-Gen installation.
Compile Fast DDS-Gen by following the steps below:
cd ~git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.gitcd Fast-DDS-Gengradle assemble./gradlew assemble -
Now we begin to work with our code. Make a directory, ideally 'robomasters' and clone the following directories and perform the following commands.
cd--- to move to the root directorymkdir robomasterscd robomastersgit clone --recursive https://github.com/nusrobomaster/PX4-Autopilot.gitcd PX4-Autopilotgit checkout rm2021. --- just hit Tab if you don't want to type the while thingThe above branch as the bin file.
Type
makeand double Tab to list the available boards. You should see something like robomaster-dev-a or something.make board-name--- replace board-name with the dev a board. This will make the bin file.(If you get an error saying that python is not detected, it’s most likely that it is not linked. So use the following command)
sudo ln -s /usr/bin/python3 /usr/bin/pythonMove out of the directory before moving onto the next step.cd ..Clone the boatloader repository.
git clone --recursive https://github.com/nusrobomaster/PX4-Bootloader.gitcd PX4-Bootloadermake-- this will make the bootloader. -
Lastly, we should be able to upload and flash the board now.
Move into the PX4-Autopilot directory from where you are.
cd ..cd PX4-AutopilotNow connect the board via USB. If it's the first time flashing put it into flashing mode by shorting the circuit. We will give you a demonstration. You should see an LED flashing.
Enter the following command.
make robomaster_dev-a uploadThis should do all the work for you. Now install
minicomwhich will let us communicate with shell on the board.sudo apt install minicomThe following command will open a new terminal with the shell running on it.
minicom -D /dev/ttyACM0USB console startup. When using a USB console, the start-up sequence differs a little: In this case, you are required to press ENTER three times. Then NSH prompt will appear as described above. This is required for the following reasons:
1. This assures that the USB connection is stable. The USB connection may be made, broken, and re-established a few times if the USB cable is not yet fully seated. Waiting for ENTER to be pressed three times assures that the connection is stable. 2. The establishment of the connection is two step process: First, the USB serial connection is made with the host PC. Then the application that uses the serial interface is started on the host. When the serial connection is established on the host, the host operating system may send several AT modem commands to the host depending upon how the host serial port is configured. By waiting for ENTER to be pressed three consecutive times, all of these modem commands will go to the bit-bucket and will not be interpreted as NSH command input. 3. Similarly, in the second step when the applications is started, there may be additional AT modem commands sent out the serial port. Most serial terminal programs will do this unless they are specifically configured to suppress the modem command output. Waiting for the ENTER input eliminates the invalid command errors from both (2) and (3). 4. Finally, if NSH did not wait for some positive indication that the serial terminal program is up and running, then the output of the NSH greeting and initial NSH prompt would be lost.(The above numbered list is quoted from Apache NuttX docs.)
You shell will not be aligned. To align the returns, `CTRL+A`, `Z` and `U`. Your shell should now be aligned. -
To see the available commands.
helpTo light-up one of the on-board LEDs,
gpio write G 2 0 --force
Now you're ready to begin programming.
Tip, for script writers, nsh doesn't use printf(). Use nsh_output(vtbl, "Hello, World!"); instead.