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: safer navigation #152

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions skills/config/motions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ play_motion:
joints: [gripper_left_finger_joint, gripper_right_finger_joint]
points:
- positions: [0.04, 0.04]
time_from_start: 0.0
pre_navigation:
joints: [torso_lift_joint]
points:
- positions: [0.15]
time_from_start: 0.0
post_navigation:
joints: [torso_lift_joint, head_1_joint, head_2_joint]
points:
- positions: [0.25, 0.0, 0.0]
time_from_start: 0.0
2 changes: 1 addition & 1 deletion skills/src/lasr_skills/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from .wait_for_person_in_area import WaitForPersonInArea
from .describe_people import DescribePeople
from .look_to_point import LookToPoint
from .play_motion import PlayMotion
from .go_to_location import GoToLocation
from .go_to_semantic_location import GoToSemanticLocation
from .say import Say
from .listen import Listen
from .listen_for import ListenFor
from .play_motion import PlayMotion
from .receive_object import ReceiveObject
from .handover_object import HandoverObject
from .ask_and_listen import AskAndListen
150 changes: 139 additions & 11 deletions skills/src/lasr_skills/go_to_location.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,146 @@
import smach_ros

import smach
import rospy
import rosservice
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
from geometry_msgs.msg import PoseStamped
from geometry_msgs.msg import Pose, PoseStamped
from std_msgs.msg import Header

from typing import Union

from lasr_skills import PlayMotion

PUBLIC_CONTAINER = False

try:
from pal_startup_msgs.srv import (
StartupStart,
StartupStop,
StartupStartRequest,
StartupStopRequest,
)
except ModuleNotFoundError:
PUBLIC_CONTAINER = True

class GoToLocation(smach_ros.SimpleActionState):

def __init__(self):
super(GoToLocation, self).__init__(
"move_base",
MoveBaseAction,
goal_cb=lambda ud, _: MoveBaseGoal(
target_pose=PoseStamped(pose=ud.location, header=Header(frame_id="map"))
),
input_keys=["location"],
class GoToLocation(smach.StateMachine):

def __init__(self, location: Union[Pose, None] = None):
super(GoToLocation, self).__init__(outcomes=["succeeded", "failed"])

IS_SIMULATION = (
"/pal_startup_control/start" not in rosservice.get_service_list()
)

with self:
smach.StateMachine.add(
"LOWER_BASE",
PlayMotion("pre_navigation"),
transitions={
"succeeded": (
"ENABLE_HEAD_MANAGER" if not IS_SIMULATION else "GO_TO_LOCATION"
),
"aborted": "failed",
"preempted": "failed",
},
)

if not IS_SIMULATION:

if PUBLIC_CONTAINER:
rospy.logwarn(
"You are using a public container. The head manager will not be stopped during navigation."
)
else:
smach.StateMachine.add(
"ENABLE_HEAD_MANAGER",
smach_ros.ServiceState(
"/pal_startup_control/start",
StartupStart,
request=StartupStartRequest("head_manager", ""),
),
transitions={
"succeeded": "GO_TO_LOCATION",
"preempted": "failed",
"aborted": "failed",
},
)

if location is not None:
smach.StateMachine.add(
"GO_TO_LOCATION",
smach_ros.SimpleActionState(
"move_base",
MoveBaseAction,
goal=MoveBaseGoal(
target_pose=PoseStamped(
pose=location, header=Header(frame_id="map")
)
),
),
transitions={
"succeeded": (
"DISABLE_HEAD_MANAGER"
if not IS_SIMULATION
else "RAISE_BASE"
),
"aborted": "failed",
"preempted": "failed",
},
)
else:
smach.StateMachine.add(
"GO_TO_LOCATION",
smach_ros.SimpleActionState(
"move_base",
MoveBaseAction,
goal_cb=lambda ud, _: MoveBaseGoal(
target_pose=PoseStamped(
pose=ud.location, header=Header(frame_id="map")
)
),
input_keys=["location"],
),
transitions={
"succeeded": (
"DISABLE_HEAD_MANAGER"
if not IS_SIMULATION
else "RAISE_BASE"
),
"aborted": "failed",
"preempted": "failed",
},
)

if not IS_SIMULATION:

if PUBLIC_CONTAINER:
rospy.logwarn(
"You are using a public container. The head manager will not be start following navigation."
)
else:
smach.StateMachine.add(
"DISABLE_HEAD_MANAGER",
smach_ros.ServiceState(
"/pal_startup_control/stop",
StartupStop,
request=StartupStopRequest("head_manager"),
),
transitions={
"succeeded": "RAISE_BASE",
"aborted": "failed",
"preempted": "failed",
},
)

smach.StateMachine.add(
"RAISE_BASE",
PlayMotion("post_navigation"),
transitions={
"succeeded": (
"ENABLE_HEAD_MANAGER" if not IS_SIMULATION else "GO_TO_LOCATION"
),
"aborted": "failed",
"preempted": "failed",
},
)
15 changes: 13 additions & 2 deletions skills/src/lasr_skills/play_motion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import smach_ros
import rospy

from play_motion_msgs.msg import PlayMotionAction, PlayMotionGoal

Expand All @@ -11,14 +12,24 @@ def __init__(self, motion_name: Union[str, None] = None):
super(PlayMotion, self).__init__(
"play_motion",
PlayMotionAction,
goal=PlayMotionGoal(motion_name=motion_name, skip_planning=False),
goal=PlayMotionGoal(
motion_name=motion_name,
skip_planning=rospy.get_param(
f"/play_motion/motions/{motion_name}/joints"
)
== ["torso_lift_joint"],
),
)
else:
super(PlayMotion, self).__init__(
"play_motion",
PlayMotionAction,
goal_cb=lambda ud, _: PlayMotionGoal(
motion_name=ud.motion_name, skip_planning=False
motion_name=ud.motion_name,
skip_planning=rospy.get_param(
f"/play_motion/motions/{ud.motion_name}/joints"
== ["torso_lift_joint"]
),
),
input_keys=["motion_name"],
)
Loading