Skip to content

Commit f97e040

Browse files
authored
Merge pull request #5 from rgariepy/galactic-CaP
New tutorial example - OpenAI/Code As Policies
2 parents b9a5585 + f5a3f48 commit f97e040

File tree

11 files changed

+401
-0
lines changed

11 files changed

+401
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright 2023 Clearpath Robotics, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# @author Ryan Gariepy ([email protected])
18+
19+
from launch import LaunchDescription
20+
from launch.actions import DeclareLaunchArgument
21+
from launch.substitutions import LaunchConfiguration
22+
from launch_ros.actions import Node
23+
24+
25+
def generate_launch_description():
26+
return LaunchDescription([
27+
DeclareLaunchArgument('openai_api_key', default_value='',
28+
description='API key set up via \
29+
https://platform.openai.com/account/api-keys'),
30+
DeclareLaunchArgument('model_name', default_value='gpt-3.5-turbo',
31+
description='OpenAI model name as selected from \
32+
https://platform.openai.com/docs/guides/gpt'),
33+
DeclareLaunchArgument('parking_brake', default_value='true',
34+
description='Set to false to execute commands on the robot'),
35+
Node(
36+
package='turtlebot4_openai_tutorials',
37+
executable='natural_language_nav',
38+
output='screen',
39+
emulate_tty=True,
40+
parameters=[
41+
{'openai_api_key': LaunchConfiguration('openai_api_key')},
42+
{'model_name': LaunchConfiguration('model_name')},
43+
{'parking_brake': LaunchConfiguration('parking_brake')}
44+
]
45+
),
46+
])
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>turtlebot4_openai_tutorials</name>
5+
<version>0.0.0</version>
6+
<description>Tutorials on using OpenAI to control Turtlebot 4</description>
7+
<maintainer email="[email protected]">rgariepy</maintainer>
8+
<license>Apache2</license>
9+
10+
<test_depend>ament_copyright</test_depend>
11+
<test_depend>ament_flake8</test_depend>
12+
<test_depend>ament_pep257</test_depend>
13+
<test_depend>python3-pytest</test_depend>
14+
15+
<depend>rclpy</depend>
16+
<depend>std_msgs</depend>
17+
<depend>turtlebot4_navigation</depend>
18+
19+
<exec_depend>python3-openai-pip</exec_depend>
20+
21+
<export>
22+
<build_type>ament_python</build_type>
23+
<ros2_package_share directory="share/${PROJECT_NAME}">
24+
prompts/turtlebot4_api.txt
25+
prompts/destination_api.txt
26+
</ros2_package_share>
27+
</export>
28+
</package>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Dock
2+
navigator.dock()
3+
# Undock
4+
navigator.undock()
5+
# Go to location 0.0, 1.0, facing North
6+
navigator.info('Moving to 0.0, 1.0, North')
7+
goal = navigator.getPoseStamped([0.0, 1.0], TurtleBot4Directions.NORTH)
8+
navigator.startToPose(goal)
9+
# Move to location -1.0, 5.0, facing South East
10+
navigator.info('Moving to -1.0, 5.0, South East')
11+
goal = navigator.getPoseStamped([-1.0, 5.0], TurtleBot4Directions.SOUTH_EAST)
12+
navigator.startToPose(goal)
13+
# Navigate to shelf
14+
dest = destinations['metal shelf']
15+
navigator.info('Moving to metal shelf')
16+
goal = navigator.getPoseStamped(dest[0:2], dest[2])
17+
navigator.startToPose(goal)
18+
# Navigate to wooden object
19+
dest = destinations['wooden crate']
20+
navigator.info('Moving to wooden crate')
21+
goal = navigator.getPoseStamped(dest[0:2], dest[2])
22+
navigator.startToPose(goal)
23+
# Go to forklift
24+
dest = destinations['forklift']
25+
navigator.info('Moving to forklift')
26+
goal = navigator.getPoseStamped(dest[0:2], dest[2])
27+
navigator.startToPose(goal)

turtlebot4_openai_tutorials/resource/turtlebot4_openai_tutorials

Whitespace-only changes.

turtlebot4_openai_tutorials/setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[develop]
2+
script_dir=$base/lib/turtlebot4_openai_tutorials
3+
[install]
4+
install_scripts=$base/lib/turtlebot4_openai_tutorials

turtlebot4_openai_tutorials/setup.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
from glob import glob
3+
from setuptools import setup
4+
5+
package_name = 'turtlebot4_openai_tutorials'
6+
7+
setup(
8+
name=package_name,
9+
version='0.0.0',
10+
packages=[package_name],
11+
data_files=[
12+
# Marker file
13+
('share/ament_index/resource_index/packages',
14+
['resource/' + package_name]),
15+
# Package.xml
16+
('share/' + package_name, ['package.xml']),
17+
# Launch files
18+
(os.path.join('share', package_name, 'launch'),
19+
glob(os.path.join('launch', '*launch.py'))),
20+
# Prompt files
21+
(os.path.join('share', package_name, 'prompts'),
22+
glob(os.path.join('prompts', '*.txt'))),
23+
],
24+
install_requires=['setuptools'],
25+
zip_safe=True,
26+
maintainer='rgariepy',
27+
maintainer_email='[email protected]',
28+
description='TurtleBot 4 OpenAI Integration Tutorials',
29+
license='Apache 2.0',
30+
tests_require=['pytest'],
31+
entry_points={
32+
'console_scripts': [
33+
'nav_to_pose = turtlebot4_openai_tutorials.nav_to_pose:main',
34+
'natural_language_nav = \
35+
turtlebot4_openai_tutorials.natural_language_nav:main',
36+
],
37+
},
38+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2015 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ament_copyright.main import main
16+
import pytest
17+
18+
19+
@pytest.mark.copyright
20+
@pytest.mark.linter
21+
def test_copyright():
22+
rc = main(argv=['.', 'test'])
23+
assert rc == 0, 'Found errors'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2017 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ament_flake8.main import main_with_errors
16+
import pytest
17+
18+
19+
@pytest.mark.flake8
20+
@pytest.mark.linter
21+
def test_flake8():
22+
rc, errors = main_with_errors(argv=[])
23+
assert rc == 0, \
24+
'Found %d code style errors / warnings:\n' % len(errors) + \
25+
'\n'.join(errors)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2015 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ament_pep257.main import main
16+
import pytest
17+
18+
19+
@pytest.mark.linter
20+
@pytest.mark.pep257
21+
def test_pep257():
22+
rc = main(argv=['.', 'test'])
23+
assert rc == 0, 'Found code style errors / warnings'

turtlebot4_openai_tutorials/turtlebot4_openai_tutorials/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)