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

[WIP][Spot] Add person lead demo #1339

Draft
wants to merge 115 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
5352c76
[spot_person_leader] add spot_person_leader package
sktometometo Apr 11, 2021
da5171a
[spot_person_leader] update demo
sktometometo Apr 11, 2021
45b7770
[spot_person_leader] add .gitignore tu autowalk directory
sktometometo Apr 11, 2021
9938163
[spot_person_leader] bugfix and update parameters
sktometometo Apr 11, 2021
95ad1f2
Update README.md
sktometometo Apr 12, 2021
d63da9b
[spot_person_leader] update node script's name
sktometometo Apr 12, 2021
145da13
[spot_person_leader] support stair
sktometometo Apr 25, 2021
1d8d234
[spot_person_leader] update
sktometometo May 4, 2021
ec62152
[spot_person_leader] update demo.launch
sktometometo May 4, 2021
c3fd47d
[spot_person_leader] update navigate_to list
sktometometo May 6, 2021
8c217d1
[spot_person_leader] update to use spot_ros_client
sktometometo May 6, 2021
fe8d40d
[spot_person_leader] fix bugs
sktometometo May 6, 2021
bb5ae59
[spot_person_leader] update some
sktometometo May 6, 2021
d76ca37
[spot_person_leader] update
sktometometo May 6, 2021
ceaeaf2
[spot_person_leader] support map.yaml
sktometometo May 8, 2021
3e93e20
[spot_person_leader] update
sktometometo May 8, 2021
d29a863
[spot_person_leader] update
sktometometo May 9, 2021
5ae67ac
[spot_person_leader] update map
sktometometo May 9, 2021
801255b
[spot_person_leader] update
sktometometo May 9, 2021
5ba771e
[spot_person_leader] update map
sktometometo May 10, 2021
ad37f43
[spot_person_leader] update lines
sktometometo May 10, 2021
995a02b
[spot_person_leader] add person_tracker
sktometometo May 11, 2021
d6e6c83
[spot_person_leader] add person_tracking to demo
sktometometo May 15, 2021
1e03fc5
[spot_person_leader] fix bugs
sktometometo May 15, 2021
0fd0690
[spot_person_leader] update
sktometometo May 20, 2021
adc26ee
[spot_person_leader] update
sktometometo May 20, 2021
951509f
[spot_person_leader] update
sktometometo May 20, 2021
63c0981
[spot_person_leader] add 2FEntrance to map
sktometometo May 20, 2021
a64ce71
[spot_person_leader] update
sktometometo May 20, 2021
c7961b7
[spot_person_leader] update
sktometometo May 24, 2021
5a1fd11
[spot_person_leader] add current_node publisher
sktometometo Jun 2, 2021
01c2d9d
[spot_person_leader] update
sktometometo Jun 3, 2021
df78113
[spot_person_leader] update
sktometometo Jun 4, 2021
d79ec98
[spot_person_leader] add maingate route
sktometometo Jun 14, 2021
0da5739
[spot_person_leader] add car tracker
sktometometo Jun 15, 2021
a7dedcb
[spot_person_leader] add edges
sktometometo Jun 15, 2021
660f2ce
[spot_person_leader] add obstacle_detector.launch
sktometometo Jun 15, 2021
2033ba5
[spot_person_leader] add jsk_data to build_tool_depend
sktometometo Jun 15, 2021
abc4e7b
[spot_person_leader] fix obstacle_detector
sktometometo Jun 15, 2021
cb70f4b
[spot_person_leader] add obstacle_detector to narrow path behavior
sktometometo Jun 16, 2021
304b3b8
[spot_person_leader] change volume to 1.0
sktometometo Jun 16, 2021
62b1164
[spot_person_leader] update scripts
sktometometo Jun 16, 2021
c239e97
[spot_person_leader] add car_tracker.py
sktometometo Jun 16, 2021
fed7ebb
[spot_person_leader] update script
sktometometo Jun 16, 2021
0bee028
[spot_person_leader] add car check before crossing road
sktometometo Jun 17, 2021
dd4b7fb
[spot_person_leader] update map
sktometometo Jun 17, 2021
29edc76
[spot_person_leader] add switchbot integration
sktometometo Jun 17, 2021
4c9421c
[spot_person_leader] add switchbot integration
sktometometo Jun 17, 2021
d94c023
[spot_person_leader] fix bugs
sktometometo Jun 17, 2021
80dc7a2
[spot_person_leader] add elevator behavior
sktometometo Jun 17, 2021
9e0c61f
[spot_person_leader] add download entry
sktometometo Jun 17, 2021
fbd9e4a
[spot_person_leader] update elevator behavior
sktometometo Jun 17, 2021
536e251
[spot_person_leader] update
sktometometo Jun 18, 2021
edb8049
[spot_person_leader] add elevator detection
sktometometo Jun 22, 2021
bb74f4f
[spot_person_leader] split detections to each file
sktometometo Jun 23, 2021
dee7d29
[spot_person_leader] add 7fmarker frame
sktometometo Jun 23, 2021
fe2c0df
[spot_person_leader] fix
sktometometo Jun 23, 2021
dd6058f
[spot_person_leader] fix each detection launch
sktometometo Jun 23, 2021
d232c3d
[spot_person_leader] split subscriber to each behavior
sktometometo Jun 23, 2021
d1f221c
[spot_person_leader] update
sktometometo Jun 23, 2021
76a86e1
[spot_person_leader] add elevator door checker
sktometometo Jun 23, 2021
a203f23
[spot_person_leader] fix elevator behavior
sktometometo Jun 25, 2021
919c2e3
[spot_person_leader] move to subdirectory
sktometometo Jun 26, 2021
07989ae
[spot_person_leader] add error handling while navigate_edge
sktometometo Jun 28, 2021
594db9e
[spot_person_leader] fix map
sktometometo Jun 28, 2021
d43ddc2
[spot_person_leader] fix behaviors
sktometometo Jun 28, 2021
6a92730
[spot_person_leader] update map
sktometometo Jun 28, 2021
28968fd
[spot_person_leader] update
sktometometo Jun 28, 2021
8b4eaad
[spot_person_leader] add bus and truck to crosswalk detection
sktometometo Jun 28, 2021
8be9d5d
[spot_person_leader] change token from arg to config file
sktometometo Jun 30, 2021
ad8004e
[spot_person_leader] update
sktometometo Jun 30, 2021
4922d8a
[spot_person_lerader] update map2
sktometometo Jun 30, 2021
027b7e8
[spot_person_leader] update crosswalk
sktometometo Jun 30, 2021
6cd680c
[spot_person_leader] update
sktometometo Jun 30, 2021
fb039fb
[spot_person_leader] update graph uploading and localization
sktometometo Jun 30, 2021
0038327
[spot_person_leader] use weight of edges when calculating path
sktometometo Jun 30, 2021
d79e68c
[spot_person_lead_behaviors] add spot_person_lead_behaviors package
sktometometo Aug 8, 2021
25f5de0
[spot_person_lead_behaviors] add detection launch and scripts
sktometometo Aug 11, 2021
267efc3
[spot_person_lead_demo] add spot_person_lead_demo pakcage
sktometometo Aug 11, 2021
38c8692
[spot_person_lead_demo][spot_person_lead_behaviors] update package.xml
sktometometo Aug 11, 2021
a7d124e
[spot_person_lead_behaviors] add stair and elevator behaviors
sktometometo Aug 13, 2021
db566c8
[spot_person_leader] remove
sktometometo Aug 13, 2021
9df99a6
[spot_person_lead_behaviors] rename
sktometometo Aug 13, 2021
901555e
[spot_person_lead_behaviors] update
sktometometo Aug 13, 2021
36f7c5f
[spot_person_lead_behaviors] fix bugs
sktometometo Aug 14, 2021
d49408a
[spot_person_lead_behaviors] add notification to elevator_behavior
sktometometo Aug 14, 2021
f8d04cc
[spot_person_lead_demo] update demo config and launch
sktometometo Aug 14, 2021
dbb2abb
[spot_person_lead_demo] update map
sktometometo Aug 15, 2021
53fbc1d
[spot_person_lead_demo] update map
sktometometo Aug 15, 2021
1b68fbf
[spot_person_lead_demo] update map
sktometometo Aug 16, 2021
794ec1f
[spot_person_lead_demo][spot_person_lead_behaviors] fix package name
sktometometo Aug 17, 2021
e38095a
[spot_person_lead_behaviors] fix behaviors
sktometometo Aug 17, 2021
000dbed
[spot_person_lead_behaviors] fix crosswalk_detection
sktometometo Aug 19, 2021
8a0ad39
[spot_person_lead_behaviors] fix crosswalk_behavior
sktometometo Aug 19, 2021
22e7383
[spot_person_lead_behaviors] fix map
sktometometo Aug 19, 2021
76bcce9
[spot_person_lead_behaviors] update stair_behavior
sktometometo Aug 19, 2021
f9d3a1d
Merge branch 'master' into PR/spot/person_lead_demo
sktometometo Aug 20, 2021
cd3f781
[spot_person_lead_behaviors] add params to narrow_behavior
sktometometo Sep 3, 2021
a280fea
[spot_person_lead_demo] add arg to demo.launch
sktometometo Sep 4, 2021
94ef983
[spot_person_lead_demo] add rosbag_record.launch
sktometometo Sep 4, 2021
b49c915
[lead_pos_server] add lead_pos_server package
sktometometo Sep 9, 2021
f74f51e
[lead_pos_server] update launch
sktometometo Sep 9, 2021
725a2f4
[lead_pos_server] bugfix
sktometometo Sep 9, 2021
140040f
[lead_pos_server] add string parser
sktometometo Sep 10, 2021
8553eb7
[lead_pos_server] update
sktometometo Sep 10, 2021
80885a1
[spot_person_lead_behaviors] update Stair Behavior
sktometometo Sep 13, 2021
e12e747
[spot_person_lead_demo] split mapfile to edgefile
sktometometo Sep 13, 2021
23c2c5d
[spot_person_lead_demo] update map
sktometometo Sep 13, 2021
632a324
[spot_person_lead_demo] update map
sktometometo Sep 13, 2021
5ea0822
[lead_pos_server] update
sktometometo Sep 13, 2021
bc2690b
[spot_person_lead_demo] support synchronized behavior managers
sktometometo Sep 14, 2021
84a6b49
[spot_person_lead_behaviors][spot_person_lead_demo] fix bugs and upda…
sktometometo Sep 14, 2021
8ccc253
[spot_person_lead_behaviors][spot_person_lead_demo] fix bugs and upda…
sktometometo Sep 14, 2021
c14b1dd
[spot_person_lead_demo] update rosbagrecrod
sktometometo Sep 15, 2021
9697788
[spot_person_lead_demo] update record launch
sktometometo Sep 15, 2021
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
7 changes: 7 additions & 0 deletions spot_person_leader/lead_pos_server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.0.2)
project(lead_pos_server)

