Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch packages from HMI display menu Entry "My Program" #13

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

ros2 launch hmi_simulation_project_manager project_manager.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from asyncio import FastChildWatcher
import string
from tkinter.messagebox import NO
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to have a lot of extra import statements that aren't used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports seems to be like auto generated by visual studio code. I will remove them

import rclpy
from rclpy.node import Node
from turtlebot4_msgs.srv import MyProgram
import subprocess
from ament_index_python.packages import get_package_share_directory, get_package_prefix



class ProjectsManager(Node):
"""
The class ProjectsManager, attributes as a ROS Node that acts as a primary entrypoint
sumedhreddy90 marked this conversation as resolved.
Show resolved Hide resolved
in the ROS system for communication especially for launching multiple packages from HMI display.

Attributes:
Node: Is a class from rclpy.node.Node
More Information at: https://docs.ros2.org/latest/api/rclpy/api/node.html

Topics:
- Services:
- Service name: /my_program
- Service desciption:
- Create a service "my_program" to trigger a bool srv "my_program_on"
- When my_program_on is set to True from client node. The my_program service
returns Success

"""
def __init__(self):
"""
ProjectsManager constructor to initialize nodes, subscribers, publishers and parameters
"""
super().__init__('my_program_service')
self.my_program_request = self.create_service(MyProgram, 'my_program', self.project_manager_callback)
self.response_message = ''
self.response_result = False

def project_manager_callback(self, request, response):

self.response_message = response.message
self.response_result = response.success
# If the client requests the service with my_program_on = True, we run a bash script of launch
# Then return Success message upon successful request exectution
if(request.my_program_on):
self.get_logger().info('My Program Mode is turned on')
subprocess.call(["bash", '/home/sumedh/workspace/src/TurtleBot4Lessons/projects/hmi_simulation_project_manager/config/auto_launch.bash'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhhhhhhhhhhhh. This is a hard coded path. I am not sure how I feel about calling subprocess to run a script from inside a node.

Did you follow this pattern from someone else? At bare minimum the bath needs to be relative.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the hardcode path. I generally prefer going with relative path. However, the relative path isnt working. Hence, during testing, I used the complete path. In my recent commits, I changed it to relative path.
Yes, calling subprocess to run a script is possible and is friendly. Please refer to one of the implementation by Tully foote and Alejandro in one of their repo's.
https://github.com/osrf/drone_demo/blob/master/sitl_launcher/scripts/launch_drone_ros2.py
Please refer to line number 172

response.message = "My Program Mode received and running projects"
response.success = True

else:
self.get_logger().info('My Program Mode rejected')
response.message = "My Program Mode rejected and failed to run projects"
response.success = False

return response


def main(args=None):
"""
Main method to instantiate ROS nodes and TurtleUnDock class to undock the bot

Args:
None
"""
rclpy.init(args=args)

projects_manager = ProjectsManager()

rclpy.spin(projects_manager)

rclpy.shutdown()


if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
from re import X
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration

ARGUMENTS = [DeclareLaunchArgument('my_goal_pose', default_value='[8.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0]',
description='Goal position in X and Y coordinates')]


def generate_launch_description():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of launch isn't that great. Can you explain a bit about what is going on here?

Copy link
Contributor Author

@sumedhreddy90 sumedhreddy90 Aug 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, In this example, as a sample I am firing Nodes required for running motion planner algorithm. The TODO is that the program manager launch will make sure to maintain a queue of all student packages. Which inturn executes one by one in the Queue. This needs to be discussed on how to architect it.

HOME = os.environ.get('HOME')
directory = HOME + '/workspace/src/'

my_list = os.listdir(directory)

my_goal_pose = LaunchConfiguration('my_goal_pose'),
planner = Node(
package='unit02_simulation_motion_planner',
namespace='tb4_rider',
executable='tb4_rider',
name='turtlebot4_ride'
)
estimator = Node(
package='unit02_simulation_motion_planner',
namespace='ekf',
executable='ekf',
name='extented_kalman_filter'
)
goal_pub = Node(
package='unit02_simulation_motion_planner',
namespace='publish_goal',
executable='tb4_goal',
parameters=[
{'my_goal_pose': LaunchConfiguration('my_goal_pose')}],
name='tb4_goal_pose'
)
# Define LaunchDescription variable
launch_desc = LaunchDescription(ARGUMENTS)
launch_desc.add_action(planner)
launch_desc.add_action(estimator)
launch_desc.add_action(goal_pub)

return launch_desc
22 changes: 22 additions & 0 deletions projects/hmi_simulation_project_manager/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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>hmi_simulation_project_manager</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">sumedh</maintainer>
<license>TODO: License declaration</license>

<depend>rclpy</depend>
<depend>std_msgs</depend>
<depend>sensor_msgs</depend>
<depend>turtlebot4_msgs</depend>
<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
4 changes: 4 additions & 0 deletions projects/hmi_simulation_project_manager/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/hmi_simulation_project_manager
[install]
install_scripts=$base/lib/hmi_simulation_project_manager
29 changes: 29 additions & 0 deletions projects/hmi_simulation_project_manager/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from setuptools import setup
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unclear to me what this is for. Why does a ROS node need a setup.py file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to https://docs.ros.org/en/galactic/Tutorials/Intermediate/Launch/Launch-system.html. This import is an inbuilt packages used to setup the ROS2 package. This is generated when we create a new ROS2 package ros2 pkg create --build-type ament_python <package_name>

import os
from glob import glob

package_name = 'hmi_simulation_project_manager'

setup(
name=package_name,
version='0.0.0',
packages=[package_name],
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join('share', package_name), glob('launch/*.launch.py')),
],
install_requires=['setuptools'],
zip_safe=True,
maintainer='sumedh',
maintainer_email='[email protected]',
description='TODO: Package description',
license='TODO: License declaration',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'manager = hmi_simulation_project_manager.manager:main',
],
},
)
23 changes: 23 additions & 0 deletions projects/hmi_simulation_project_manager/test/test_copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_copyright.main import main
import pytest


