Skip to content

Commit

Permalink
ros2 development
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshZ18 committed Oct 9, 2021
1 parent acf6854 commit f4d0360
Show file tree
Hide file tree
Showing 23 changed files with 392 additions and 203 deletions.
64 changes: 31 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.5)
project(flexbe_app)

find_package(catkin REQUIRED)

## 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()

# specify catkin-specific information
# INCLUDE_DIRS - The exported include paths (i.e. cflags) for the package
# LIBRARIES - The exported libraries from the project
# CATKIN_DEPENDS - Other catkin projects that this project depends on
# DEPENDS - Non-catkin CMake projects that this project depends on
# CFG_EXTRAS - Additional configuration options
catkin_package(
INCLUDE_DIRS src
LIBRARIES ${PROJECT_NAME})
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)

# use add_library() or add_executable() as required
#add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS})
Expand All @@ -32,9 +24,9 @@ add_custom_command(OUTPUT nwjs

add_custom_target(nw_install DEPENDS nwjs)

if(NOT ${CMAKE_CURRENT_SOURCE_DIR}/nwjs)
safe_execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bin/nwjs_install)
endif()
#if(NOT ${CMAKE_CURRENT_SOURCE_DIR}/nwjs)
# safe_execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bin/nwjs_install)
#endif()

