Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions install_ROS2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,14 @@ if [[ $branch == "develop" || $branch == "main" ]]; then

# Install mirte ros packages with apt from github, since they take ages to compile and it's easier to update them.
# colcon ignore those packages

if [[ $branch == "develop" ]]; then
arch="${arch}_develop"
fi
echo "Using precompiled version of packages"
echo "deb [trusted=yes] $github_url/raw/ros_mirte_${ROS_NAME}_${ubuntu_version}_${arch}/ ./" | sudo tee /etc/apt/sources.list.d/mirte-ros-packages.list
echo "yaml $github_url/raw/ros_mirte_${ROS_NAME}_${ubuntu_version}_${arch}/local.yaml ${ROS_NAME}" | sudo tee /etc/ros/rosdep/sources.list.d/mirte-ros-packages.list
sudo apt update

cd /home/mirte/mirte_ws/src/ || exit 1
ignore=(mirte_telemetrix_cpp mirte_msgs mirte_teleop astra_camera astra_camera_msgs libuvc mirte_base_control mirte_master_arm_control mirte_control usb_cam)
packages=''
Expand All @@ -106,14 +112,16 @@ if [[ $branch == "develop" || $branch == "main" ]]; then
fi
touch $path/COLCON_IGNORE
i_dash=$(echo $i | tr '_' '-')
packages="$packages ros-$ROS_NAME-$i_dash"
pkg_name="ros-$ROS_NAME-$i_dash"
# check if dbgsym package exists
sudo apt-cache madison "$pkg_name-dbgsym"

if sudo apt-cache madison "$pkg_name-dbgsym" | grep -vqz "Unable to locate package"; then
echo "Adding debug package $pkg_name-dbgsym"
packages="$packages $pkg_name-dbgsym"
fi
packages="$packages $pkg_name"
done
if [[ $branch == "develop" ]]; then
arch="${arch}_develop"
fi
echo "deb [trusted=yes] $github_url/raw/ros_mirte_${ROS_NAME}_${ubuntu_version}_${arch}/ ./" | sudo tee /etc/apt/sources.list.d/mirte-ros-packages.list
echo "yaml $github_url/raw/ros_mirte_${ROS_NAME}_${ubuntu_version}_${arch}/local.yaml ${ROS_NAME}" | sudo tee /etc/ros/rosdep/sources.list.d/mirte-ros-packages.list
sudo apt update
sudo apt install -y -m $packages || fallback=false # TODO: disabled fallback for now as mirte-arm doesn't compile.
fi

Expand Down Expand Up @@ -167,8 +175,6 @@ sudo adduser mirte dialout
# Some nice extra packages: clean can clean workspaces and packages. No need to do it by hand. lint can check for errors in the cmake/package code.
sudo pip3 install colcon-clean colcon-lint

# Add colcon top level workspace, this makes it possible to run colcon build from any folder, it will find the workspace and build it. Otherwise it will create a new workspace in the subdirectory.

if [[ $MIRTE_TYPE == "mirte-master" ]]; then
# TODO: need to check and edit the next part:
sudo apt install ros-$ROS_NAME-slam-toolbox -y
Expand Down Expand Up @@ -207,12 +213,9 @@ if [[ $MIRTE_TYPE == "mirte-master" ]]; then

fi

cd /tmp
git clone https://github.com/rhaschke/colcon-top-level-workspace
cd colcon-top-level-workspace
pip install .
cd ..
rm -rf colcon-top-level-workspace
# Add colcon top level workspace, this makes it possible to run colcon build from any folder, it will find the workspace and build it. Otherwise it will create a new workspace in the subdirectory.
pip install git+https://github.com/arendjan/colcon-top-level-workspace.git

# zsh does not work nicely with ros2 autocomplete, so we need to add a function to fix it.
# ROS 2 Foxy should have this fixed, but we are using ROS 2 Humble.
# TODO: check for ROS2 jazzy
Expand Down
2 changes: 1 addition & 1 deletion install_arduino.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export PICO_SDK_PATH=$MIRTE_SRC_DIR/pico/pico-sdk
add_rc "export PICO_SDK_PATH=$MIRTE_SRC_DIR/pico/pico-sdk"
git clone https://github.com/raspberrypi/picotool.git --depth=1 # shallow clone to save space
cd picotool || exit 1
sudo cp udev/99-picotool.rules /etc/udev/rules.d/
sudo cp udev/*.rules /etc/udev/rules.d/

mkdir build
cd build || exit 1
Expand Down
5 changes: 3 additions & 2 deletions network_setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash
MIRTE_SRC_DIR=/usr/local/src/mirte

($MIRTE_SRC_DIR/mirte-install-scripts/services/mirte_auto_dhcp_eth.sh || true) &

# wait for wlan0 to be up, with max 30 seconds
TIMEOUT=30
Expand Down Expand Up @@ -131,8 +134,6 @@ function file_empty() {

}

MIRTE_SRC_DIR=/usr/local/src/mirte

sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf || true

# Create unique SSID
Expand Down
70 changes: 70 additions & 0 deletions services/mirte_auto_dhcp_eth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

# nm dispatcher is whack and not running reliably or without the interface name.

# this script repeatedly checks eth0, when it goes up, wait for a few seconds
# if no ip assigned: start dnsmasq
# if ip assigned:don't do anything
# when eth0 goes down, kill dnsmasq if started

set -xe

# start dnsmasq
SUBNET=45
interface=eth0

dnsmasq_pid=$(pgrep -f "dnsmasq --address=/#/192.168.$SUBNET.1") || true

function cleanup {
has_dhcp=false
echo "Cleaning up..."
if [ -n "$dnsmasq_pid" ]; then
echo "Stopping dnsmasq with PID $dnsmasq_pid"
sudo kill "$dnsmasq_pid" || true
dnsmasq_pid=""
else
echo "No dnsmasq process found."
fi
sudo ip address del 192.168."$SUBNET".1/24 dev eth0 || true
# exit 0
echo "Cleanup complete."
# exit 0
}

function start_dhcp {
cleanup
has_dhcp=true
sudo ip address add 192.168."$SUBNET".1/24 dev eth0
sudo dnsmasq --address=/#/192.168."$SUBNET".1 --dhcp-range=192.168."$SUBNET".10,192.168."$SUBNET".100 --conf-file --domain-needed --bogus-priv --server=8.8.8.8 --dhcp-option=option:dns-server,8.8.8.8 --interface="$interface" --except-interface=lo --bind-interfaces -p0 --dhcp-leasefile=/tmp/dnsmasq.leases
dnsmasq_pid=$(pgrep -f "dnsmasq --address=/#/192.168.$SUBNET.1")
}

function check_up {
is_up=$(ip addr show $interface | grep -q "state UP" && echo true || echo false)
has_ip=$(ip addr show $interface | grep -q "inet " && echo true || echo false)
if [ "$is_up" = false ]; then
SECONDS=0
elif [ $SECONDS -gt 10 ] && [ "$has_ip" = false ]; then
echo "Interface $interface has been up for more than 10 seconds."
echo "No IP address assigned, starting DHCP server."
start_dhcp
fi
}

function check_down {
is_up=$(ip addr show $interface | grep -q "state UP" && echo true || echo false)
if [ "$is_up" = false ] && [ "$has_dhcp" = true ]; then
echo "Interface $interface is down, stopping DHCP server."
cleanup
fi
}

trap cleanup EXIT

is_up=false
has_dhcp=false
while true; do
check_up
check_down
sleep 5
done