find_package(catkin REQUIRED)

catkin_package(
)
22 changes: 22 additions & 0 deletions spot_person_leader/lead_pos_server/launch/lead_pos_server.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<launch>
<node pkg="lead_pos_server" type="person_tracker.py" name="lead_pos_server_person_tracker" output="screen">
<remap from="~bbox_array" to="/spot_recognition/bbox_array" />
<!-- remap from="~visible" to="" / -->

<rosparam subst_value="true">
frame_id_robot: 'body'
label_person: 0
dist_visible: 5.0
timeout_observation: 5.0
</rosparam>
</node>

<node pkg="lead_pos_server" type="lead_pos_server.py" name="lead_pos_server" output="screen">
<remap from="~visible" to="/lead_pos_server_person_tracker/visible" />
</node>

<node pkg="lead_pos_server" type="string_parser_node.py" name="lead_pos_string_parser" output="screen">
<remap from="~lead_pos" to="/lead_pos_server/lead_pos" />
</node>
</launch>
224 changes: 224 additions & 0 deletions spot_person_leader/lead_pos_server/node_scripts/lead_pos_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

import PyKDL
import actionlib
import rospy
import tf2_ros
import tf2_geometry_msgs

from std_msgs.msg import Bool
from move_base_msgs.msg import MoveBaseAction, MoveBaseResult
from geometry_msgs.msg import PoseStamped