#############
## Install ##
Expand All @@ -43,28 +35,34 @@ endif()
INSTALL(PROGRAMS
bin/run_app
bin/shortcut
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
bin/nwjs_install
bin/test_report
DESTINATION lib/${PROJECT_NAME}
)
INSTALL(FILES
package.json
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
DESTINATION lib/${PROJECT_NAME}
)
INSTALL(FILES
flexbe.desktop
DESTINATION lib/${PROJECT_NAME}
)
INSTALL(DIRECTORY
src
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
DESTINATION lib/${PROJECT_NAME}
)
INSTALL(DIRECTORY
nwjs
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
USE_SOURCE_PERMISSIONS
launch
DESTINATION lib/${PROJECT_NAME}
)
install(DIRECTORY
INSTALL(DIRECTORY
launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
DESTINATION share/${PROJECT_NAME}
)
#INSTALL(DIRECTORY
# nwjs
# DESTINATION lib/${PROJECT_NAME}
# USE_SOURCE_PERMISSIONS
#)

# run tests
if(CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)
add_rostest(launch/test_report.test)
endif()
ament_package()
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ To download the binaries manually instead, run the script `bin/nwjs_install`.

In order to create and prepare a new repository for behavior development, run the following script in your ROS workspace and pass it the name of your project or identifier:

rosrun flexbe_widget create_repo [your_project_name]
ros2 run flexbe_widget create_repo [your_project_name]

This will initialize a new local git repository with the correct workspace structure which you can then push to a desired remote location. Make sure that you build the workspace afterwards.

## Usage

If desired, run the following command to create a shortcut in the application menu:

rosrun flexbe_app shortcut create
rosrun flexbe_app shortcut remove # if you want to remove it
ros2 run flexbe_app shortcut create
ros2 run flexbe_app shortcut remove # if you want to remove it

Use the shortcut or the following command to run the FlexBE App alone, i.e., for only developing behaviors, but not executing them:

rosrun flexbe_app run_app --offline
ros2 run flexbe_app run_app --offline

Omitting the `--offline` arg will let the App try to connect to ROS. You can manually connect/disconnect the App in the *Configuration* view.

Use the following launch file to run FlexBE's operator control station, i.e., everything FlexBE requires on the operator machine for controlling behavior execution:

roslaunch flexbe_app flexbe_ocs.launch
roslaunch flexbe_onboard behavior_onboard.launch # counterpart expected to run on the robot
ros2 launch flexbe_app flexbe_ocs.launch.py
ros2 launch flexbe_onboard behavior_onboard.launch.py # counterpart expected to run on the robot

Use the following launch file to run both of the above for local behavior execution:

roslaunch flexbe_app flexbe_full.launch
ros2 launch flexbe_app flexbe_full.launch.py


## Backwards Compatibility
Expand Down
4 changes: 2 additions & 2 deletions bin/nwjs_install
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ TEMPFILE="nwjs.tar.gz"
mkdir -p ../nwjs
cd ../nwjs

VERSION="v0.42.3" # verified working, to be incremented explicitly

# VERSION="v0.42.3" # verified working, to be incremented explicitly
VERSION="v0.55.0"
# check if nw is already existing and up-to-date, abort if so
if [ -f nw ]; then
if [ -f version ] && [ "$(cat version)" == "$VERSION" ]; then
Expand Down
7 changes: 3 additions & 4 deletions bin/run_app
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/bin/bash

ROOT_PATH="$(rospack find flexbe_app)"
ROOT_PATH="$(ros2 pkg prefix flexbe_app)"/lib/flexbe_app
NW=$ROOT_PATH/nwjs/nw
if [ ! -f $NW ]; then
ROOT_PATH=.
NW=$ROOT_PATH/nwjs/nw
fi
if [ ! -x $NW ]; then
echo "Cannot run flexbe_app, need to download nwjs first."
echo "Please build flexbe_app via catkin before using it or run the following command now:"
echo " rosrun flexbe_app nwjs_install"
echo "Please build flexbe_app via colcon before using it or run the following command now:"
echo " ros2 run flexbe_app nwjs_install"
exit -1
fi

Expand Down
6 changes: 3 additions & 3 deletions bin/shortcut
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash
if [ "$1" == "create" ] ; then
cd $(rospack find flexbe_app)
cd $(ros2 pkg prefix flexbe_app)/lib/flexbe_app
if [[ -z $2 ]] ; then
cp flexbe.desktop ~/.local/share/applications
else
content=$(cat flexbe.desktop)
echo "${content/rosrun/$2; rosrun}" > ~/.local/share/applications/flexbe.desktop
echo "${content/ros2run/$2; ros2 run}" > ~/.local/share/applications/flexbe.desktop
fi
if [[ ! -d ~/.local/share/icons ]] ; then
mkdir -p ~/.local/share/icons
Expand All @@ -22,7 +22,7 @@ else
echo ""
echo " create - Creates the new launcher shortcut"
echo " (optional) In case you do not source a setup.bash in your .bashrc, you can specify one for the shortcut, e.g.:"
echo " > rosrun flexbe_app shortcut create \"source ~/catkin_ws/devel/setup.bash\""
echo " > ros2 run flexbe_app shortcut create \"source ~/ros2_ws/install/setup.bash\""
echo ""
echo " remove - Removes the launcher shortcut"
fi
32 changes: 17 additions & 15 deletions bin/test_report
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ class TestReport(unittest.TestCase):
if test_type == "assertTrue":
self.assertTrue(test_data, test_name)
def main():
try:
with open("/tmp/flexbe_app_behavior_report.log", 'r') as f:
report = yaml.safe_load(f)
except IOError:
pass # add no tests because there is no report to evaluate
else:
for test_type, tests in report.items():
for test_name, test_data in tests.items():
function_name = "test_%s_%s" % (test_name, test_type)
test_function = generate_test(test_type, test_data)
test_function.__name__ = function_name
setattr(TestReport, function_name, test_function)
unittest.main()
if __name__ == '__main__':
try:
with open("/tmp/flexbe_app_behavior_report.log", 'r') as f:
report = yaml.safe_load(f)
except IOError:
pass # add no tests because there is no report to evaluate
else:
for test_type, tests in report.items():
for test_name, test_data in tests.items():
function_name = "test_%s_%s" % (test_name, test_type)
test_function = generate_test(test_type, test_data)
test_function.__name__ = function_name
setattr(TestReport, function_name, test_function)
import rosunit
rosunit.unitrun("flexbe_app", "test_report", TestReport)
if __name__ == '__main__':
main()
3 changes: 1 addition & 2 deletions flexbe.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Version=1.0
Name=FlexBE App
Comment=User interface for the FlexBE behavior engine.
Exec=bash -i -c "rosrun flexbe_app run_app --offline"
Exec=bash -i -c "ros2 run flexbe_app run_app --offline"
Icon=flexbe_app.png
Type=Application
Categories=Application;Development;

28 changes: 28 additions & 0 deletions launch/flexbe_full.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.substitutions import LaunchConfiguration
from launch.launch_description_sources import PythonLaunchDescriptionSource

from ament_index_python.packages import get_package_share_directory

flexbe_app_dir = get_package_share_directory('flexbe_app')
flexbe_onboard_dir = get_package_share_directory('flexbe_onboard')


def generate_launch_description():
return LaunchDescription([
DeclareLaunchArgument(
"no_app",
default_value="false"),
IncludeLaunchDescription(
PythonLaunchDescriptionSource(flexbe_app_dir + "/launch/flexbe_ocs.launch.py"),
launch_arguments={
"offline": "false",
"no_app": LaunchConfiguration("no_app")
}.items()
),
IncludeLaunchDescription(
PythonLaunchDescriptionSource(flexbe_onboard_dir + "/behavior_onboard.launch.py")
)
])
34 changes: 34 additions & 0 deletions launch/flexbe_ocs.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.substitutions import LaunchConfiguration
from launch.launch_description_sources import PythonLaunchDescriptionSource


offline = DeclareLaunchArgument("offline", default_value="false")

offline_arg = None

if LaunchConfiguration("offline_arg"):
offline_arg = DeclareLaunchArgument("offline_arg", default_value="--offline")
else:
offline_arg = DeclareLaunchArgument("offline_arg", default_value="")

no_app = DeclareLaunchArgument("no_app", default_value="false")

behavior_mirror = Node(name="behavior_mirror", package="flexbe_mirror", executable="behavior_mirror_sm")

flexbe_app = Node(name="flexbe_app", package="flexbe_app", executable="run_app", output="screen",
arguments=[{LaunchConfiguration("offline_arg")}])

behavior_launcher = Node(name="behavior_launcher", package="flexbe_widget", executable="be_launcher", output="screen")

def generate_launch_description():
return LaunchDescription([
offline,
offline_arg,
no_app,
behavior_mirror,
flexbe_app,
behavior_launcher
])
37 changes: 37 additions & 0 deletions launch/test_report_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import sys
import ament_index_python
import launch
import launch_ros
import launch_ros.actions
import launch_testing.actions
import launch_testing_ros
import pytest
from ament_index_python.packages import get_package_share_directory

@pytest.mark.rostest
def generate_launch_description():
flexbe_app_dir = get_package_share_directory('flexbe_app')
TEST_PROC_PATH = os.path.join(flexbe_app_dir, 'test_report')

# This is necessary to get unbuffered output from the process under test
proc_env = os.environ.copy()
proc_env['PYTHONUNBUFFERED'] = '1'

test_report = launch.actions.ExecuteProcess(
cmd=[sys.executable, TEST_PROC_PATH],
env=proc_env,
output='screen',
sigterm_timeout=launch.substitutions.LaunchConfiguration('sigterm_timeout', default=90),
sigkill_timeout=launch.substitutions.LaunchConfiguration('sigkill_timeout', default=90)
)

return (
launch.LaunchDescription([
test_report,
launch_testing.actions.ReadyToTest()
]),
{
'test_report': test_report,
}
)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "src/main.js",
"window": {
"icon": "src/img/icon-128.png",
"toolbar": false,
"toolbar": true,
"width": 1340,
"height": 830,
"min_width": 1340,
Expand Down
Loading

0 comments on commit f4d0360

Please sign in to comment.