-
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.
Add support for merging ROS nodes Part of #7
- Loading branch information
1 parent
6deaae3
commit facc623
Showing
21 changed files
with
424 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,11 @@ CATKIN_IGNORE | |
# VSCode | ||
.vscode | ||
|
||
# Pycharm | ||
.idea/ | ||
|
||
# macOS cache | ||
.DS_Store | ||
|
||
# Coveralls | ||
.coverage | ||
.coverage |
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
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,23 @@ | ||
<launch> | ||
<arg name='robot_name' default='test_bot' /> | ||
<arg name='map_service' default='dynamic_map'/> | ||
|
||
<node name='merge_handler' pkg='coms' type='merge_handler.py' output="screen"> | ||
<param name="robot_name" value="$(arg robot_name)"/> | ||
<param name="map_service" value="$(arg map_service)"/> | ||
</node> | ||
|
||
<node name='gmapping_merger' pkg='coms' type='gmapping_merger.py' output="screen"> | ||
<param name="robot_name" value="$(arg robot_name)"/> | ||
<param name="map_service" value="$(arg map_service)"/> | ||
</node> | ||
|
||
<node name='test_amcl' pkg='coms' type='test_amcl.py' output="screen"> | ||
<param name="robot_name" value="$(arg robot_name)"/> | ||
</node> | ||
|
||
<node name='test_gmapping' pkg='coms' type='test_gmapping.py' output="screen"> | ||
<param name="robot_name" value="$(arg robot_name)"/> | ||
<param name="map_service" value="$(arg map_service)"/> | ||
</node> | ||
</launch> |
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,18 @@ | ||
<launch> | ||
<arg name='robot_name' default='test_bot' /> | ||
<arg name='map_service' default='dynamic_map'/> | ||
|
||
<node name='mapmerger' pkg='coms' type='mapmerger.py' output="screen"> | ||
<param name="robot_name" value="$(arg robot_name)"/> | ||
<param name="map_service" value="$(arg map_service)"/> | ||
</node> | ||
|
||
<node name='test_amcl' pkg='coms' type='test_amcl.py' output="screen"> | ||
<param name="robot_name" value="$(arg robot_name)"/> | ||
</node> | ||
|
||
<node name='test_gmapping' pkg='coms' type='test_gmapping.py' output="screen"> | ||
<param name="robot_name" value="$(arg robot_name)"/> | ||
<param name="map_service" value="$(arg map_service)"/> | ||
</node> | ||
</launch> |
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
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,5 @@ | ||
from mapmerge.constants import * | ||
from mapmerge.keypoint_merge import * | ||
from mapmerge.merge_utils import * | ||
from mapmerge.ros_utils import * | ||
from mapmerge.hough_merge import * |
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
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
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,78 @@ | ||
#!/usr/bin/env python3 | ||
from merger import ROSMerger | ||
from std_msgs.msg import Header | ||
from nav_msgs.srv import GetMap, GetMapResponse | ||
from nav_msgs.msg import OccupancyGrid, MapMetaData | ||
from coms.srv import MergeMap | ||
import numpy as np | ||
import rospy | ||
|
||
|
||
class GmappingMerger(ROSMerger): | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
self.robot_name = rospy.get_param('robot_name', 'tb0') | ||
self.request_service = f'{self.robot_name}/merge' | ||
self.map_service = rospy.get_param('map_service', 'dynamic_map') | ||
|
||
self.latest_map = np.array([]) | ||
|
||
rospy.init_node(f"{self.robot_name}_GmappingMerger") | ||
self.rate = rospy.Rate(10) # 10hz | ||
|
||
def run(self) -> None: | ||
rospy.loginfo(f'{self.robot_name} gmapping merger node starting') | ||
|
||
while not rospy.is_shutdown(): | ||
resp = self.get_latest() | ||
if self.check_new(resp): | ||
self.request_merge(resp) | ||
self.rate.sleep() | ||
|
||
rospy.loginfo(f'{self.robot_name} gmapping merger node shutting down') | ||
|
||
def request_merge(self, new_map: OccupancyGrid) -> bool: | ||
""" | ||
Requests a merge from the specified ros service {request_service}. | ||
""" | ||
rospy.wait_for_service(self.request_service) | ||
attempts = 0 | ||
max_attemps = 10 | ||
try: | ||
req = new_map.map | ||
request_service = rospy.ServiceProxy(self.request_service, MergeMap) | ||
return request_service(req) | ||
except rospy.ServiceException as e: | ||
attempts += 1 | ||
rospy.loginfo("service call failed: %s" % e) | ||
if attempts >= max_attemps: | ||
return False | ||
return False | ||
|
||
def get_latest(self): | ||
""" | ||
gets the latest map from map service | ||
""" | ||
rospy.wait_for_service(self.map_service) | ||
while 1: | ||
try: | ||
map_service = rospy.ServiceProxy(self.map_service, GetMap) | ||
return map_service() | ||
except rospy.ServiceException as e: | ||
rospy.loginfo("service call failed: %s" % e) | ||
self.rate.sleep() | ||
|
||
def check_new(self, new_map: OccupancyGrid) -> bool: | ||
if not self.latest_map.any(): | ||
# if we don't have a latest map | ||
return True | ||
|
||
temp = np.array(new_map.data) | ||
# return True if maps don't match, continue to merge req | ||
return not np.all(self.latest_map, temp) | ||
|
||
|
||
if __name__ == '__main__': | ||
GM = GmappingMerger() | ||
GM.run() |
Oops, something went wrong.