-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
N-Shimoda
committed
Nov 18, 2022
1 parent
46c5ec7
commit 1bd250d
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python | ||
|
||
import rospy | ||
from geometry_msgs.msg import PolygonStamped, PoseStamped, Quaternion | ||
|
||
header = None | ||
ghost_locations = None # type : Point32[] | ||
|
||
|
||
# callbuck function of "/ghost" to update ghost locations | ||
def ghostCb(msg): | ||
|
||
global header, ghost_locations | ||
|
||
header = msg.header | ||
ghost_locations = msg.polygon.points | ||
|
||
rospy.logerr("ghost_locations updated. (%s ghosts remain)", len(ghost_locations)) | ||
|
||
|
||
""" | ||
function to calculate next goal. | ||
param : ghost_locations (Point32[]) | ||
return : goal_pos (PoseStamped) | ||
""" | ||
def createTarget(ghost_locations): | ||
|
||
goal_pos = PoseStamped() | ||
|
||
# if ghost exists | ||
if len(ghost_locations) != 0: | ||
|
||
goal_pos.header.frame_id = "map" | ||
goal_pos.pose.position = ghost_locations[0] | ||
goal_pos.pose.orientation = Quaternion(0,0,0,1) | ||
|
||
return goal_pos | ||
|
||
|
||
# main function to buster ghosts | ||
def main(): | ||
|
||
global ghost_locations | ||
|
||
rospy.init_node("ghost_buster") | ||
|
||
rospy.Subscriber("ghost", PolygonStamped, ghostCb) | ||
|
||
pub_goal = rospy.Publisher("move_base_simple/goal", PoseStamped) | ||
|
||
rate = rospy.Rate(20.0) | ||
|
||
while not rospy.is_shutdown(): | ||
|
||
if ghost_locations is not None: | ||
|
||
goal_pos = createTarget(ghost_locations) | ||
pub_goal.publish(goal_pos) | ||
|
||
rate.sleep() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |