Skip to content

Commit c39f84d

Browse files
committed
successfully implemented github actions for SITL checks, it runs locallygit statusgit status!
1 parent 4b20b4b commit c39f84d

11 files changed

Lines changed: 337 additions & 49 deletions

File tree

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: SITL Docker Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
sitl-test:
9+
runs-on: ubuntu-latest
10+
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Pull SITL image
17+
run: |
18+
echo "${{ secrets.CR_PAT}}" | \
19+
docker login ghcr.io -u ${{ github.actor }} --password-stdin
20+
docker pull ghcr.io/${{ github.repository_owner }}/sitl:latest
21+
22+
- name: Run tests
23+
run: |
24+
docker run --rm \
25+
-v $PWD:/workspace \
26+
ghcr.io/uaarg/sitl:latest \
27+
bash /workspace/scripts/dockertest.sh

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,41 @@
1-
# mavctl-python
1+
![act-logo](https://raw.githubusercontent.com/wiki/nektos/act/img/logo-150.png)
22

3-
An Open Source Library for Autonomous Drone Navigation.
3+
# Overview [![push](https://github.com/nektos/act/workflows/push/badge.svg?branch=master&event=push)](https://github.com/nektos/act/actions) [![Go Report Card](https://goreportcard.com/badge/github.com/nektos/act)](https://goreportcard.com/report/github.com/nektos/act) [![awesome-runners](https://img.shields.io/badge/listed%20on-awesome--runners-blue.svg)](https://github.com/jonico/awesome-runners)
44

5-
## Things to be Familiar With
5+
> "Think globally, `act` locally"
66
7-
Before diving into mavctl, it is recommended that you read up on or familiarize yourself with the following so that you have an easier time working on mavctl
7+
Run your [GitHub Actions](https://developer.github.com/actions/) locally! Why would you want to do this? Two reasons:
88

9-
1. MAVLink (https://mavlink.io/)
10-
Take a look through introduction just to get an idea of how the MAVLink protocol works
9+
- **Fast Feedback** - Rather than having to commit/push every time you want to test out the changes you are making to your `.github/workflows/` files (or for any changes to embedded GitHub actions), you can use `act` to run the actions locally. The [environment variables](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables) and [filesystem](https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners) are all configured to match what GitHub provides.
10+
- **Local Task Runner** - I love [make](<https://en.wikipedia.org/wiki/Make_(software)>). However, I also hate repeating myself. With `act`, you can use the GitHub Actions defined in your `.github/workflows/` to replace your `Makefile`!
1111

12-
2. Shepard (https://github.com/uaarg/shepard)
13-
Take a look through here (https://github.com/uaarg/shepard/blob/main/src/modules/autopilot/navigator.py) to get an idea of what the navigation functions should sort of look like
14-
Another thing to take a look at is the flight tests scripts as well (https://github.com/uaarg/shepard/blob/main/src/modules/autopilot/navigator.py)
12+
> [!TIP]
13+
> **Now Manage and Run Act Directly From VS Code!**<br/>
14+
> Check out the [GitHub Local Actions](https://sanjulaganepola.github.io/github-local-actions-docs/) Visual Studio Code extension which allows you to leverage the power of `act` to run and test workflows locally without leaving your editor.
1515
16-
3. DroneKit (OPTIONAL) (https://github.com/dronekit/dronekit-python)
17-
While this is optional, a lot of things from DroneKit are borrowed, specifically the things that DroneKit does well.
18-
Overall, mavctl-python is similar to dronekit but it is revamped and is meant to replace DroneKit for all of its functionality.
19-
Over time we will reach a point where we will have exceeded dronekit but that time has not been reached just yet.
16+
# How Does It Work?
2017

21-
## Contribution Guidelines
18+
When you run `act` it reads in your GitHub Actions from `.github/workflows/` and determines the set of actions that need to be run. It uses the Docker API to either pull or build the necessary images, as defined in your workflow files and finally determines the execution path based on the dependencies that were defined. Once it has the execution path, it then uses the Docker API to run containers for each action based on the images prepared earlier. The [environment variables](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables) and [filesystem](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#file-systems) are all configured to match what GitHub provides.
2219

23-
Push all of your changes to a seperate branch and make a pull request if you would like to merge to main
20+
Let's see it in action with a [sample repo](https://github.com/cplee/github-actions-demo)!
2421

25-
IMPORTANT: FOLLOW THE STRUCTURE.
26-
It is very important for you to follow the structure that `mavctl-python` follows in terms of its operation.
22+
![Demo](https://raw.githubusercontent.com/wiki/nektos/act/quickstart/act-quickstart-2.gif)
2723

28-
`mavctl-python` works as follows:
24+
# Act User Guide
2925

30-
`MAVLink` connection is created and a `PyMAVLink` object is passed to the `Navigator` class.
31-
In the `Navigator` class, there are methods which conduct the drone navigation (ex. move the drone 1m North)
26+
Please look at the [act user guide](https://nektosact.com) for more documentation.
3227

33-
More advanced maneuvers should be located in their own files, but should NOT be in their own respective class.
34-
Instead, you can pass the `Navigator` class object into these advanced maneuver functions.
28+
# Support
3529

36-
The structure of that would look as follows:
30+
Need help? Ask in [discussions](https://github.com/nektos/act/discussions)!
3731

38-
```
39-
import advanced
32+
# Contributing
4033

41-
master = connect()
42-
nav = Navigator()
43-
44-
advanced_maneuver = advancedManeuver(nav)
45-
```
46-
47-
`advanced` would be a file named `advanced.py` and `advancedManeuver()` would be the advanced maneuver method in question.
34+
Want to contribute to act? Awesome! Check out the [contributing guidelines](CONTRIBUTING.md) to get involved.
4835

36+
## Manually building from source
4937

38+
- Install Go tools 1.20+ - (<https://golang.org/doc/install>)
39+
- Clone this repo `git clone git@github.com:nektos/act.git`
40+
- Run unit tests with `make test`
41+
- Build and install: `make install`

docker/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM ubuntu:24.04
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt update && apt install -y python3 python3-pip netcat-traditional
6+
RUN apt install -y git
7+
8+
9+
WORKDIR /work
10+
RUN git clone --recurse-submodules https://github.com/ArduPilot/ardupilot.git
11+
WORKDIR /work/ardupilot
12+
13+
COPY patches /work/patches
14+
RUN git apply /work/patches/01-SITL-ubuntu-deps.patch
15+
RUN git apply /work/patches/02-SITL-no-usermod.patch
16+
17+
RUN Tools/environment_install/install-prereqs-ubuntu.sh -y
18+
RUN echo '. ~/venv-ardupilot/bin/activate' >> /root/.profile
19+
20+
RUN . ~/venv-ardupilot/bin/activate && \
21+
./waf configure --board sitl && \
22+
./waf copter
23+
24+
CMD . /root/venv-ardupilot/bin/activate
25+
# Tools/autotest/sim_vehicle.py -v Copter --no-mavproxy -w -S 10 --udp

docker/Dockerfile.sitl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM ubuntu:22.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
# Install dependencies
6+
RUN apt update && apt install -y \
7+
git \
8+
python3 \
9+
python3-pip \
10+
python3-dev \
11+
build-essential \
12+
ccache \
13+
g++ \
14+
make \
15+
wget \
16+
netcat \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
# Clone ArduPilot
20+
WORKDIR /opt
21+
RUN git clone https://github.com/ArduPilot/ardupilot.git
22+
WORKDIR /opt/ardupilot
23+
24+
RUN git submodule update --init --recursive
25+
26+
# Install ArduPilot prerequisites
27+
RUN Tools/environment_install/install-prereqs-ubuntu.sh -y
28+
29+
# Configure + build SITL
30+
RUN ./waf configure --board sitl
31+
RUN ./waf copter
32+
33+
# Install pytest + mav tools
34+
RUN pip3 install pytest pymavlink mavctl
35+
36+
WORKDIR /workspace

mavctl/connect/conn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Connect:
1313
"""Handles MAVLink connections and heartbeat monitors"""
1414

1515
def __init__(self,
16-
ip: str = "udp:127.0.0.1:14552",
16+
ip: str = "udp:127.0.0.1:14551",
1717
baud: int = 57600,
1818
heartbeat_timeout: Optional[int] = None):
1919

@@ -31,7 +31,7 @@ def __init__(self,
3131

3232
self.ip = ip
3333

34-
def connect(self, ip: str = "udp:127.0.0.1:14552",
34+
def connect(self, ip: str = "udp:127.0.0.1:14551",
3535
baud: int = 57600,
3636
heartbeat_timeout: Optional[int] = None) -> mavutil.mavlink_connection:
3737
"""
@@ -49,7 +49,7 @@ def connect(self, ip: str = "udp:127.0.0.1:14552",
4949
ConnError: If heartbeat or the connection fails
5050
"""
5151
try:
52-
master = mavutil.mavlink_connection(ip, baud)
52+
master = mavutil.mavlink_connection(device=ip, baud=baud)
5353
msg_recv = master.recv_match(type="HEARTBEAT", blocking=False)
5454
while not msg_recv:
5555
i = 0

patches/01-SITL-ubuntu-deps.patch

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
diff --git a/Tools/environment_install/install-prereqs-ubuntu.sh b/Tools/environment_install/install-prereqs-ubuntu.sh
2+
index 2dfcd34ec4..cccae745d2 100755
3+
--- a/Tools/environment_install/install-prereqs-ubuntu.sh
4+
+++ b/Tools/environment_install/install-prereqs-ubuntu.sh
5+
@@ -3,11 +3,6 @@ echo "---------- $0 start ----------"
6+
set -e
7+
set -x
8+
9+
-if [ $EUID == 0 ]; then
10+
- echo "Please do not run this script as root; don't sudo it!"
11+
- exit 1
12+
-fi
13+
-
14+
OPT="/opt"
15+
# Ardupilot Tools
16+
ARDUPILOT_TOOLS="Tools/autotest"
17+
@@ -29,7 +24,7 @@ while getopts "yq" opt; do
18+
esac
19+
done
20+
21+
-APT_GET="sudo apt-get"
22+
+APT_GET="apt-get"
23+
if $ASSUME_YES; then
24+
APT_GET="$APT_GET --assume-yes"
25+
fi
26+
@@ -173,7 +168,7 @@ if [ "$ARM_PKG_CONFIG_NOT_PRESENT" -eq 1 ]; then
27+
$APT_GET install pkg-config
28+
if [ -f /usr/share/pkg-config-crosswrapper ]; then
29+
# We are on non-Ubuntu so simulate effect of installing pkg-config-arm-linux-gnueabihf.
30+
- sudo ln -sf /usr/share/pkg-config-crosswrapper /usr/bin/arm-linux-gnueabihf-pkg-config
31+
+ ln -sf /usr/share/pkg-config-crosswrapper /usr/bin/arm-linux-gnueabihf-pkg-config
32+
else
33+
echo "Warning: unable to link to pkg-config-crosswrapper"
34+
fi
35+
@@ -241,17 +236,17 @@ function install_arm_none_eabi_toolchain() {
36+
heading "Installing toolchain for STM32 Boards"
37+
echo "Installing toolchain for STM32 Boards"
38+
echo "Downloading from ArduPilot server"
39+
- sudo wget --progress=dot:giga https://firmware.ardupilot.org/Tools/STM32-tools/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
40+
+ wget --progress=dot:giga https://firmware.ardupilot.org/Tools/STM32-tools/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
41+
echo "Installing..."
42+
- sudo chmod -R 777 gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
43+
- sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
44+
+ chmod -R 777 gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
45+
+ tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
46+
echo "... Cleaning"
47+
- sudo rm gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
48+
+ rm gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
49+
)
50+
fi
51+
echo "Registering STM32 Toolchain for ccache"
52+
- sudo ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-g++
53+
- sudo ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-gcc
54+
+ ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-g++
55+
+ ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-gcc
56+
echo "Done!";;
57+
58+
aarch64)
59+
@@ -261,17 +256,17 @@ function install_arm_none_eabi_toolchain() {
60+
heading "Installing toolchain for STM32 Boards"
61+
echo "Installing toolchain for STM32 Boards"
62+
echo "Downloading from ArduPilot server"
63+
- sudo wget --progress=dot:giga https://firmware.ardupilot.org/Tools/STM32-tools/gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
64+
+ wget --progress=dot:giga https://firmware.ardupilot.org/Tools/STM32-tools/gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
65+
echo "Installing..."
66+
- sudo chmod -R 777 gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
67+
- sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
68+
+ chmod -R 777 gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
69+
+ tar xjf gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
70+
echo "... Cleaning"
71+
- sudo rm gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
72+
+ rm gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
73+
)
74+
fi
75+
echo "Registering STM32 Toolchain for ccache"
76+
- sudo ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-g++
77+
- sudo ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-gcc
78+
+ ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-g++
79+
+ ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-gcc
80+
echo "Done!";;
81+
esac
82+
}
83+
@@ -290,7 +285,7 @@ function maybe_prompt_user() {
84+
}
85+
86+
heading "Add user to dialout group to allow managing serial ports"
87+
-sudo usermod -a -G dialout $USER
88+
+usermod -a -G dialout $USER
89+
echo "Done!"
90+
91+
# Add back python symlink to python interpreter on Ubuntu >= 20.04

patches/02-SITL-no-usermod.patch

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/Tools/environment_install/install-prereqs-ubuntu.sh b/Tools/environment_install/install-prereqs-ubuntu.sh
2+
index cccae745d2..beb03e4694 100755
3+
--- a/Tools/environment_install/install-prereqs-ubuntu.sh
4+
+++ b/Tools/environment_install/install-prereqs-ubuntu.sh
5+
@@ -284,10 +284,6 @@ function maybe_prompt_user() {
6+
fi
7+
}
8+
9+
-heading "Add user to dialout group to allow managing serial ports"
10+
-usermod -a -G dialout $USER
11+
-echo "Done!"
12+
-
13+
# Add back python symlink to python interpreter on Ubuntu >= 20.04
14+
if [ ${RELEASE_CODENAME} == 'focal' ];
15+
then

scripts/dockertest.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
source /root/venv-ardupilot/bin/activate
5+
pip install --upgrade pip
6+
pip install pytest pymavlink pexpect
7+
8+
# Start SITL if not running
9+
if ! pgrep -f ArduCopter > /dev/null; then
10+
echo "Starting SITL..."
11+
Tools/autotest/sim_vehicle.py -v ArduCopter \
12+
--no-mavproxy \
13+
--no-rebuild \
14+
--speedup 1 \
15+
--udp \
16+
--out=udp:127.0.0.1:14550 \
17+
--instance 0 &
18+
SITL_PID=$!
19+
else
20+
echo "SITL already running"
21+
fi
22+
23+
mavproxy.py \
24+
--master=udp:127.0.0.1:5760 \
25+
--out=udp:127.0.0.1:14551 \
26+
--daemon &
27+
MAVPROXY_PID=$!
28+
29+
# Ensure SITL is ready
30+
echo "Waiting for SITL process..."
31+
until pgrep -f ArduCopter > /dev/null; do
32+
sleep 1
33+
done
34+
echo "SITL process detected"
35+
36+
echo "SITL ready"
37+
38+
sleep 10
39+
40+
cd /workspace
41+
# Run tests
42+
echo "Running python script"
43+
44+
#echo "Running pytest..."
45+
PYTHONPATH=. pytest
46+
47+
# Kill SITL if started here
48+
if [ ! -z "$SITL_PID" ]; then
49+
echo "Stopping SITL..."
50+
kill $SITL_PID
51+
wait $SITL_PID || true
52+
fi
53+
54+
# Kill Mavproxy if started here
55+
if [ ! -z "$MAVPROXY_PID" ]; then
56+
echo "Stopping MAVROXY"
57+
kill $MAVPROXY_PID
58+
wait $MAVPROXY_PID || true
59+
fi

test.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)