Skip to content

Commit 386c76f

Browse files
committed
Bug fix after addressing comments
1 parent af06d6b commit 386c76f

File tree

4 files changed

+84
-10
lines changed

4 files changed

+84
-10
lines changed

spot_tools/src/spot_skills/navigation_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,12 @@ def follow_trajectory_continuous(
160160
# if mid_level_planner is not None:
161161
# update path every (couple?) loop
162162
mlp_success, planning_output = mid_level_planner.plan_path(waypoints_list[:, :2])
163-
path = planning_output['path_shapely']
164-
path_wp = planning_output['path_waypoints_metric']
165-
target_point_metric = planning_output['target_point_metric']
166-
163+
path = planning_output.path_shapely
164+
path_wp = planning_output.path_waypoints_metric
165+
target_point_metric = planning_output.target_point_metric
166+
167167
if feedback is not None and target_point_metric is not None:
168+
feedback.print("INFO", f"target_point_metric: {target_point_metric}")
168169
feedback.path_follow_MLP_feedback(path_wp, target_point_metric)
169170

170171
if not mlp_success:

spot_tools_ros/src/spot_tools_ros/fake_path_publisher.py

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,76 @@ def __init__(self, goal_x, goal_y, map_frame, robot_name, follow_robot=False, pu
5252
self.timer = self.create_timer(1.0, self.publish_once)
5353
self.get_logger().info(f"Publishing path to goal ({goal_x}, {goal_y}) once")
5454

55+
def to_viz_msg_follow(self, action, marker_ns):
56+
points = []
57+
for p in action.path.poses:
58+
pt = Point()
59+
pt.x = p.pose.position.x
60+
pt.y = p.pose.position.y
61+
pt.z = p.pose.position.z
62+
points.append(pt)
63+
m = Marker()
64+
m.header.frame_id = self.map_frame
65+
m.header.stamp = gtm()
66+
m.ns = marker_ns
67+
m.id = 0
68+
m.type = m.LINE_STRIP
69+
m.action = m.ADD
70+
m.pose.orientation.w = 1.0
71+
m.scale.x = 0.2
72+
m.scale.y = 0.2
73+
m.color.a = 1.0
74+
m.color.r = 0.0
75+
m.color.g = 1.0
76+
m.color.b = 0.0
77+
m.points = points
78+
79+
start = Marker()
80+
start.header.frame_id = self.map_frame
81+
start.header.stamp = gtm()
82+
start.ns = marker_ns
83+
start.id = 1
84+
start.type = m.SPHERE
85+
start.action = m.ADD
86+
start.pose.orientation.w = 1.0
87+
start.scale.x = 0.4
88+
start.scale.y = 0.4
89+
start.scale.z = 0.4
90+
start.color.a = 0.5
91+
start.color.r = 1.0
92+
start.color.g = 0.0
93+
start.color.b = 0.0
94+
start.pose.position.x = points[0].x
95+
start.pose.position.y = points[0].y
96+
start.pose.position.z = points[0].z
97+
98+
end = Marker()
99+
end.header.frame_id = self.map_frame
100+
end.header.stamp = gtm()
101+
end.ns = marker_ns
102+
end.id = 2
103+
end.type = m.SPHERE
104+
end.action = m.ADD
105+
end.pose.orientation.w = 1.0
106+
end.scale.x = 0.4
107+
end.scale.y = 0.4
108+
end.scale.z = 0.4
109+
end.color.a = 0.5
110+
end.color.r = 0.0
111+
end.color.g = 0.0
112+
end.color.b = 1.0
113+
end.pose.position.x = points[-1].x
114+
end.pose.position.y = points[-1].y
115+
end.pose.position.z = points[-1].z
116+
117+
return [m, start, end]
118+
119+
120+
def to_viz_msg(self, action, marker_ns):
121+
ma = MarkerArray()
122+
for ix, a in enumerate(action.actions):
123+
ma.markers += self.to_viz_msg_follow(a, marker_ns + f"/{ix}")
124+
return ma
55125

56126

57127
def generate_waypoints(self, start_x, start_y, start_yaw, num_waypoints=10):
@@ -71,7 +141,7 @@ def publish_path(self):
71141
"""Publish path from current robot pose to goal"""
72142
try:
73143
# Get current robot pose
74-
robot_pose, robot_yaw = get_tf_pose(self.tf_buffer, self.map_frame, self.robot_frame)
144+
robot_pose, (roll, pitch, robot_yaw) = get_tf_pose(self.tf_buffer, self.map_frame, self.robot_frame, get_euler=True)
75145

76146
# Generate waypoints
77147
if self.follow_robot:
@@ -117,7 +187,8 @@ def publish_path(self):
117187
msg.actions.append(action_msg)
118188

119189
self.publisher.publish(msg)
120-
self.viz_publisher.publish(to_viz_msg(msg, self.robot_name))
190+
# self.viz_publisher.publish(to_viz_msg(msg, self.robot_name)) # somehow throw an error about the msg type, it has a '_' before the actual msg name
191+
self.viz_publisher.publish(self.to_viz_msg(msg, self.robot_name))
121192
self.get_logger().info(f"Published path with {len(waypoints)} waypoints")
122193

123194
except Exception as e:
@@ -162,4 +233,4 @@ def main():
162233

163234

164235
if __name__ == "__main__":
165-
main()
236+
main()

spot_tools_ros/src/spot_tools_ros/spot_executor_ros.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from spot_skills.detection_utils import YOLODetector
3030
from std_msgs.msg import Bool, String
3131
from visualization_msgs.msg import Marker, MarkerArray
32-
32+
from shapely.geometry import Point
3333

3434
from spot_tools_ros.fake_spot_ros import FakeSpotRos
3535
from spot_tools_ros.occupancy_grid_ros_updater import OccupancyGridROSUpdater
@@ -149,7 +149,7 @@ def path_following_progress_feedback(self, progress_point, target_point):
149149

150150
def path_follow_MLP_feedback(self, path, target_point_metric):
151151
self.mlp_path_publisher.publish(waypoints_to_path(self.odom_frame, path)) # TODO: parameterize frame name
152-
target_point_metric_flattened = [p[0] for p in target_point_metric]
152+
target_point_metric_flattened = Point([p[0] for p in target_point_metric[:3]])
153153

154154
pts = [target_point_metric_flattened]
155155
namespaces = ["projected target point"]

spot_tools_ros/src/spot_tools_ros/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def pose_to_homo(pose, quat):
6868
return homo_mat
6969

7070

71-
def get_tf_pose(tf_buffer, parent_frame: str, child_frame: str):
71+
def get_tf_pose(tf_buffer, parent_frame: str, child_frame: str, get_euler=False):
7272
"""
7373
Looks up the transform from parent_frame to child_frame and returns [x, y, z, yaw].
7474
@@ -91,6 +91,8 @@ def get_tf_pose(tf_buffer, parent_frame: str, child_frame: str):
9191
quat = [rotation.x, rotation.y, rotation.z, rotation.w]
9292
roll, pitch, yaw = tf_transformations.euler_from_quaternion(quat)
9393

94+
if get_euler:
95+
return np.array([translation.x, translation.y, translation.z]), (roll, pitch, yaw)
9496
return np.array([translation.x, translation.y, translation.z]), rotation
9597

9698
except tf2_ros.TransformException as e:

0 commit comments

Comments
 (0)