from spot_ros_client.libspotros import SpotRosClient
from sound_play.libsoundplay import SoundClient


class LeadPosServer:

def __init__(self):

self._frame_id_robot = rospy.get_param('~frame_id_robot', 'body')
self._frame_id_fixed = rospy.get_param('~frame_id_fixed', 'odom')
self._timeout_transform = rospy.get_param('~timeout_transform', 0.05)

self._tolerance_x = rospy.get_param('~tolerance_x', 0.1)
self._tolerance_y = rospy.get_param('~tolerance_y', 0.1)
self._tolerance_theta = rospy.get_param('~tolerance_theta', 0.1)

self._tf_buffer = tf2_ros.Buffer()
self._tf_listener = tf2_ros.TransformListener(self._tf_buffer)

self._spot_client = SpotRosClient()
self._sound_client = SoundClient()

self._state_person_visible = False
self._state_last_visible = rospy.Time()
self._state_duration_visible = rospy.Duration()

self._subscriber_person_visible = rospy.Subscriber(
'~visible',
Bool,
self.callback_person_view
)
self._action_server_lead_pos = actionlib.SimpleActionServer(
'~lead_pos',
MoveBaseAction,
execute_cb=self.handler_lead_pose,
auto_start=True
)

rospy.loginfo('Initialized')

