Skip to content

Commit

Permalink
Basic training in ROS2 (#326)
Browse files Browse the repository at this point in the history
* Redo table of contents to break into sidebar sections

* ROS2 versions of session 1 pages, ROS1 content moved to 'Legacy' section

* Port of session 2 material

* Added intro text on landing page and moved ROS1 content to dedicated legacy page

* Added numeric prefixes to file names for sorting in the filesystem

* Change ROS2 version from Dashing to Eloquent

* Fixed some bugs/problems after a run-through

* Added ROS1 and ROS2 versions of exercise solutions

* Point Travis back to ROS1 exercises

* Note about background for session 3

* Fix incorrent includes

* Fix missing include

* Fix another include

* Fix typo

* Update launch files to Foxy API

* Update eloquent references to foxy

* Minor clean-up prior to ROS2 PR merge

- update PC Setup page and install/check scripts
- add wait_for_service
- sync exercise references to better match instructions

Co-authored-by: Jeremy Zoss <jzoss@swri.org>
  • Loading branch information
jdlangs and JeremyZoss committed Feb 24, 2021
1 parent 2f9a489 commit 85f3034
Show file tree
Hide file tree
Showing 97 changed files with 2,455 additions and 141 deletions.
20 changes: 13 additions & 7 deletions .check_training_config.bash
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

TARGET_BRANCH=melodic # industrial_training git branch
ROS_RELEASE=melodic # ROS1 release version
ROS2_RELEASE=dashing # ROS2 release version
TARGET_BRANCH=foxy # industrial_training git branch
ROS_RELEASE=noetic # ROS1 release version
ROS2_RELEASE=foxy # ROS2 release version

#=======================================================================
# verify that PC configuration matches requirements for training class
Expand Down Expand Up @@ -73,7 +73,7 @@ function check_debs() {
check_deb libglu1-mesa-dev
check_deb pcl-tools
echo "Checking ROS1 packages:"
check_deb python-catkin-tools
check_deb python3-catkin-tools
check_deb ros-$ROS_RELEASE-desktop
check_deb ros-$ROS_RELEASE-perception
check_deb ros-$ROS_RELEASE-moveit
Expand All @@ -91,11 +91,17 @@ function check_debs() {

function check_bashrc() {
echo "Checking .bashrc... "
printf " - %-30s" "\$ROS_ROOT:"
if [ -z ${ROS_ROOT+x} ]; then
printf " - %-30s" "\$ROS_VERSION:"
if [ -z ${ROS_VERSION+x} ]; then
print_result $(false)
else
print_result $([ $ROS_ROOT == "/opt/ros/$ROS_RELEASE/share/ros" ])
print_result $([ $ROS_VERSION == "2" ])
fi
printf " - %-30s" "\$ROS_DISTRO:"
if [ -z ${ROS_DISTRO+x} ]; then
print_result $(false)
else
print_result $([ $ROS_DISTRO == "$ROS2_RELEASE" ])
fi
}

Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ matrix:
env:
- CONTAINER_IMAGE=ros:melodic \
CONTAINER_NAME=industrial_training_ci \
SRC_DIRS="exercises/1.3/src exercises/1.4/src"
SRC_DIRS="exercises/1.3/ros1/src exercises/1.4/ros1/src"
- name: "Exercise 2"
env:
- CONTAINER_IMAGE=ros:melodic \
CONTAINER_NAME=industrial_training_ci \
SRC_DIRS="exercises/2.0/src exercises/2.2/src exercises/2.3/src"
SRC_DIRS="exercises/2.0/ros1/src exercises/2.2/ros1/src exercises/2.3/ros1/src"
- name: "Exercise 3"
env:
- CONTAINER_IMAGE=ros:melodic \
Expand Down Expand Up @@ -65,4 +65,4 @@ before_script:
- source .industrial_training_ci.bash && ci_run update_image

script:
- source .industrial_training_ci.bash && ci_run build_exercises $SRC_DIRS
- source .industrial_training_ci.bash && ci_run build_exercises $SRC_DIRS
File renamed without changes.
44 changes: 44 additions & 0 deletions exercises/1.3/ros2/src/myworkcell_core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.5)
project(myworkcell_core)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# 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")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)

# The vision_node executable
add_executable(vision_node src/vision_node.cpp)
ament_target_dependencies(vision_node rclcpp)

# Mark executables and/or libraries for installation
install(TARGETS vision_node
ARCHIVE DESTINATION lib/${PROJECT_NAME}
LIBRARY DESTINATION lib/${PROJECT_NAME}
RUNTIME DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
20 changes: 20 additions & 0 deletions exercises/1.3/ros2/src/myworkcell_core/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>myworkcell_core</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="me@rosindustrial.com">ROS-Industrial</maintainer>
<license>TODO: License declaration</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>rclcpp</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
15 changes: 15 additions & 0 deletions exercises/1.3/ros2/src/myworkcell_core/src/vision_node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <rclcpp/rclcpp.hpp>

int main(int argc, char* argv[])
{
// This must be called before anything else ROS-related
rclcpp::init(argc, argv);

// Create a ROS node
auto node = std::make_shared<rclcpp::Node>("vision_node");

RCLCPP_INFO(node->get_logger(), "Hello, World!");

// Don't exit the program.
rclcpp::spin(node);
}
File renamed without changes.
45 changes: 45 additions & 0 deletions exercises/1.4/ros2/src/myworkcell_core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.5)
project(myworkcell_core)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# 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")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(fake_ar_publisher REQUIRED)

# The vision_node executable
add_executable(vision_node src/vision_node.cpp)
ament_target_dependencies(vision_node rclcpp fake_ar_publisher)

# Mark executables and/or libraries for installation
install(TARGETS vision_node
ARCHIVE DESTINATION lib/${PROJECT_NAME}
LIBRARY DESTINATION lib/${PROJECT_NAME}
RUNTIME DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
21 changes: 21 additions & 0 deletions exercises/1.4/ros2/src/myworkcell_core/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>myworkcell_core</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="me@rosindustrial.com">ROS-Industrial</maintainer>
<license>TODO: License declaration</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>rclcpp</depend>
<depend>fake_ar_publisher</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
40 changes: 40 additions & 0 deletions exercises/1.4/ros2/src/myworkcell_core/src/vision_node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <rclcpp/rclcpp.hpp>
#include <fake_ar_publisher/msg/ar_marker.hpp>

class Localizer : public rclcpp::Node
{
public:
Localizer() : Node("vision_node"), last_msg_{nullptr}
{
ar_sub_ = this->create_subscription<fake_ar_publisher::msg::ARMarker>(
"ar_pose_marker",
rclcpp::QoS(1),
std::bind(&Localizer::visionCallback, this, std::placeholders::_1));
}

void visionCallback(fake_ar_publisher::msg::ARMarker::SharedPtr msg)
{
last_msg_ = msg;
RCLCPP_INFO(get_logger(), "Received pose: x=%f, y=%f, z=%f",
msg->pose.pose.position.x,
msg->pose.pose.position.y,
msg->pose.pose.position.z);
}

rclcpp::Subscription<fake_ar_publisher::msg::ARMarker>::SharedPtr ar_sub_;
fake_ar_publisher::msg::ARMarker::SharedPtr last_msg_;
};

int main(int argc, char* argv[])
{
// This must be called before anything else ROS-related
rclcpp::init(argc, argv);

// The Localizer class provides this node's ROS interfaces
auto node = std::make_shared<Localizer>();

RCLCPP_INFO(node->get_logger(), "Vision node starting");

// Don't exit the program.
rclcpp::spin(node);
}
File renamed without changes.
60 changes: 60 additions & 0 deletions exercises/2.0/ros2/src/myworkcell_core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.5)
project(myworkcell_core)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# 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")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(fake_ar_publisher REQUIRED)

# Interface generation dependencies
find_package(geometry_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
"srv/LocalizePart.srv"
DEPENDENCIES geometry_msgs
)

# The vision_node executable
add_executable(vision_node src/vision_node.cpp)
ament_target_dependencies(vision_node rclcpp fake_ar_publisher)
rosidl_target_interfaces(vision_node ${PROJECT_NAME} "rosidl_typesupport_cpp")

# The myworkcell_node executable
add_executable(myworkcell_node src/myworkcell_node.cpp)
ament_target_dependencies(myworkcell_node rclcpp)
rosidl_target_interfaces(myworkcell_node ${PROJECT_NAME} "rosidl_typesupport_cpp")

# Mark executables and/or libraries for installation
install(TARGETS vision_node myworkcell_node
ARCHIVE DESTINATION lib/${PROJECT_NAME}
LIBRARY DESTINATION lib/${PROJECT_NAME}
RUNTIME DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
26 changes: 26 additions & 0 deletions exercises/2.0/ros2/src/myworkcell_core/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>myworkcell_core</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="me@rosindustrial.com">ROS-Industrial</maintainer>
<license>TODO: License declaration</license>
<member_of_group>rosidl_interface_packages</member_of_group>

<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<depend>geometry_msgs</depend>

<depend>rclcpp</depend>
<depend>fake_ar_publisher</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>

0 comments on commit 85f3034

Please sign in to comment.