Skip to content

Commit 59664f7

Browse files
committed
Merge branch 'new_analyzed_points_publisher' into test_scripts
2 parents d2e7664 + c227c00 commit 59664f7

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

dynamic_payload_analysis_core/dynamic_payload_analysis_core/core.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,17 @@ def compute_all_configurations(self, range : int, resolution : int, end_joint_id
423423

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

427430
# Iterate over the range to compute all configurations
428431
for x in np.arange(-range, range , resolution):
429432
for y in np.arange(-range, range , resolution):
430433
for z in np.arange(-range/2, range , resolution):
434+
435+
self.analyzed_points = np.append(self.analyzed_points, {"position" : [x, y, z]})
436+
431437
target_position = pin.SE3(np.eye(3), np.array([x, y, z]))
432438
new_q = self.compute_inverse_kinematics(q, target_position, end_joint_id)
433439

@@ -887,6 +893,15 @@ def get_zero_acceleration(self) -> np.ndarray:
887893
return a0
888894

889895

896+
def get_analyzed_points(self) -> np.ndarray:
897+
"""
898+
Get the analyzed points during the computation of all configurations.
899+
900+
:return: Array of analyzed points.
901+
"""
902+
903+
return self.analyzed_points
904+
890905
def get_random_configuration(self) -> tuple[np.ndarray, np.ndarray]:
891906
"""
892907
Get a random configuration for configuration and velocity vectors.

dynamic_payload_analysis_ros/dynamic_payload_analysis_ros/rviz_visualization_menu.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def __init__(self):
6868
# Pusblisher for point cloud of maximum payloads in the workspace area
6969
self.publisher_maximum_payloads = self.create_publisher(MarkerArray, '/maximum_payloads', 10)
7070

71+
# Publisher for point cloud of all analyzed points
72+
self.publisher_analyzed_points = self.create_publisher(MarkerArray, '/analyzed_points', 10)
73+
7174
# subscription to joint states
7275
self.joint_states_subscription = self.create_subscription(JointState, '/joint_states', self.joint_states_callback, 10)
7376

@@ -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
@@ -113,6 +119,8 @@ def __init__(self):
113119
self.timer_publish_force = self.create_timer(1.0, self.publish_payload_force)
114120
# timer to update items in the menu for payload selection
115121
self.timer_update_payload_selection = self.create_timer(0.5, self.update_payload_selection)
122+
# timer to publish all analyzed points in the workspace area
123+
self.timer_publish_analyzed_points = self.create_timer(2, self.publish_analyzed_points)
116124

117125
self.get_logger().info('Robot description subscriber node started')
118126

@@ -161,6 +169,53 @@ def update_payload_selection(self):
161169

162170
self.links = links # Update the links to the current ones
163171

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

0 commit comments

Comments
 (0)