def callback_person_view(self, msg):

if self._state_person_visible != msg.data:
self._state_last_visible = rospy.Time.now()
self._state_duration_visible = rospy.Duration()
self._state_person_visible = msg.data
else:
self._state_duration_visible = rospy.Time.now() - self._state_last_visible

def handler_lead_pose(self, goal):

rospy.loginfo('New Goal: {}'.format(goal))

# [m] [m] [rad]
target_frame = goal.target_pose.header.frame_id
target_x = goal.target_pose.pose.position.x
target_y = goal.target_pose.pose.position.y
target_z = goal.target_pose.pose.position.z
target_qx = goal.target_pose.pose.orientation.x
target_qy = goal.target_pose.pose.orientation.y
target_qz = goal.target_pose.pose.orientation.z
target_qw = goal.target_pose.pose.orientation.w

#
# calculate target pose at fixed frame
#
try:
frame_fixed_to_target_frame = tf2_geometry_msgs.transform_to_kdl(
self._tf_buffer.lookup_transform(
self._frame_id_fixed,
target_frame,
rospy.Time(),
timeout=rospy.Duration(self._timeout_transform)
)
)
except (tf2_ros.LookupException,
tf2_ros.ConnectivityException,
tf2_ros.ExtrapolationException) as e:
rospy.logerr('lookup transform failed. {}'.format(e))
rospy.logerr('Aborted')
self._action_server_lead_pos.set_aborted()
return

frame_target_frame_to_goal = PyKDL.Frame(
PyKDL.Rotation.Quaternion(
target_qx,
target_qy,
target_qz,
target_qw
),
PyKDL.Vector(
target_x,
target_y,
target_z
)
)

frame_fixed_to_goal = frame_fixed_to_target_frame * frame_target_frame_to_goal

#
# Execute navigation
#
rate = rospy.Rate(1)
state = 'none' # trajectory, stop, or none
trajectory_command_validtime = rospy.Time()
while not rospy.is_shutdown():

rate.sleep()

if self._action_server_lead_pos.is_preempt_requested():
rospy.loginfo('Preemptino requested.')
self._action_server_lead_pos.set_preempted()
return

try:
frame_fixed_to_robot = tf2_geometry_msgs.transform_to_kdl(
self._tf_buffer.lookup_transform(
self._frame_id_fixed,
self._frame_id_robot,
rospy.Time(),
timeout=rospy.Duration(self._timeout_transform)
)
)
except (tf2_ros.LookupException,
tf2_ros.ConnectivityException,
tf2_ros.ExtrapolationException) as e:
rospy.logerr('lookup transform failed. {}'.format(e))
continue

frame_robot_to_goal = frame_fixed_to_robot.Inverse() * frame_fixed_to_goal

command_x = frame_robot_to_goal.p[0]
command_y = frame_robot_to_goal.p[1]
command_theta = frame_robot_to_goal.M.GetRPY()[2]

rospy.loginfo('command_x: {}'.format(command_x))
rospy.loginfo('command_y: {}'.format(command_y))
rospy.loginfo('r p y: {}'.format(frame_robot_to_goal.M.GetRPY()))
rospy.loginfo('command_theta: {}'.format(command_theta))
# break if robot reach the goal
if math.fabs(command_x) < self._tolerance_x \
and math.fabs(command_y) < self._tolerance_y \
and math.fabs(command_theta) < self._tolerance_theta:
rospy.loginfo('Goal Reached.')
self._action_server_lead_pos.set_succeeded(MoveBaseResult())
break

if state == 'trajectory':

if not self._state_person_visible and self._state_duration_visible > rospy.Duration(1):
rospy.logwarn('No person visible')
self._spot_client.pubCmdVel(0, 0, 0)
state = 'stop'
elif rospy.Time.now() > trajectory_command_validtime:
rospy.loginfo('Restart moving')
command_duration = 10
trajectory_command_validtime = rospy.Time.now() + rospy.Duration(command_duration - 2)
self._spot_client.trajectory(
command_x,
command_y,
command_theta,
command_duration,
blocking=False
)
state = 'trajectory'

