Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Add Example Agent call_do_objective.py Scripts #16

Merged
merged 18 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0a59037
Added the example call_do_objective scripts
chancecardona May 11, 2023
f126187
Updated call_do_objective_waypoint to be consistent
chancecardona May 11, 2023
1f52383
Updated copyright
chancecardona May 11, 2023
4061458
Reduce package dependencies to a more minimal set
chancecardona May 12, 2023
cb75dc9
Added doc strings and updated call_do_objectives
chancecardona May 12, 2023
9fd5941
Added precommit config, added license to new package, and then precom…
chancecardona May 12, 2023
340cb14
Renamed from moveit_studio_agent_utils to moveit_studio_agent_examples
chancecardona May 12, 2023
144ee98
Some review suggestions. mostly consistency and removing more uneeded…
chancecardona May 12, 2023
1e97891
Updated docstrings on all the call do objectives. Added a cancelation…
chancecardona May 13, 2023
f1f2dce
precommit and formatting
chancecardona May 13, 2023
33b5633
Updated to use MoveItErrorCodes. Added argparse and cancellation option
chancecardona May 15, 2023
44733b0
Incorporated cancel option with argparse into both scripts, removed e…
chancecardona May 15, 2023
ae2df5b
update docstring for waypoint script
chancecardona May 15, 2023
ba39f32
Apply suggestions from code review
chancecardona May 16, 2023
1ff1ee1
Remove unneeded fstrings and change hardcoded comment
chancecardona May 16, 2023
d9f7aa3
Updated copyright removed unused variable for flake8
chancecardona May 16, 2023
dee26e8
Fixed copyrights for real via ament_copyright add-missing
chancecardona May 17, 2023
e10b9d8
Fix sonarcloud bug
chancecardona May 17, 2023
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
36 changes: 36 additions & 0 deletions src/moveit_studio_agent_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.16.3)
project(moveit_studio_agent_utils)
chancecardona marked this conversation as resolved.
Show resolved Hide resolved

find_package(ament_cmake REQUIRED)
find_package(moveit_studio_agent_msgs REQUIRED)
find_package(moveit_studio_behavior_interface REQUIRED)
find_package(moveit_studio_behavior_msgs REQUIRED)
find_package(pluginlib REQUIRED)
find_package(std_msgs REQUIRED)

set(THIS_PACKAGE_INCLUDE_DEPENDS
chancecardona marked this conversation as resolved.
Show resolved Hide resolved
moveit_studio_agent_msgs
moveit_studio_behavior_interface
chancecardona marked this conversation as resolved.
Show resolved Hide resolved
moveit_studio_behavior_msgs
std_msgs
)

#############
## Install ##
#############

# Install scripts directory
install(PROGRAMS
scripts/call_do_objective.py
scripts/call_do_objective_waypoint.py
DESTINATION lib/${PROJECT_NAME}
)


chancecardona marked this conversation as resolved.
Show resolved Hide resolved
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
ament_package()
5 changes: 5 additions & 0 deletions src/moveit_studio_agent_utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# moveit_studio_agent_utils

Provides Scripts to interact with MoveIt Studio Agent API programatically.

Please see the [Interact with the Objective Server Directly](https://docs.picknik.ai/en/stable/how_to/interact_with_the_objective_server_directly/interact_with_the_objective_server_directly.html) tutorial for more information on these scripts and their use.
32 changes: 32 additions & 0 deletions src/moveit_studio_agent_utils/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<package format="3">
<name>moveit_studio_agent_utils</name>
<version>2.1.0</version>
chancecardona marked this conversation as resolved.
Show resolved Hide resolved
<description>Package containing scripts for interacting with MoveIt Studio Agent</description>

<maintainer email="[email protected]">Chance Cardona</maintainer>
<author email="[email protected]">Chance Cardona</author>

<license>BSD-3</license>
chancecardona marked this conversation as resolved.
Show resolved Hide resolved

<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>moveit_common</build_depend>
chancecardona marked this conversation as resolved.
Show resolved Hide resolved

<depend>moveit_studio_agent_msgs</depend>
<depend>moveit_studio_behavior_interface</depend>
<depend>moveit_studio_behavior_msgs</depend>
<depend>std_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_clang_format</test_depend>
<test_depend>ament_clang_tidy</test_depend>
<test_depend>ament_cmake_copyright</test_depend>
<test_depend>ament_cmake_lint_cmake</test_depend>
<test_depend>picknik_ament_copyright</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Empty file.
69 changes: 69 additions & 0 deletions src/moveit_studio_agent_utils/scripts/call_do_objective.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python3

# Copyright (c) 2023 PickNik Inc.
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.

# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.

# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


import rclpy
from rclpy.action import ActionClient
from rclpy.node import Node
import sys

from moveit_studio_agent_msgs.action import DoObjectiveSequence


class DoObjectiveSequenceClient(Node):
chancecardona marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self):
super().__init__("DoObjectiveSequence")
self._action_client = ActionClient(self, DoObjectiveSequence, "do_objective")

def send_goal(self, objective_name):
goal_msg = DoObjectiveSequence.Goal()
goal_msg.objective_name = objective_name
self._action_client.wait_for_server()
result = self._action_client.send_goal_async(goal_msg)
return result


def main(args=None):
if len(sys.argv) < 2:
print(
"usage: ros2 run moveit_studio_behavior call_do_objective.py 'Objective Name'"
)
else:
rclpy.init(args=args)

client = DoObjectiveSequenceClient()

future = client.send_goal(sys.argv[1])
chancecardona marked this conversation as resolved.
Show resolved Hide resolved

rclpy.spin_until_future_complete(client, future)
chancecardona marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python3

# Copyright (c) 2023 PickNik Inc.
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.

# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.

# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


import rclpy
from rclpy.action import ActionClient
from rclpy.node import Node
import sys

from moveit_studio_agent_msgs.action import DoObjectiveSequence
from moveit_studio_behavior_msgs.msg import (
BehaviorParameter,
BehaviorParameterDescription,
)

class DoObjectiveSequenceClient(Node):
chancecardona marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self):
super().__init__("DoObjectiveSequence")
self._action_client = ActionClient(self, DoObjectiveSequence, "do_objective")

def send_goal(self, waypoint_name="Behind"):
goal_msg = DoObjectiveSequence.Goal()
goal_msg.objective_name = "Move to Joint State"

behavior_parameter = BehaviorParameter()
behavior_parameter.behavior_namespaces.append("move_to_joint_state")
behavior_parameter.description.name = "waypoint_name"
behavior_parameter.description.type = BehaviorParameterDescription.TYPE_STRING
behavior_parameter.string_value = waypoint_name
goal_msg.parameter_overrides = [behavior_parameter]

self._action_client.wait_for_server()
result = self._action_client.send_goal_async(goal_msg)
return result


def main(args=None):
if len(sys.argv) < 2:
print(
"usage: ros2 run moveit_studio_behavior call_do_objective.py 'Waypoint Name'"
)
else:
rclpy.init(args=args)

client = DoObjectiveSequenceClient()

future = client.send_goal(sys.argv[1])

rclpy.spin_until_future_complete(client, future)


if __name__ == "__main__":
main()