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

Feat/add-moveit-collision-object-services #13

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
39 changes: 37 additions & 2 deletions rcdt_utilities/nodes/moveit_controller_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
from rclpy.action import ActionServer
from rclpy.action.server import ServerGoalHandle

from moveit.planning import MoveItPy, PlanningComponent
from moveit.planning import MoveItPy, PlanningComponent, PlanningSceneMonitor
from moveit.core.robot_state import RobotState
from moveit.core.robot_model import RobotModel, JointModelGroup
from moveit.core.planning_interface import MotionPlanResponse
from moveit.core.controller_manager import ExecutionStatus
from rcdt_utilities_msgs.action import Moveit
from moveit.core.planning_scene import PlanningScene

from geometry_msgs.msg import PoseStamped
from moveit_msgs.msg import CollisionObject
from rcdt_utilities_msgs.action import Moveit
from rcdt_utilities_msgs.srv import AddObject
from std_srvs.srv import Trigger


class MoveitControllerNode(Node):
Expand All @@ -32,8 +36,11 @@ def __init__(self, group: str) -> None:
if not self.init_links(group):
return
self.planner: PlanningComponent = self.robot.get_planning_component(group)
self.monitor: PlanningSceneMonitor = self.robot.get_planning_scene_monitor()

self.server = ActionServer(self, Moveit, name, self.callback)
self.create_service(AddObject, "~/add_object", self.add_object)
self.create_service(Trigger, "~/clear_objects", self.clear_objects)

def init_links(self, group: str) -> bool:
robot_model: RobotModel = self.robot.get_robot_model()
Expand Down Expand Up @@ -97,6 +104,34 @@ def move_to_pose(self, pose: PoseStamped) -> bool:
self.planner.set_goal_state(pose_stamped_msg=pose, pose_link=self.ee_link)
return self.plan_and_execute()

def add_object(
self, request: AddObject.Request, response: AddObject.Response
) -> None:
with self.monitor.read_write() as scene:
scene: PlanningScene

collision_object = request.object
collision_object.operation = CollisionObject.ADD
collision_object.header.frame_id = "fr3_link0"
Jelmerdw marked this conversation as resolved.
Show resolved Hide resolved

scene.apply_collision_object(collision_object)
current_state: RobotState = scene.current_state
current_state.update()
response.success = True
return response
Jelmerdw marked this conversation as resolved.
Show resolved Hide resolved

def clear_objects(
self, _request: Trigger.Request, response: Trigger.Response
) -> None:
with self.monitor.read_write() as scene:
scene: PlanningScene
Jelmerdw marked this conversation as resolved.
Show resolved Hide resolved

scene.remove_all_collision_objects()
current_state: RobotState = scene.current_state
current_state.update()
Jelmerdw marked this conversation as resolved.
Show resolved Hide resolved
response.success = True
return response


def main(args: str = None) -> None:
rclpy.init(args=args)
Expand Down
4 changes: 3 additions & 1 deletion rcdt_utilities_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ find_package(ament_cmake_python REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(moveit_msgs REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
"srv/AddMarker.srv"
"srv/AddObject.srv"
"action/Moveit.action"
DEPENDENCIES std_msgs geometry_msgs
DEPENDENCIES std_msgs geometry_msgs moveit_msgs
)

if(BUILD_TESTING)
Expand Down
7 changes: 7 additions & 0 deletions rcdt_utilities_msgs/srv/AddObject.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: Alliander N. V.
#
# SPDX-License-Identifier: Apache-2.0

moveit_msgs/CollisionObject object
---
bool success