elif state == 'stop':

if not self._state_person_visible and self._state_duration_visible > rospy.Duration(1):
rospy.logwarn('No person visible')
self._spot_client.pubCmdVel(0, 0, 0)
state = 'stop'
else:
rospy.loginfo('Restart moving')
command_duration = 10
trajectory_command_validtime = rospy.Time.now() + rospy.Duration(command_duration - 2)
self._spot_client.trajectory(
command_x,
command_y,
command_theta,
command_duration,
blocking=False
)
state = 'trajectory'

else:
if not self._state_person_visible and self._state_duration_visible > rospy.Duration(1):
rospy.logwarn('No person visible')
self._spot_client.pubCmdVel(0, 0, 0)
state = 'stop'
else:
rospy.loginfo('Start moving')
command_duration = 10
trajectory_command_validtime = rospy.Time.now() + rospy.Duration(command_duration - 2)
self._spot_client.trajectory(
command_x,
command_y,
command_theta,
command_duration,
blocking=False
)
state = 'trajectory'


if __name__ == '__main__':

rospy.init_node('lead_pos_server')
server = LeadPosServer()
rospy.spin()
100 changes: 100 additions & 0 deletions spot_person_leader/lead_pos_server/node_scripts/person_tracker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import PyKDL
import actionlib
import rospy
import tf2_ros
import tf2_geometry_msgs

from jsk_recognition_msgs.msg import BoundingBoxArray
from geometry_msgs.msg import PoseArray, Pose
from std_msgs.msg import Bool


def convert_msg_point_to_kdl_vector(point):
return PyKDL.Vector(point.x, point.y, point.z)


class PersonTracker(object):

def __init__(self):

self._frame_id_robot = rospy.get_param('~frame_id_robot', 'body')
self._label_person = rospy.get_param('~label_person', 0)
self._view_range = rospy.get_param('~view_range', 1.0)
self._timeout_transform = rospy.get_param('~timeout_transform', 0.05)

self._tf_buffer = tf2_ros.Buffer()
self._tf_listener = tf2_ros.TransformListener(self._tf_buffer)

self._sub_bbox_array = rospy.Subscriber(
'~bbox_array',
BoundingBoxArray,
self._cb_bbox_array
)
self._pub_visible = rospy.Publisher(
'~visible',
Bool,
queue_size=1
)
self._pub_people_pose_array = rospy.Publisher(
'~people_pose_array',
PoseArray,
queue_size=1
)

def _cb_bbox_array(self, msg):

frame_id_msg = msg.header.frame_id
frame_id_robot = self._frame_id_robot

try:
frame_fixed_to_robot = tf2_geometry_msgs.transform_to_kdl(
self._tf_buffer.lookup_transform(
frame_id_robot,
frame_id_msg,
msg.header.stamp,
timeout=rospy.Duration(self._timeout_transform)
)
)
except (tf2_ros.LookupException,
tf2_ros.ConnectivityException,
tf2_ros.ExtrapolationException) as e:
rospy.logerr('lookup transform failed. {}'.format(e))
return

# check if there is a person
is_person_visible = False
people_pose_array = PoseArray()
people_pose_array.header.stamp = msg.header.stamp
people_pose_array.header.frame_id = frame_id_robot
for bbox in msg.boxes:
if bbox.label == self._label_person:
vector_bbox = convert_msg_point_to_kdl_vector(
bbox.pose.position)
vector_bbox_robotbased = frame_fixed_to_robot * vector_bbox
rospy.loginfo('Person found at the distance {}'.format(
vector_bbox_robotbased.Norm()))
if vector_bbox_robotbased.Norm() < self._view_range:
pose = Pose()
pose.position.x = vector_bbox_robotbased[0]
pose.position.y = vector_bbox_robotbased[1]
pose.position.z = vector_bbox_robotbased[2]
pose.orientation.w = 1.0
people_pose_array.poses.append(pose)
is_person_visible = True
break
self._pub_people_pose_array.publish(people_pose_array)
self._pub_visible.publish(Bool(is_person_visible))


def main():

rospy.init_node('person_tracker')
person_tracker = PersonTracker()
rospy.spin()


if __name__ == '__main__':
main()
Loading