Skip to content

Commit

Permalink
utilsを分離
Browse files Browse the repository at this point in the history
  • Loading branch information
chama1176 committed Aug 20, 2024
1 parent a14f513 commit b80158e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 59 deletions.
30 changes: 1 addition & 29 deletions sciurus17_examples_py/sciurus17_examples_py/gripper_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,7 @@
PlanRequestParameters,
)


def plan_and_execute(
robot,
planning_component,
logger,
single_plan_parameters=None,
multi_plan_parameters=None,
sleep_time=0.0,
):
"""Helper function to plan and execute a motion."""
logger.info("Planning trajectory")
if multi_plan_parameters is not None:
plan_result = planning_component.plan(
multi_plan_parameters=multi_plan_parameters)
elif single_plan_parameters is not None:
plan_result = planning_component.plan(
single_plan_parameters=single_plan_parameters)
else:
plan_result = planning_component.plan()

# execute the plan
if plan_result:
logger.info("Executing plan")
robot_trajectory = plan_result.trajectory
robot.execute(robot_trajectory, controllers=[])
else:
logger.error("Planning failed")

time.sleep(sleep_time)
from sciurus17_examples_py.utils import plan_and_execute


def main(args=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,7 @@
PlanRequestParameters,
)


def plan_and_execute(
robot,
planning_component,
logger,
single_plan_parameters=None,
multi_plan_parameters=None,
sleep_time=0.0,
):
"""Helper function to plan and execute a motion."""
logger.info("Planning trajectory")
if multi_plan_parameters is not None:
plan_result = planning_component.plan(
multi_plan_parameters=multi_plan_parameters)
elif single_plan_parameters is not None:
plan_result = planning_component.plan(
single_plan_parameters=single_plan_parameters)
else:
plan_result = planning_component.plan()

# execute the plan
if plan_result:
logger.info("Executing plan")
robot_trajectory = plan_result.trajectory
robot.execute(robot_trajectory, controllers=[])
else:
logger.error("Planning failed")

time.sleep(sleep_time)

from sciurus17_examples_py.utils import plan_and_execute

def main(args=None):
rclpy.init(args=args)
Expand Down
30 changes: 30 additions & 0 deletions sciurus17_examples_py/sciurus17_examples_py/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import time

def plan_and_execute(
robot,
planning_component,
logger,
single_plan_parameters=None,
multi_plan_parameters=None,
sleep_time=0.0,
):
"""Helper function to plan and execute a motion."""
logger.info("Planning trajectory")
if multi_plan_parameters is not None:
plan_result = planning_component.plan(
multi_plan_parameters=multi_plan_parameters)
elif single_plan_parameters is not None:
plan_result = planning_component.plan(
single_plan_parameters=single_plan_parameters)
else:
plan_result = planning_component.plan()

# execute the plan
if plan_result:
logger.info("Executing plan")
robot_trajectory = plan_result.trajectory
robot.execute(robot_trajectory, controllers=[])
else:
logger.error("Planning failed")

time.sleep(sleep_time)

0 comments on commit b80158e

Please sign in to comment.