@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found errors'
25 changes: 25 additions & 0 deletions projects/hmi_simulation_project_manager/test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2017 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_flake8.main import main_with_errors
import pytest


@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc, errors = main_with_errors(argv=[])
assert rc == 0, \
'Found %d code style errors / warnings:\n' % len(errors) + \
'\n'.join(errors)
23 changes: 23 additions & 0 deletions projects/hmi_simulation_project_manager/test/test_pep257.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_pep257.main import main
import pytest


@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found code style errors / warnings'
11 changes: 11 additions & 0 deletions projects/turtlebot4_msgs/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sumedhreddy90 marked this conversation as resolved.
Show resolved Hide resolved
Changelog for package turtlebot4_msgs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0.1.1 (2022-07-12)
------------------

0.1.0 (2022-05-03)
------------------
* First Galactic release
* Contributors: Roni Kreinin
37 changes: 37 additions & 0 deletions projects/turtlebot4_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.5)
project(turtlebot4_msgs)

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

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)


rosidl_generate_interfaces(${PROJECT_NAME}
"msg/UserLed.msg"
"msg/UserButton.msg"
"msg/UserDisplay.msg"
"srv/MyProgram.srv"
)

ament_package()
4 changes: 4 additions & 0 deletions projects/turtlebot4_msgs/msg/UserButton.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This message relays the state of the user buttons
sumedhreddy90 marked this conversation as resolved.
Show resolved Hide resolved
# Each button is represented with a boolean, were True indicates the button is pressed

bool[4] button
8 changes: 8 additions & 0 deletions projects/turtlebot4_msgs/msg/UserDisplay.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This message represents the header and 5 entries
sumedhreddy90 marked this conversation as resolved.
Show resolved Hide resolved
# that are displayed on the Turtlebot4 display
# selected_entry indicates which menu entry is currently selected

string ip
string battery
string[5] entries
int32 selected_entry
29 changes: 29 additions & 0 deletions projects/turtlebot4_msgs/msg/UserLed.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This message sets the state of the user LEDs
# Blink period is the time in milliseconds during which the ON/OFF cycle occurs
# The duty cycle represents the percentage of the blink period that the LED is ON
# A duty cycle of 1.0 would set the LED to always be ON, whereas a duty cycle of 0.0 is always OFF
# A blink period of 1000ms with a duty cycle of 0.6 will have the LED turn ON for 600ms,
# then OFF for 400ms

# Available LEDs
uint8 USER_LED_1 = 0
uint8 USER_LED_2 = 1

# Available colors
uint8 COLOR_OFF = 0
uint8 COLOR_GREEN = 1
uint8 COLOR_RED = 2
uint8 COLOR_YELLOW = 3


# Which available LED to use
uint8 led

# Which color to set the LED to
uint8 color

# Blink period in ms
uint32 blink_period

# Duty cycle (0.0 to 1.0)
float64 duty_cycle
24 changes: 24 additions & 0 deletions projects/turtlebot4_msgs/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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>turtlebot4_msgs</name>
<version>0.1.1</version>
<description>Turtlebot4 Messages</description>
<maintainer email="[email protected]">rkreinin</maintainer>
<license>Apache 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

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

<depend>std_msgs</depend>

<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
4 changes: 4 additions & 0 deletions projects/turtlebot4_msgs/srv/MyProgram.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bool my_program_on # true enables MyProgram and triggers a True flag
---
bool success # indicate successful application of command
string message # information for result