From 86accdb783b601d53db7478f448f4be1961bb249 Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Wed, 6 Mar 2024 20:06:42 +0000 Subject: [PATCH 01/17] Add Dockerfile --- docker/Dockerfile | 138 +++++++++++++++++++++++++++++++++ docker/build_docker_image.bash | 3 + docker/entry.sh | 8 ++ 3 files changed, 149 insertions(+) create mode 100644 docker/Dockerfile create mode 100755 docker/build_docker_image.bash create mode 100755 docker/entry.sh diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..5da3d29 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,138 @@ +FROM ubuntu:focal +SHELL ["/bin/bash", "-c"] + +# Settings +ENV ARCH=amd64 +ENV DEBIAN_FRONTEND=noninteractive +ARG ROS_DISTRO=noetic + +# Permissions +RUN apt-get update && apt-get install -y sudo +ARG USER=docker +ARG PASS=docker +ARG UID=1000 +ARG GID=1000 +ARG SSH_PRIV_KEY +RUN useradd -m ${USER} --uid=${UID} && echo "${USER}:${PASS}" | chpasswd +RUN adduser ${USER} sudo +ENV HOME /home/$USER + +# Install deps +RUN apt-get install -qy \ + git \ + tree \ + htop \ + tmux \ + exuberant-ctags \ + automake \ + cmake \ + ccache \ + gcc \ + clang \ + clang-format \ + clang-tidy \ + protobuf-compiler \ + libpython3-dev \ + pylint \ + yapf3 + +# Install ROS +RUN apt-get install -y lsb-release +RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' +RUN apt-get install curl gnupg -qy +RUN curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add - +RUN apt-get update +RUN apt-get install ros-${ROS_DISTRO}-desktop -qy + +# Install Gazebo-Fortress +RUN apt-get install wget -qy +RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg +RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null +RUN apt-get update +RUN apt-get install ignition-fortress -qy + +# Install MAVROS +RUN apt-get install ros-${ROS_DISTRO}-mavros ros-${ROS_DISTRO}-mavros-extras -qy + +# Install additional tools and libraries +RUN apt-get install -qy \ + python3-pip \ + python3-numpy \ + python3-scipy \ + python3-pandas \ + python3-seaborn \ + python3-matplotlib \ + python3-setuptools \ + python3-catkin-tools \ + libeigen3-dev \ + libopencv-dev + +# Switch to user +USER ${USER} + +# Setup catkin workspace +WORKDIR $HOME +RUN mkdir -p $HOME/catkin_ws/src +RUN cd $HOME/catkin_ws \ + && source /opt/ros/${ROS_DISTRO}/setup.bash \ + && catkin init \ + && catkin build + +# Download srl-mav-sim +RUN mkdir $HOME/.ssh/ +RUN echo "$SSH_PRIV_KEY" > $HOME/.ssh/id_rsa +RUN chmod 600 $HOME/.ssh/id_rsa +RUN touch $HOME/.ssh/known_hosts +RUN ssh-keyscan github.com >> $HOME/.ssh/known_hosts +RUN ssh-keyscan bitbucket.org >> $HOME/.ssh/known_hosts +WORKDIR $HOME/catkin_ws/src +RUN git clone --recurse-submodules git@github.com:smartroboticslab/srl-mav-sim.git +RUN rm -rf $HOME/.ssh/id_rsa + +# Install PX4 deps +WORKDIR $HOME/catkin_ws/src +RUN pip3 install kconfiglib +USER root +RUN ./srl-mav-sim/PX4-Autopilot/Tools/setup/ubuntu.sh --no-nuttx --no-sim-tools +USER ${USER} + +# Install GeographicLib datasets +WORKDIR $HOME/catkin_ws +USER root +RUN wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh +RUN chmod +x install_geographiclib_datasets.sh +RUN sudo bash ./install_geographiclib_datasets.sh +RUN rm install_geographiclib_datasets.sh +USER ${USER} + +# Build catkin workspace +WORKDIR $HOME/catkin_ws +USER root +RUN apt-get install \ + libgflags-dev \ + ros-${ROS_DISTRO}-gazebo-msgs \ + libignition-gazebo3-* \ + libignition-transport8-* \ + -qy +USER ${USER} +RUN env IGNITION_VERSION=fortress catkin build -DCMAKE_BUILD_TYPE=Release + +# Tools +USER root +RUN curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux64.tar.gz \ + && sudo rm -rf /opt/nvim \ + && sudo tar -C /opt -xzf nvim-linux64.tar.gz \ + && echo 'export PATH=$PATH:/opt/nvim-linux64/bin' > $HOME/.bashrc +RUN apt-get install -qy vim vifm +RUN echo "set -g default-command /bin/bash" >> $HOME/.tmux.conf +RUN echo "set -g mouse on" >> $HOME/.tmux.conf +RUN echo "bind-key h select-pane -L" >> $HOME/.tmux.conf +RUN echo "bind-key j select-pane -D" >> $HOME/.tmux.conf +RUN echo "bind-key k select-pane -U" >> $HOME/.tmux.conf +RUN echo "bind-key l select-pane -R" >> $HOME/.tmux.conf +USER ${USER} + +# Entry point script +WORKDIR $HOME +COPY entry.sh / +ENTRYPOINT ["/entry.sh"] diff --git a/docker/build_docker_image.bash b/docker/build_docker_image.bash new file mode 100755 index 0000000..d27f33f --- /dev/null +++ b/docker/build_docker_image.bash @@ -0,0 +1,3 @@ +#!/bin/bash +set -e +docker build -t mav_exp --build-arg SSH_PRIV_KEY="$(cat ~/.ssh/id_rsa)" . diff --git a/docker/entry.sh b/docker/entry.sh new file mode 100755 index 0000000..2046e5c --- /dev/null +++ b/docker/entry.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e +source /opt/ros/noetic/setup.bash +source $HOME/catkin_ws/devel/setup.bash +export IGNITION_VERSION=fortress + +# Start an interactive shell +/bin/bash From ef7a224e1f1ac80f9962523150d5593008e155c5 Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Wed, 6 Mar 2024 20:06:43 +0000 Subject: [PATCH 02/17] Add makefile --- Makefile | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0ddee41 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +DATA_DIR=/data +SSH_PRIV_KEY=`cat ~/.ssh/id_rsa` + +help: ## Help + @echo -e "\033[1;34m[make targets]:\033[0m" + @egrep -h '\s##\s' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*?## "}; \ + {printf "\033[1;36m%-20s\033[0m %s\n", $$1, $$2}' + +install_docker: ## Install Docker (Ubuntu only) + @bash scripts/install_docker.bash + +build_docker: ## Build srl_mav_sim docker + cd docker && ./build_docker_image.bash + +run_docker: ## Run srl_mav_sim docker + @xhost +local:docker && docker run \ + -e DISPLAY \ + -v $(DATA_DIR):$(DATA_DIR) \ + -v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule='c 189:* rmw' \ + -v /dev/shm:/dev/shm \ + -v /dev/dri:/dev/dri \ + --privileged \ + --ipc=host \ + --pid=host \ + --network="host" \ + -it --rm srl_mav_sim /bin/bash From 25214dc9b25c04d80b08985d84a802ea0cf33793 Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Wed, 6 Mar 2024 20:08:55 +0000 Subject: [PATCH 03/17] Update dockerfile --- docker/Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index 5da3d29..5a838fc 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -119,11 +119,16 @@ RUN env IGNITION_VERSION=fortress catkin build -DCMAKE_BUILD_TYPE=Release # Tools USER root +WORKDIR $HOME +# -- Install Neovim RUN curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux64.tar.gz \ && sudo rm -rf /opt/nvim \ && sudo tar -C /opt -xzf nvim-linux64.tar.gz \ + && rm nvim-linux64.tar.gz \ && echo 'export PATH=$PATH:/opt/nvim-linux64/bin' > $HOME/.bashrc +# -- Install vim and vifm RUN apt-get install -qy vim vifm +# -- Add sane tmux configs RUN echo "set -g default-command /bin/bash" >> $HOME/.tmux.conf RUN echo "set -g mouse on" >> $HOME/.tmux.conf RUN echo "bind-key h select-pane -L" >> $HOME/.tmux.conf From 8af55cd0aa6f93520a7deacfa0f16b63fecfa883 Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Wed, 6 Mar 2024 20:14:05 +0000 Subject: [PATCH 04/17] Add script to install docker --- scripts/install_docker.bash | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 scripts/install_docker.bash diff --git a/scripts/install_docker.bash b/scripts/install_docker.bash new file mode 100755 index 0000000..0708c99 --- /dev/null +++ b/scripts/install_docker.bash @@ -0,0 +1,28 @@ +#!/bin/bash +set -e + +# Install deps +sudo apt-get update -y -qq +sudo apt-get install -y -qq \ + ca-certificates \ + curl \ + gnupg \ + lsb-release + +# Install GPG key and docker sources +sudo mkdir -p /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg +echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + +# Install Docker +sudo apt-get update -y -qq +sudo apt-get install -q -yy \ + docker-ce \ + docker-ce-cli \ + containerd.io \ + docker-compose-plugin + +# Create and add user to docker group +groupadd -f docker +sudo usermod -aG docker ${USER} +echo "You now need to log out and log back in so that your group membership is re-evaluated" From 2fe351d7d33df05c7b6fa9479bdda83397098004 Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Wed, 6 Mar 2024 20:15:06 +0000 Subject: [PATCH 05/17] Add offboard example --- offboard_py/CMakeLists.txt | 204 +++++++++++++++++++++++++++ offboard_py/launch/start_offb.launch | 10 ++ offboard_py/package.xml | 62 ++++++++ offboard_py/scripts/offb_node.py | 74 ++++++++++ 4 files changed, 350 insertions(+) create mode 100644 offboard_py/CMakeLists.txt create mode 100644 offboard_py/launch/start_offb.launch create mode 100644 offboard_py/package.xml create mode 100755 offboard_py/scripts/offb_node.py diff --git a/offboard_py/CMakeLists.txt b/offboard_py/CMakeLists.txt new file mode 100644 index 0000000..295cafa --- /dev/null +++ b/offboard_py/CMakeLists.txt @@ -0,0 +1,204 @@ +cmake_minimum_required(VERSION 3.0.2) +project(offboard_py) + +## Compile as C++11, supported in ROS Kinetic and newer +# add_compile_options(-std=c++11) + +## Find catkin macros and libraries +## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) +## is used, also find other catkin packages +find_package(catkin REQUIRED COMPONENTS + rospy +) + +## System dependencies are found with CMake's conventions +# find_package(Boost REQUIRED COMPONENTS system) + + +## Uncomment this if the package has a setup.py. This macro ensures +## modules and global scripts declared therein get installed +## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html +# catkin_python_setup() + +################################################ +## Declare ROS messages, services and actions ## +################################################ + +## To declare and build messages, services or actions from within this +## package, follow these steps: +## * Let MSG_DEP_SET be the set of packages whose message types you use in +## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). +## * In the file package.xml: +## * add a build_depend tag for "message_generation" +## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependency has been pulled in +## but can be declared for certainty nonetheless: +## * add a exec_depend tag for "message_runtime" +## * In this file (CMakeLists.txt): +## * add "message_generation" and every package in MSG_DEP_SET to +## find_package(catkin REQUIRED COMPONENTS ...) +## * add "message_runtime" and every package in MSG_DEP_SET to +## catkin_package(CATKIN_DEPENDS ...) +## * uncomment the add_*_files sections below as needed +## and list every .msg/.srv/.action file to be processed +## * uncomment the generate_messages entry below +## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) + +## Generate messages in the 'msg' folder +# add_message_files( +# FILES +# Message1.msg +# Message2.msg +# ) + +## Generate services in the 'srv' folder +# add_service_files( +# FILES +# Service1.srv +# Service2.srv +# ) + +## Generate actions in the 'action' folder +# add_action_files( +# FILES +# Action1.action +# Action2.action +# ) + +## Generate added messages and services with any dependencies listed here +# generate_messages( +# DEPENDENCIES +# std_msgs # Or other packages containing msgs +# ) + +################################################ +## Declare ROS dynamic reconfigure parameters ## +################################################ + +## To declare and build dynamic reconfigure parameters within this +## package, follow these steps: +## * In the file package.xml: +## * add a build_depend and a exec_depend tag for "dynamic_reconfigure" +## * In this file (CMakeLists.txt): +## * add "dynamic_reconfigure" to +## find_package(catkin REQUIRED COMPONENTS ...) +## * uncomment the "generate_dynamic_reconfigure_options" section below +## and list every .cfg file to be processed + +## Generate dynamic reconfigure parameters in the 'cfg' folder +# generate_dynamic_reconfigure_options( +# cfg/DynReconf1.cfg +# cfg/DynReconf2.cfg +# ) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +## INCLUDE_DIRS: uncomment this if your package contains header files +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +catkin_package( +# INCLUDE_DIRS include +# LIBRARIES offboard_py +# CATKIN_DEPENDS rospy +# DEPENDS system_lib +) + +########### +## Build ## +########### + +## Specify additional locations of header files +## Your package locations should be listed before other locations +include_directories( +# include + ${catkin_INCLUDE_DIRS} +) + +## Declare a C++ library +# add_library(${PROJECT_NAME} +# src/${PROJECT_NAME}/offboard_py.cpp +# ) + +## Add cmake target dependencies of the library +## as an example, code may need to be generated before libraries +## either from message generation or dynamic reconfigure +# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Declare a C++ executable +## With catkin_make all packages are built within a single CMake context +## The recommended prefix ensures that target names across packages don't collide +# add_executable(${PROJECT_NAME}_node src/offboard_py_node.cpp) + +## Rename C++ executable without prefix +## The above recommended prefix causes long target names, the following renames the +## target back to the shorter version for ease of user use +## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node" +# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "") + +## Add cmake target dependencies of the executable +## same as for the library above +# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Specify libraries to link a library or executable target against +# target_link_libraries(${PROJECT_NAME}_node +# ${catkin_LIBRARIES} +# ) + +############# +## Install ## +############# + +# all install targets should use catkin DESTINATION variables +# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html + +## Mark executable scripts (Python etc.) for installation +## in contrast to setup.py, you can choose the destination +# catkin_install_python(PROGRAMS +# scripts/my_python_script +# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark executables for installation +## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html +# install(TARGETS ${PROJECT_NAME}_node +# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark libraries for installation +## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html +# install(TARGETS ${PROJECT_NAME} +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} +# ) + +## Mark cpp header files for installation +# install(DIRECTORY include/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +# FILES_MATCHING PATTERN "*.h" +# PATTERN ".svn" EXCLUDE +# ) + +## Mark other files for installation (e.g. launch and bag files, etc.) +# install(FILES +# # myfile1 +# # myfile2 +# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +# ) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# catkin_add_gtest(${PROJECT_NAME}-test test/test_offboard_py.cpp) +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) diff --git a/offboard_py/launch/start_offb.launch b/offboard_py/launch/start_offb.launch new file mode 100644 index 0000000..e7d8906 --- /dev/null +++ b/offboard_py/launch/start_offb.launch @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/offboard_py/package.xml b/offboard_py/package.xml new file mode 100644 index 0000000..5654875 --- /dev/null +++ b/offboard_py/package.xml @@ -0,0 +1,62 @@ + + + offboard_py + 0.0.0 + The offboard_py package + + + + + docker + + + + + + TODO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + catkin + rospy + rospy + rospy + + + + + + + + diff --git a/offboard_py/scripts/offb_node.py b/offboard_py/scripts/offb_node.py new file mode 100755 index 0000000..c7a4386 --- /dev/null +++ b/offboard_py/scripts/offb_node.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 + +import rospy +from geometry_msgs.msg import PoseStamped +from mavros_msgs.msg import State +from mavros_msgs.srv import CommandBool, CommandBoolRequest, SetMode, SetModeRequest + +current_state = State() + +def state_cb(msg): + global current_state + current_state = msg + + +if __name__ == "__main__": + rospy.init_node("offb_node_py") + + state_sub = rospy.Subscriber("mavros/state", State, callback = state_cb) + + local_pos_pub = rospy.Publisher("mavros/setpoint_position/local", PoseStamped, queue_size=10) + + rospy.wait_for_service("/mavros/cmd/arming") + arming_client = rospy.ServiceProxy("mavros/cmd/arming", CommandBool) + + rospy.wait_for_service("/mavros/set_mode") + set_mode_client = rospy.ServiceProxy("mavros/set_mode", SetMode) + + + # Setpoint publishing MUST be faster than 2Hz + rate = rospy.Rate(20) + + # Wait for Flight Controller connection + while(not rospy.is_shutdown() and not current_state.connected): + rate.sleep() + + pose = PoseStamped() + + pose.pose.position.x = 0 + pose.pose.position.y = 0 + pose.pose.position.z = 2 + + # Send a few setpoints before starting + for i in range(100): + if(rospy.is_shutdown()): + break + + local_pos_pub.publish(pose) + rate.sleep() + + offb_set_mode = SetModeRequest() + offb_set_mode.custom_mode = 'OFFBOARD' + + arm_cmd = CommandBoolRequest() + arm_cmd.value = True + + last_req = rospy.Time.now() + + while(not rospy.is_shutdown()): + if(current_state.mode != "OFFBOARD" and (rospy.Time.now() - last_req) > rospy.Duration(5.0)): + if(set_mode_client.call(offb_set_mode).mode_sent == True): + rospy.loginfo("OFFBOARD enabled") + + last_req = rospy.Time.now() + else: + if(not current_state.armed and (rospy.Time.now() - last_req) > rospy.Duration(5.0)): + if(arming_client.call(arm_cmd).success == True): + rospy.loginfo("Vehicle armed") + + last_req = rospy.Time.now() + + local_pos_pub.publish(pose) + + rate.sleep() + From 0119b1a1af3f3d9ead1d37cbc1eb22c87881e6c0 Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Wed, 6 Mar 2024 20:36:23 +0000 Subject: [PATCH 06/17] Fix build_docker_image.bash --- docker/build_docker_image.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/build_docker_image.bash b/docker/build_docker_image.bash index d27f33f..11b0ce8 100755 --- a/docker/build_docker_image.bash +++ b/docker/build_docker_image.bash @@ -1,3 +1,3 @@ #!/bin/bash set -e -docker build -t mav_exp --build-arg SSH_PRIV_KEY="$(cat ~/.ssh/id_rsa)" . +docker build -t srl_mav_sim --build-arg SSH_PRIV_KEY="$(cat ~/.ssh/id_rsa)" . From 27c2d8f83e54f2d7cb84941ed15eeddcd0ac493e Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Wed, 6 Mar 2024 21:27:07 +0000 Subject: [PATCH 07/17] Update --- docker/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 5a838fc..211a1e9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -87,9 +87,11 @@ RUN ssh-keyscan github.com >> $HOME/.ssh/known_hosts RUN ssh-keyscan bitbucket.org >> $HOME/.ssh/known_hosts WORKDIR $HOME/catkin_ws/src RUN git clone --recurse-submodules git@github.com:smartroboticslab/srl-mav-sim.git +RUN git clone --recurse-submodules git@github.com:smartroboticslab/mpc_ros.git +RUN git clone git@github.com:smartroboticslab/mav_ekf.git RUN rm -rf $HOME/.ssh/id_rsa -# Install PX4 deps +# Install srl-mav-sim WORKDIR $HOME/catkin_ws/src RUN pip3 install kconfiglib USER root @@ -110,6 +112,7 @@ WORKDIR $HOME/catkin_ws USER root RUN apt-get install \ libgflags-dev \ + libgoogle-glog-dev \ ros-${ROS_DISTRO}-gazebo-msgs \ libignition-gazebo3-* \ libignition-transport8-* \ From 64ac0ac132da797d7f31f4c93b115c6cd622c3ab Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Fri, 8 Mar 2024 10:04:31 +0000 Subject: [PATCH 08/17] Add Java deps so that one can run jMAVSim with PX4 --- docker/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index 211a1e9..433b4d5 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -94,6 +94,7 @@ RUN rm -rf $HOME/.ssh/id_rsa # Install srl-mav-sim WORKDIR $HOME/catkin_ws/src RUN pip3 install kconfiglib +RUN apt install -qy ant openjdk-11-jdk USER root RUN ./srl-mav-sim/PX4-Autopilot/Tools/setup/ubuntu.sh --no-nuttx --no-sim-tools USER ${USER} @@ -140,6 +141,7 @@ RUN echo "bind-key k select-pane -U" >> $HOME/.tmux.conf RUN echo "bind-key l select-pane -R" >> $HOME/.tmux.conf USER ${USER} + # Entry point script WORKDIR $HOME COPY entry.sh / From 92b512dd42a9085dbb0729682710d4fcbe4a2788 Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Thu, 14 Mar 2024 17:03:40 +0000 Subject: [PATCH 09/17] Fix dockerfile --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 433b4d5..10b6c40 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -94,8 +94,8 @@ RUN rm -rf $HOME/.ssh/id_rsa # Install srl-mav-sim WORKDIR $HOME/catkin_ws/src RUN pip3 install kconfiglib -RUN apt install -qy ant openjdk-11-jdk USER root +RUN apt-get install ant openjdk-11-jdk -qy RUN ./srl-mav-sim/PX4-Autopilot/Tools/setup/ubuntu.sh --no-nuttx --no-sim-tools USER ${USER} From 013fb8b351fe97e9a94f30e3b79de59d138e7e8e Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Thu, 14 Mar 2024 17:06:00 +0000 Subject: [PATCH 10/17] Add QGroundControl to docker file --- docker/Dockerfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index 10b6c40..88bc5ae 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -121,6 +121,18 @@ RUN apt-get install \ USER ${USER} RUN env IGNITION_VERSION=fortress catkin build -DCMAKE_BUILD_TYPE=Release +# Install QGroundControl +USER root +RUN usermod -a -G dialout $USER +RUN apt-get remove modemmanager -y +RUN apt install gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl -y +RUN apt install fuse libfuse2 -y +RUN apt install libxcb-xinerama0 libxkbcommon-x11-0 libxcb-cursor0 -y +USER ${USER} +WORKDIR $HOME +RUN wget https://d176tv9ibo4jno.cloudfront.net/latest/QGroundControl.AppImage +RUN chmod +x QGroundControl.AppImage + # Tools USER root WORKDIR $HOME From bde43d5f04a5877d8a5f881856330a4549ad48db Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Thu, 14 Mar 2024 17:06:35 +0000 Subject: [PATCH 11/17] Delete offboard_py --- offboard_py/CMakeLists.txt | 204 --------------------------- offboard_py/launch/start_offb.launch | 10 -- offboard_py/package.xml | 62 -------- offboard_py/scripts/offb_node.py | 74 ---------- 4 files changed, 350 deletions(-) delete mode 100644 offboard_py/CMakeLists.txt delete mode 100644 offboard_py/launch/start_offb.launch delete mode 100644 offboard_py/package.xml delete mode 100755 offboard_py/scripts/offb_node.py diff --git a/offboard_py/CMakeLists.txt b/offboard_py/CMakeLists.txt deleted file mode 100644 index 295cafa..0000000 --- a/offboard_py/CMakeLists.txt +++ /dev/null @@ -1,204 +0,0 @@ -cmake_minimum_required(VERSION 3.0.2) -project(offboard_py) - -## Compile as C++11, supported in ROS Kinetic and newer -# add_compile_options(-std=c++11) - -## Find catkin macros and libraries -## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) -## is used, also find other catkin packages -find_package(catkin REQUIRED COMPONENTS - rospy -) - -## System dependencies are found with CMake's conventions -# find_package(Boost REQUIRED COMPONENTS system) - - -## Uncomment this if the package has a setup.py. This macro ensures -## modules and global scripts declared therein get installed -## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html -# catkin_python_setup() - -################################################ -## Declare ROS messages, services and actions ## -################################################ - -## To declare and build messages, services or actions from within this -## package, follow these steps: -## * Let MSG_DEP_SET be the set of packages whose message types you use in -## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). -## * In the file package.xml: -## * add a build_depend tag for "message_generation" -## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET -## * If MSG_DEP_SET isn't empty the following dependency has been pulled in -## but can be declared for certainty nonetheless: -## * add a exec_depend tag for "message_runtime" -## * In this file (CMakeLists.txt): -## * add "message_generation" and every package in MSG_DEP_SET to -## find_package(catkin REQUIRED COMPONENTS ...) -## * add "message_runtime" and every package in MSG_DEP_SET to -## catkin_package(CATKIN_DEPENDS ...) -## * uncomment the add_*_files sections below as needed -## and list every .msg/.srv/.action file to be processed -## * uncomment the generate_messages entry below -## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) - -## Generate messages in the 'msg' folder -# add_message_files( -# FILES -# Message1.msg -# Message2.msg -# ) - -## Generate services in the 'srv' folder -# add_service_files( -# FILES -# Service1.srv -# Service2.srv -# ) - -## Generate actions in the 'action' folder -# add_action_files( -# FILES -# Action1.action -# Action2.action -# ) - -## Generate added messages and services with any dependencies listed here -# generate_messages( -# DEPENDENCIES -# std_msgs # Or other packages containing msgs -# ) - -################################################ -## Declare ROS dynamic reconfigure parameters ## -################################################ - -## To declare and build dynamic reconfigure parameters within this -## package, follow these steps: -## * In the file package.xml: -## * add a build_depend and a exec_depend tag for "dynamic_reconfigure" -## * In this file (CMakeLists.txt): -## * add "dynamic_reconfigure" to -## find_package(catkin REQUIRED COMPONENTS ...) -## * uncomment the "generate_dynamic_reconfigure_options" section below -## and list every .cfg file to be processed - -## Generate dynamic reconfigure parameters in the 'cfg' folder -# generate_dynamic_reconfigure_options( -# cfg/DynReconf1.cfg -# cfg/DynReconf2.cfg -# ) - -################################### -## catkin specific configuration ## -################################### -## The catkin_package macro generates cmake config files for your package -## Declare things to be passed to dependent projects -## INCLUDE_DIRS: uncomment this if your package contains header files -## LIBRARIES: libraries you create in this project that dependent projects also need -## CATKIN_DEPENDS: catkin_packages dependent projects also need -## DEPENDS: system dependencies of this project that dependent projects also need -catkin_package( -# INCLUDE_DIRS include -# LIBRARIES offboard_py -# CATKIN_DEPENDS rospy -# DEPENDS system_lib -) - -########### -## Build ## -########### - -## Specify additional locations of header files -## Your package locations should be listed before other locations -include_directories( -# include - ${catkin_INCLUDE_DIRS} -) - -## Declare a C++ library -# add_library(${PROJECT_NAME} -# src/${PROJECT_NAME}/offboard_py.cpp -# ) - -## Add cmake target dependencies of the library -## as an example, code may need to be generated before libraries -## either from message generation or dynamic reconfigure -# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) - -## Declare a C++ executable -## With catkin_make all packages are built within a single CMake context -## The recommended prefix ensures that target names across packages don't collide -# add_executable(${PROJECT_NAME}_node src/offboard_py_node.cpp) - -## Rename C++ executable without prefix -## The above recommended prefix causes long target names, the following renames the -## target back to the shorter version for ease of user use -## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node" -# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "") - -## Add cmake target dependencies of the executable -## same as for the library above -# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) - -## Specify libraries to link a library or executable target against -# target_link_libraries(${PROJECT_NAME}_node -# ${catkin_LIBRARIES} -# ) - -############# -## Install ## -############# - -# all install targets should use catkin DESTINATION variables -# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html - -## Mark executable scripts (Python etc.) for installation -## in contrast to setup.py, you can choose the destination -# catkin_install_python(PROGRAMS -# scripts/my_python_script -# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} -# ) - -## Mark executables for installation -## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html -# install(TARGETS ${PROJECT_NAME}_node -# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} -# ) - -## Mark libraries for installation -## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html -# install(TARGETS ${PROJECT_NAME} -# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} -# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} -# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} -# ) - -## Mark cpp header files for installation -# install(DIRECTORY include/${PROJECT_NAME}/ -# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} -# FILES_MATCHING PATTERN "*.h" -# PATTERN ".svn" EXCLUDE -# ) - -## Mark other files for installation (e.g. launch and bag files, etc.) -# install(FILES -# # myfile1 -# # myfile2 -# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} -# ) - -############# -## Testing ## -############# - -## Add gtest based cpp test target and link libraries -# catkin_add_gtest(${PROJECT_NAME}-test test/test_offboard_py.cpp) -# if(TARGET ${PROJECT_NAME}-test) -# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) -# endif() - -## Add folders to be run by python nosetests -# catkin_add_nosetests(test) diff --git a/offboard_py/launch/start_offb.launch b/offboard_py/launch/start_offb.launch deleted file mode 100644 index e7d8906..0000000 --- a/offboard_py/launch/start_offb.launch +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/offboard_py/package.xml b/offboard_py/package.xml deleted file mode 100644 index 5654875..0000000 --- a/offboard_py/package.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - offboard_py - 0.0.0 - The offboard_py package - - - - - docker - - - - - - TODO - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - catkin - rospy - rospy - rospy - - - - - - - - diff --git a/offboard_py/scripts/offb_node.py b/offboard_py/scripts/offb_node.py deleted file mode 100755 index c7a4386..0000000 --- a/offboard_py/scripts/offb_node.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python3 - -import rospy -from geometry_msgs.msg import PoseStamped -from mavros_msgs.msg import State -from mavros_msgs.srv import CommandBool, CommandBoolRequest, SetMode, SetModeRequest - -current_state = State() - -def state_cb(msg): - global current_state - current_state = msg - - -if __name__ == "__main__": - rospy.init_node("offb_node_py") - - state_sub = rospy.Subscriber("mavros/state", State, callback = state_cb) - - local_pos_pub = rospy.Publisher("mavros/setpoint_position/local", PoseStamped, queue_size=10) - - rospy.wait_for_service("/mavros/cmd/arming") - arming_client = rospy.ServiceProxy("mavros/cmd/arming", CommandBool) - - rospy.wait_for_service("/mavros/set_mode") - set_mode_client = rospy.ServiceProxy("mavros/set_mode", SetMode) - - - # Setpoint publishing MUST be faster than 2Hz - rate = rospy.Rate(20) - - # Wait for Flight Controller connection - while(not rospy.is_shutdown() and not current_state.connected): - rate.sleep() - - pose = PoseStamped() - - pose.pose.position.x = 0 - pose.pose.position.y = 0 - pose.pose.position.z = 2 - - # Send a few setpoints before starting - for i in range(100): - if(rospy.is_shutdown()): - break - - local_pos_pub.publish(pose) - rate.sleep() - - offb_set_mode = SetModeRequest() - offb_set_mode.custom_mode = 'OFFBOARD' - - arm_cmd = CommandBoolRequest() - arm_cmd.value = True - - last_req = rospy.Time.now() - - while(not rospy.is_shutdown()): - if(current_state.mode != "OFFBOARD" and (rospy.Time.now() - last_req) > rospy.Duration(5.0)): - if(set_mode_client.call(offb_set_mode).mode_sent == True): - rospy.loginfo("OFFBOARD enabled") - - last_req = rospy.Time.now() - else: - if(not current_state.armed and (rospy.Time.now() - last_req) > rospy.Duration(5.0)): - if(arming_client.call(arm_cmd).success == True): - rospy.loginfo("Vehicle armed") - - last_req = rospy.Time.now() - - local_pos_pub.publish(pose) - - rate.sleep() - From 0e512628b21438acdfc3de1d0633f130a4fb0971 Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Thu, 14 Mar 2024 17:08:05 +0000 Subject: [PATCH 12/17] Update README --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 792ad2a..510e60a 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,17 @@ build and use the MAV simulator based on Ignition Gazebo. See [`srl_mpc_examples`](srl_mpc_examples/README.md) for usage examples of the SRL linear MPC. +**Important note**: + +If the drone does not seem to be taking off in Gazebo, you will probably need +to set the following PX4 parameters +([source](https://github.com/PX4/PX4-Autopilot/issues/19919#issuecomment-1188864384)): + +``` +rosrun mavros mavparam set COM_RCL_EXCEPT 4 # RC LOSS EXCEPTION -> 4 (Not documented) +rosrun mavros mavparam set NAV_DLL_ACT 0 # GCS loss failsafe mode -> 0 (Disabled) +rosrun mavros mavparam set NAV_RCL_ACT 0 # RC loss failsafe modea -> 0 (Not documented) +``` ## MAVROS From 676906e5f26dac06c498879f83596396f49259e1 Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Thu, 14 Mar 2024 17:08:38 +0000 Subject: [PATCH 13/17] Add test_offboard_mode.py --- scripts/test_offboard_mode.py | 62 +++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 scripts/test_offboard_mode.py diff --git a/scripts/test_offboard_mode.py b/scripts/test_offboard_mode.py new file mode 100755 index 0000000..03df289 --- /dev/null +++ b/scripts/test_offboard_mode.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +import time + +import rospy +from geometry_msgs.msg import PoseStamped +from mavros_msgs.msg import State +from mavros_msgs.srv import CommandBool, CommandBoolRequest, SetMode, SetModeRequest + +current_state = State() + +def state_cb(msg): + global current_state + current_state = msg + + +if __name__ == "__main__": + rospy.init_node("test_offboard_mode") + state_sub = rospy.Subscriber("mavros/state", State, callback = state_cb) + local_pos_pub = rospy.Publisher("/mavros/setpoint_position/local", PoseStamped, queue_size=10) + rospy.wait_for_service("/mavros/cmd/arming") + arming_client = rospy.ServiceProxy("mavros/cmd/arming", CommandBool) + rospy.wait_for_service("/mavros/set_mode") + set_mode_client = rospy.ServiceProxy("mavros/set_mode", SetMode) + + # Setpoint publishing MUST be faster than 2Hz + rate = rospy.Rate(20) + + # Wait for Flight Controller connection + while(not rospy.is_shutdown() and not current_state.connected): + rate.sleep() + rospy.loginfo("Connected!") + + # Send a few setpoints before starting + pose = PoseStamped() + pose.pose.position.x = 0 + pose.pose.position.y = 0 + pose.pose.position.z = 2 + for i in range(100): + if(rospy.is_shutdown()): + break + local_pos_pub.publish(pose) + rate.sleep() + + # Offboard mode + offb_set_mode = SetModeRequest() + offb_set_mode.custom_mode = 'OFFBOARD' + set_mode_client.call(offb_set_mode) + rospy.loginfo("Sent offboard mode!") + time.sleep(5) + + # Arm Command + arm_cmd = CommandBoolRequest() + arm_cmd.value = True + arming_client.call(arm_cmd) + rospy.loginfo("Sent ARM command!") + rate.sleep() + + # Keep publishing pose setpoint + rospy.loginfo("Sending position setpoint!") + while(not rospy.is_shutdown()): + local_pos_pub.publish(pose) + rate.sleep() From 53878b8ef1c968d4daf92dbe634f48db1b3d3f4b Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Thu, 14 Mar 2024 17:11:06 +0000 Subject: [PATCH 14/17] Update README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 510e60a..ce44ae4 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,12 @@ rosrun mavros mavparam set NAV_DLL_ACT 0 # GCS loss failsafe mode -> 0 (Disa rosrun mavros mavparam set NAV_RCL_ACT 0 # RC loss failsafe modea -> 0 (Not documented) ``` +You can test out whether you can take off by running: + +``` +python3 scripts/test_offboard_mode.py +``` + ## MAVROS [MAVROS](http://wiki.ros.org/mavros) allows communicating with the PX4 through From 9649f412f80aebd5b6a4437fd355cc6226d681a6 Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Thu, 14 Mar 2024 17:15:46 +0000 Subject: [PATCH 15/17] Add make fix_px4 target and update README --- Makefile | 5 +++++ README.md | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0ddee41..df6b74b 100644 --- a/Makefile +++ b/Makefile @@ -25,3 +25,8 @@ run_docker: ## Run srl_mav_sim docker --pid=host \ --network="host" \ -it --rm srl_mav_sim /bin/bash + +fix_px4: ## Fix PX4 in gazebo mode + rosrun mavros mavparam set COM_RCL_EXCEPT 4 # RC LOSS EXCEPTION -> 4 (Not documented) + rosrun mavros mavparam set NAV_DLL_ACT 0 # GCS loss failsafe mode -> 0 (Disabled) + rosrun mavros mavparam set NAV_RCL_ACT 0 # RC loss failsafe modea -> 0 (Not documented) diff --git a/README.md b/README.md index ce44ae4..4498f84 100644 --- a/README.md +++ b/README.md @@ -58,10 +58,11 @@ rosrun mavros mavparam set NAV_DLL_ACT 0 # GCS loss failsafe mode -> 0 (Disa rosrun mavros mavparam set NAV_RCL_ACT 0 # RC loss failsafe modea -> 0 (Not documented) ``` -You can test out whether you can take off by running: +Or simply type `make fix_px4` in the terminal. Then you can test out whether +the drone can take off by running: ``` -python3 scripts/test_offboard_mode.py +python3 scripts/test_offboard_mode.py # Sends offboard + arm + position setpoint command ``` ## MAVROS From bd0e90bf02ba204d07dcdfc522906d75715fbd8c Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Thu, 14 Mar 2024 17:23:05 +0000 Subject: [PATCH 16/17] Update README --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4498f84..4f1b164 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,17 @@ build and use the MAV simulator based on Ignition Gazebo. See [`srl_mpc_examples`](srl_mpc_examples/README.md) for usage examples of the SRL linear MPC. -**Important note**: +Alternatively, if you lazy like me you can run the entire simulator in docker +mode via three make targets: + +``` +make install_docker # Install docker +make build_docker # Build docker container +make run_docker # Run docker container +# Once you're running the container, both the username and password is `docker` +``` + +## Important Note If the drone does not seem to be taking off in Gazebo, you will probably need to set the following PX4 parameters From 6a819362e9f71cb6c7eedd187b8dea329771e0b7 Mon Sep 17 00:00:00 2001 From: Chris Choi Date: Thu, 14 Mar 2024 17:31:50 +0000 Subject: [PATCH 17/17] Update README --- README.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4f1b164..3c97b7c 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,20 @@ The simulators have been tested on Ubuntu 20.04 using ROS Noetic. ## Setup +If you're lazy like me you can run the entire simulator in docker +mode via three make targets: + +``` +make install_docker # Install docker +make build_docker # Build docker container +make run_docker # Run docker container +# Once you're running the container, both the username and password is `docker` +``` + +--- + +Alternatively ... + Install the `ros-noetic-desktop-full` package by following the instructions from [here](http://wiki.ros.org/noetic/Installation) and then install the common dependencies. @@ -46,15 +60,6 @@ build and use the MAV simulator based on Ignition Gazebo. See [`srl_mpc_examples`](srl_mpc_examples/README.md) for usage examples of the SRL linear MPC. -Alternatively, if you lazy like me you can run the entire simulator in docker -mode via three make targets: - -``` -make install_docker # Install docker -make build_docker # Build docker container -make run_docker # Run docker container -# Once you're running the container, both the username and password is `docker` -``` ## Important Note