Skip to content

Commit 00402b8

Browse files
authored
(states) Extend API of GetMap(AndShow) (#1304)
2 parents bcd09a3 + 4312cc8 commit 00402b8

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

robot_smach_states/src/robot_smach_states/world_model/get_show_map.py

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@
1111

1212

1313
class GetMap(smach.State):
14-
def __init__(self, robot, filename_des, entity_ids=None, mark_ids=None, plan_points=None):
14+
def __init__(
15+
self,
16+
robot,
17+
filename_des,
18+
entity_ids=None,
19+
mark_ids=None,
20+
plan_points=None,
21+
background: str = "white",
22+
print_labels: bool = True,
23+
width: int = 0,
24+
height: int = 0,
25+
):
1526
super().__init__(outcomes=["created", "failed"])
1627
self.robot = robot
1728

@@ -26,12 +37,27 @@ def __init__(self, robot, filename_des, entity_ids=None, mark_ids=None, plan_poi
2637
check_type(plan_points, Vector, type(None))
2738
self.plan_points = plan_points
2839

40+
check_type(background, str)
41+
self.background = background
42+
check_type(print_labels, bool)
43+
self.print_labels = print_labels
44+
check_type(width, int)
45+
self.width = width
46+
check_type(height, int)
47+
self.height = height
48+
2949
def execute(self, ud=None):
3050
entity_ids = self.entity_ids.resolve() if hasattr(self.entity_ids, "resolve") else self.entity_ids
51+
background = self.background.resolve() if hasattr(self.background, "resolve") else self.background
52+
print_labels = self.print_labels.resolve() if hasattr(self.print_labels, "resolve") else self.print_labels
53+
width = self.width.resolve() if hasattr(self.width, "resolve") else self.width
54+
height = self.height.resolve() if hasattr(self.height, "resolve") else self.height
3155
if entity_ids is None:
3256
entity_ids = []
3357
for _ in range(3):
34-
floor_plan = self.robot.ed.get_map(entity_ids)
58+
floor_plan = self.robot.ed.get_map(
59+
entity_ids, background=background, print_labels=print_labels, width=width, height=height
60+
)
3561
if floor_plan is not None:
3662
break
3763
else:
@@ -58,7 +84,6 @@ def execute(self, ud=None):
5884

5985
if plan_points is not None:
6086
for point in plan_points:
61-
6287
vs_image_frame = floor_plan.map_pose.frame.Inverse() * point
6388

6489
px = int(vs_image_frame.x() * floor_plan.pixels_per_meter_width)
@@ -78,15 +103,36 @@ def execute(self, ud=None):
78103

79104

80105
class GetMapAndShow(smach.StateMachine):
81-
def __init__(self, robot, entity_ids=None, mark_ids=None, plan_points=None, duration=30):
106+
def __init__(
107+
self,
108+
robot,
109+
entity_ids=None,
110+
mark_ids=None,
111+
plan_points=None,
112+
background: str = "white",
113+
print_labels: bool = True,
114+
width: int = 0,
115+
height: int = 0,
116+
duration=30,
117+
):
82118
super().__init__(outcomes=["done", "failed"])
83119

84-
filename_des = VariableDesignator(resolve_type=str).writeable
120+
filename_des = VariableDesignator(resolve_type=str)
85121

86122
with self:
87123
smach.StateMachine.add(
88124
"GET_MAP",
89-
GetMap(robot, filename_des, entity_ids, mark_ids, plan_points),
125+
GetMap(
126+
robot,
127+
filename_des.writeable,
128+
entity_ids,
129+
mark_ids,
130+
plan_points,
131+
background,
132+
print_labels,
133+
width,
134+
height,
135+
),
90136
transitions={"created": "SHOW_MAP", "failed": "failed"},
91137
)
92138

0 commit comments

Comments
 (0)