Skip to content

Commit 5a289ba

Browse files
authored
Merge pull request #14 from pal-robotics/new_analyzed_points_publisher
added publisher for analyzed points
2 parents 0aa42bd + 433aba4 commit 5a289ba

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

dynamic_payload_analysis_core/dynamic_payload_analysis_core/core.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def __init__(self, robot_description : Union[str, Path]):
6969
# compute main trees of the robot model
7070
self.compute_subtrees()
7171

72-
72+
# array to store all analyzed points
73+
self.analyzed_points = np.array([], dtype=object)
7374

7475
# array to store all configurations for the robot model
7576
self.configurations = np.array([], dtype=object)
@@ -422,11 +423,17 @@ def compute_all_configurations(self, range : int, resolution : int, end_joint_id
422423

423424
# Create an array to store all configurations
424425
configurations = []
426+
427+
# restore analyzed points array
428+
self.analyzed_points = np.array([], dtype=object)
425429

426430
# Iterate over the range to compute all configurations
427431
for x in np.arange(-range, range , resolution):
428432
for y in np.arange(-range, range , resolution):
429433
for z in np.arange(-range/2, range , resolution):
434+
435+
self.analyzed_points = np.append(self.analyzed_points, {"position" : [x, y, z]})
436+
430437
target_position = pin.SE3(np.eye(3), np.array([x, y, z]))
431438
new_q = self.compute_inverse_kinematics(q, target_position, end_joint_id)
432439

@@ -873,6 +880,15 @@ def get_zero_acceleration(self) -> np.ndarray:
873880
return a0
874881

875882

883+
def get_analyzed_points(self) -> np.ndarray:
884+
"""
885+
Get the analyzed points during the computation of all configurations.
886+
887+
:return: Array of analyzed points.
888+
"""
889+
890+
return self.analyzed_points
891+
876892
def get_random_configuration(self) -> tuple[np.ndarray, np.ndarray]:
877893
"""
878894
Get a random configuration for configuration and velocity vectors.

dynamic_payload_analysis_ros/dynamic_payload_analysis_ros/rviz_visualization_menu.py

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ def __init__(self):
6363
self.publisher_rviz_torque = self.create_publisher(MarkerArray, '/torque_visualization', 10)
6464

6565
# Pusblisher for point cloud workspace area
66-
self.publisher_workspace_area = self.create_publisher(MarkerArray, '/workspace_area', 10)
66+
self.publisher_workspace_area = self.create_publisher(MarkerArray, '/workspace_area', qos_profile=rclpy.qos.QoSProfile( durability=rclpy.qos.DurabilityPolicy.TRANSIENT_LOCAL, depth = 1))
6767

6868
# Pusblisher for point cloud of maximum payloads in the workspace area
69-
self.publisher_maximum_payloads = self.create_publisher(MarkerArray, '/maximum_payloads', 10)
69+
self.publisher_maximum_payloads = self.create_publisher(MarkerArray, '/maximum_payloads', qos_profile=rclpy.qos.QoSProfile( durability=rclpy.qos.DurabilityPolicy.TRANSIENT_LOCAL, depth = 1))
70+
71+
# Publisher for point cloud of all analyzed points
72+
self.publisher_analyzed_points = self.create_publisher(MarkerArray, '/analyzed_points', qos_profile=rclpy.qos.QoSProfile( durability=rclpy.qos.DurabilityPolicy.TRANSIENT_LOCAL, depth = 1))
7073

7174
# subscription to joint states
7275
self.joint_states_subscription = self.create_subscription(JointState, '/joint_states', self.joint_states_callback, 10)
@@ -103,6 +106,9 @@ def __init__(self):
103106
# variable to store if there is a selected configuration from the workspace menu to visualize
104107
self.selected_configuration = None
105108

109+
# variable to store analyzed points of the workspace area
110+
self.marker_analyzed_points = None
111+
106112
# timer to compute the valid workspace area
107113
self.timer_workspace_calculation = self.create_timer(1.0, self.workspace_calculation)
108114
# timer to publish the selected configuration in joint states
@@ -161,6 +167,53 @@ def update_payload_selection(self):
161167

162168
self.links = links # Update the links to the current ones
163169

170+
171+
def publisher_analyzed_point_markers(self):
172+
"""
173+
Publish the analyzed points in the workspace area.
174+
This will publish all the points in the workspace area where the robot can reach with the current configuration.
175+
"""
176+
if self.menu is not None:
177+
178+
if len(self.robot_handler.get_analyzed_points()) == 0:
179+
return
180+
else:
181+
if self.marker_analyzed_points is None:
182+
183+
self.marker_analyzed_points = MarkerArray()
184+
185+
# publish the analyzed points
186+
for i, analyzed_point in enumerate(self.robot_handler.get_analyzed_points()):
187+
point = Marker()
188+
point.header.frame_id = self.robot_handler.get_root_name()
189+
point.header.stamp = Time()
190+
point.ns = f"analyzed_points_ns"
191+
point.id = i
192+
point.type = Marker.SPHERE
193+
point.action = Marker.ADD
194+
point.scale.x = 0.01
195+
point.scale.y = 0.01
196+
point.scale.z = 0.01
197+
point.pose.position.x = analyzed_point['position'][0]
198+
point.pose.position.y = analyzed_point['position'][1]
199+
point.pose.position.z = analyzed_point['position'][2]
200+
point.pose.orientation.w = 1.0
201+
point.color.a = 1.0 # Alpha
202+
point.color.r = 1.0 # Red
203+
point.color.g = 1.0 # Green
204+
point.color.b = 1.0 # Blue
205+
206+
self.marker_analyzed_points.markers.append(point)
207+
208+
self.publisher_analyzed_points.publish(self.marker_analyzed_points)
209+
210+
else:
211+
# update with current time
212+
for marker in self.marker_analyzed_points.markers:
213+
marker.header.stamp = Time()
214+
215+
self.publisher_analyzed_points.publish(self.marker_analyzed_points)
216+
164217
def publish_payload_force(self):
165218
"""
166219
Publish the gravity force on the frame with id `id_force`.
@@ -227,6 +280,9 @@ def workspace_calculation(self):
227280

228281
# compute the maximum payloads for the valid configurations
229282
self.valid_configurations = self.robot_handler.compute_maximum_payloads(self.valid_configurations)
283+
284+
# publish the analyzed points in the workspace area
285+
self.publisher_analyzed_point_markers()
230286

231287
# insert the valid configurations in the menu
232288
self.menu.insert_dropdown_configuration(self.valid_configurations)

0 commit comments

Comments
 (0)