-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from StarlingUAS/pr-ap-camera
Gazebo Ros2 Ardupilot Camera Support
- Loading branch information
Showing
27 changed files
with
1,249 additions
and
634 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
# `starling-sim-iris-ap` | ||
|
||
Based on [`staring-sim-ardupilot-gazebo`](../sim-ardupilot-gazebo) | ||
See for additional environment variables. | ||
|
||
## Overview | ||
|
||
This image adds the launch files required to launch an Iris model with the ArduPilot plugin using Gazebo. | ||
|
||
The [iris ardupilot model](https://github.com/khancyr/ardupilot_gazebo/tree/master/models/iris_with_ardupilot) depends on the iris with standoffs and a *gimbal_small_2d*. | ||
|
||
The original gimbal in the gazebo model library is out of date, therefore an updated one is included in this image. It also includes an updated plugin which allows control of the gimbal and streams the camera image. | ||
## Environment Variables | ||
|
||
Name | Default Value | Description | ||
----------------------|------------------------------|------------ | ||
`AP_SITL_ADDRESS` | 127.0.0.1 | IP address for Gazebo plugin to use to talk to ArduPilot instance | ||
`AP_SITL_HOST` | {null} | Hostname for Gazebo plugin to use to talk to ArduPilot instance. Set to __override__ IP address. | ||
`CAMERA_NAME` | camera | ROS2 Name of the camera, camera topic is `$VEHICLE_NAMESPACE/$CAMERA_NAME/image_raw`. | ||
`CAMERA_HEIGHT` | 480 | Height resolution of camera image | ||
`CAMERA_WIDTH` | 640 | Width resolution of camera image | ||
`GIMBAL_INITIAL_ANGLE`| 0.785 | Initial angle (radians) of the gimbal. 0.0 Angle is forwards, pi/2 is down. | ||
|
||
## Exposed Topics | ||
|
||
Name | Topic | Description | ||
----------------------|------------------------------|------------ | ||
`$VEHICLE_NAMESPACE/$CAMERA_NAME/image_raw` | `sensor_msgs/msg/Image` | Image topic from the camera attached to the gimbal | ||
`$VEHICLE_NAMESPACE/$CAMERA_NAME/camera_info` | `sensor_msgs/msg/CameraInfo` | Camera Info topic from the camera attached to the gimbal | ||
`$VEHICLE_NAMESPACE/gimbal_tilt_cmd` | `std_msgs/msg/Float32` | The target angle (radians) of the gimbal camera tilt [0.0, 3.14]. | ||
`$VEHICLE_NAMESPACE/gimbal_tilt_status` | `std_msgs/msg/Float32` | The current angle (radians) of the gimbal camera tilt [0.0, 3.14]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
|
||
# If AP_SYSID is "ordinal", then set AP_SYSID id to take AP_SYSID_BASE + ORDINAL from StatefulSet hostname | ||
# Hostname is of the form '<stateful set name>-<ordinal>' | ||
if [ "$AP_SYSID" == "ordinal" ]; then | ||
ORDINAL="${HOSTNAME##*-}" | ||
AP_SYSID=$((AP_SYSID_BASE + ORDINAL)); | ||
if (($AP_SYSID > 0 && $AP_SYSID <= 255 )); then | ||
echo "AP_SYSID was 'ordinal' therefore set to $AP_SYSID (from base: $AP_SYSID_BASE and hostname: $HOSTNAME)" | ||
export AP_SYSID | ||
else | ||
echo "AP_SYSID was 'ordinal' but result ($AP_SYSID) was not valid (from base: $AP_SYSID_BASE and hostname: $HOSTNAME)" | ||
exit 1 | ||
fi | ||
elif [ "$AP_SYSID" == "ip" ]; then | ||
AP_SYSID=$(hostname -i | cut -d'.' -f4) | ||
echo "AP_SYSID was 'ip' therefore set to $AP_SYSID (from IP: $(hostname -i))" | ||
export AP_SYSID | ||
elif (($AP_SYSID > 0 && $AP_SYSID <= 255 )); then | ||
echo "AP_SYSID setting as specified: $AP_SYSID" | ||
export AP_SYSID | ||
else | ||
echo "AP_SYSID ($AP_SYSID) is invalid. Must either be set to 'ordinal', 'ip' or number between 1 and 255 inclusive" | ||
exit 1 | ||
fi | ||
echo "AP_SYSID is set to $AP_SYSID" | ||
|
||
if [ ! -z "${AP_SITL_HOST}" ]; then | ||
# AP_SITL_HOST has been set, use it to set AP_SITL_ADDRESS | ||
AP_SITL_ADDRESS="$(getent hosts ${AP_SITL_HOST} | cut -d ' ' -f1)" | ||
if [ -z "${AP_SITL_ADDRESS}" ]; then | ||
# Address lookup failed | ||
echo "Error: Failed to lookup IP address for host '${AP_SITL_HOST}'" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [ ! -v $VEHICLE_NAMESPACE ]; then | ||
# If set Ensure VEHICLE_NAMESPACE is a valid topic name | ||
# Replace all '-' with '_' | ||
export VEHICLE_NAMESPACE=${VEHICLE_NAMESPACE//-/_} | ||
echo "VEHICLE_NAMESPACE setting to $VEHICLE_NAMESPACE" | ||
else | ||
export VEHICLE_NAMESPACE="vehicle_$AP_SYSID" | ||
echo "VEHICLE_NAMESPACE not set, default to auto generated default based on ardupilot sysid target ($AP_SYSID) of $VEHICLE_NAMESPACE" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
set -e | ||
echo "--------------- Start setup_display.sh ----------------------" | ||
|
||
if [ "$ENABLE_VIRTUAL_FRAMEBUFFER" = true ]; then | ||
echo "Creating virtual display using virtual framebuffer" | ||
export DISPLAY=:1 | ||
rm -f /tmp/.X1-lock | ||
Xvfb $DISPLAY -screen 0 1600x900x24 & | ||
|
||
echo "Waiting for display to become available" | ||
while [ ! -e /tmp/.X11-unix/X1 ]; do echo "Wait for X server.."; sleep 0.1; done | ||
else | ||
echo "Virtual Framebuffer Disabled" | ||
fi | ||
echo "--------------- End setup_display.sh ----------------------" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(gimbal_plugin) | ||
|
||
# Default to C++14 | ||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 14) | ||
endif() | ||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
# we dont use add_compile_options with pedantic in message packages | ||
# because the Python C extensions dont comply with it | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wno-inconsistent-missing-override") | ||
endif() | ||
|
||
if(WIN32) | ||
add_compile_definitions( | ||
# For math constants | ||
_USE_MATH_DEFINES | ||
# Minimize Windows namespace collision | ||
NOMINMAX | ||
WIN32_LEAN_AND_MEAN | ||
) | ||
endif() | ||
|
||
find_package(ament_cmake REQUIRED) | ||
find_package(gazebo_dev REQUIRED) | ||
find_package(gazebo_msgs REQUIRED) | ||
find_package(gazebo_ros REQUIRED) | ||
find_package(geometry_msgs REQUIRED) | ||
# find_package(nav_msgs REQUIRED) | ||
find_package(rclcpp REQUIRED) | ||
# find_package(sensor_msgs REQUIRED) | ||
find_package(std_msgs REQUIRED) | ||
find_package(std_srvs REQUIRED) | ||
# find_package(tf2 REQUIRED) | ||
# find_package(tf2_geometry_msgs REQUIRED) | ||
# find_package(tf2_ros REQUIRED) | ||
# find_package(trajectory_msgs REQUIRED) | ||
|
||
link_directories(${gazebo_dev_LIBRARY_DIRS}) | ||
|
||
# Gimbal2dPlugin | ||
add_library(Gimbal2dPlugin SHARED | ||
src/Gimbal2dPlugin.cpp | ||
) | ||
target_include_directories(Gimbal2dPlugin PUBLIC include) | ||
ament_target_dependencies(Gimbal2dPlugin | ||
"gazebo_dev" | ||
"gazebo_ros" | ||
"rclcpp" | ||
"geometry_msgs" | ||
) | ||
ament_export_libraries(Gimbal2dPlugin) | ||
|
||
# ament_export_include_directories(include) | ||
ament_export_dependencies(rclcpp) | ||
ament_export_dependencies(gazebo_dev) | ||
ament_export_dependencies(gazebo_msgs) | ||
ament_export_dependencies(gazebo_ros) | ||
|
||
if(NOT WIN32) | ||
if(NOT APPLE) | ||
set( | ||
AMENT_CMAKE_ENVIRONMENT_HOOKS_DESC_gazebo_plugins | ||
"prepend-non-duplicate;LD_LIBRARY_PATH;${GAZEBO_PLUGIN_PATH}") | ||
else() | ||
set( | ||
AMENT_CMAKE_ENVIRONMENT_HOOKS_DESC_gazebo_plugins | ||
"prepend-non-duplicate;DYLD_LIBRARY_PATH;${GAZEBO_PLUGIN_PATH}") | ||
endif() | ||
endif() | ||
ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/env-hooks/gazebo_plugins.sh.in") | ||
|
||
ament_package() | ||
|
||
install(DIRECTORY include/ | ||
DESTINATION include) | ||
|
||
install(TARGETS | ||
Gimbal2dPlugin | ||
ARCHIVE DESTINATION lib | ||
LIBRARY DESTINATION lib | ||
RUNTIME DESTINATION bin) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Configuration file for colcon (https://colcon.readthedocs.io). | ||
# | ||
# Please see the doc for the details of the spec: | ||
# - https://colcon.readthedocs.io/en/released/user/configuration.html#colcon-pkg-files | ||
|
||
{ | ||
"dependencies": ["Gazebo"], | ||
} |
19 changes: 19 additions & 0 deletions
19
simulator/vehicles/iris-ap/gimbal_plugin/env-hooks/gazebo_plugins.sh.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# generated from gazebo_plugins/env-hooks/gazebo_plugins.sh.in | ||
|
||
# detect if running on Darwin platform | ||
_UNAME=`uname -s` | ||
_IS_DARWIN=0 | ||
if [ "$_UNAME" = "Darwin" ]; then | ||
_IS_DARWIN=1 | ||
fi | ||
unset _UNAME | ||
|
||
if [ $_IS_DARWIN -eq 0 ]; then | ||
ament_prepend_unique_value LD_LIBRARY_PATH @GAZEBO_PLUGIN_PATH@ | ||
else | ||
ament_prepend_unique_value DYLD_LIBRARY_PATH @GAZEBO_PLUGIN_PATH@ | ||
fi | ||
unset _IS_DARWIN | ||
|
||
ament_prepend_unique_value GAZEBO_PLUGIN_PATH "$AMENT_CURRENT_PREFIX/lib" | ||
|
Oops, something went wrong.