5 from ..
import pinocchio_pywrap_default
as pin
6 from ..utils
import npToTuple
7 from .
import BaseVisualizer
12 WITH_HPP_FCL_BINDINGS =
True
14 WITH_HPP_FCL_BINDINGS =
False
18 """Make capsule using two sphere and one cylinder"""
19 from copy
import deepcopy
21 from geometry_msgs.msg
import Point
22 from visualization_msgs.msg
import Marker
24 displacment = pin.SE3.Identity()
26 displacment.translation[2] = fl / 2.0
27 oMsphere_1 = oMg * displacment
28 displacment.translation[2] = -fl / 2.0
29 oMsphere_2 = oMg * displacment
31 marker_cylinder = marker_ref
32 marker_cylinder.type = Marker.CYLINDER
33 marker_cylinder.scale = Point(d, d, fl)
36 marker_sphere_1 = deepcopy(marker_ref)
37 marker_sphere_1.id += 10000
38 marker_sphere_1.type = Marker.SPHERE
39 marker_sphere_1.scale = Point(d, d, d)
42 marker_sphere_2 = deepcopy(marker_ref)
43 marker_sphere_2.id += 20000
44 marker_sphere_2.type = Marker.SPHERE
45 marker_sphere_2.scale = Point(d, d, d)
48 return [marker_cylinder, marker_sphere_1, marker_sphere_2]
52 """Converts SE3 matrix to ROS geometry_msgs/Pose format"""
53 from geometry_msgs.msg
import Point, Pose, Quaternion
55 xyz_quat = pin.SE3ToXYZQUATtuple(oMg)
56 return Pose(position=Point(*xyz_quat[:3]), orientation=
Quaternion(*xyz_quat[3:]))
60 """A Pinocchio display using RViz"""
70 windowName="python-pinocchio",
75 Init RVizViewer by starting a ros node (or not) and creating an RViz window.
77 from python_qt_binding.QtWidgets
import QApplication
78 from rosgraph
import is_master_online
79 from rospy
import WARN, init_node
80 from rviz
import bindings
as rviz
82 if not is_master_online():
85 "Error while importing the viz client.\n"
86 "Check whether ROS master (roscore) is properly started",
93 init_node(
"pinocchio_viewer", anonymous=
True, log_level=WARN)
97 self.
viewer.app = QApplication([])
98 self.
viewer.viz = rviz.VisualizationFrame()
99 self.
viewer.viz.setSplashPath(
"")
100 self.
viewer.viz.initialize()
101 self.
viewer.viz.setWindowTitle(windowName +
"[*]")
113 """Create the displays in RViz and create publishers for the MarkerArray"""
114 from rospy
import Publisher
115 from visualization_msgs.msg
import MarkerArray
119 rootNodeName +
"_visuals", MarkerArray, queue_size=1, latch=
True
122 "rviz/MarkerArray", rootNodeName +
"_visuals",
True
124 self.
visual_Display.subProp(
"Marker Topic").setValue(rootNodeName +
"_visuals")
129 rootNodeName +
"_collisions", MarkerArray, queue_size=1, latch=
True
132 "rviz/MarkerArray", rootNodeName +
"_collisions",
True
135 rootNodeName +
"_collisions"
140 root_group = self.
viewer.viz_manager.getRootDisplayGroup()
142 "rviz/Group", rootNodeName,
True
155 """Delete all the objects from the whole scene"""
156 if hasattr(self,
"collisions_publisher"):
160 if hasattr(self,
"visuals_publisher"):
165 """Display the robot at configuration q in the viz by placing all the bodies."""
168 pin.forwardKinematics(self.model, self.data, q)
170 if self.collision_model
is not None and hasattr(self,
"collisions_publisher"):
171 pin.updateGeometryPlacements(
172 self.model, self.data, self.collision_model, self.collision_data
176 self.collision_model,
181 if self.visual_model
is not None and hasattr(self,
"visuals_publisher"):
182 pin.updateGeometryPlacements(
183 self.model, self.data, self.visual_model, self.visual_data
192 def _plot(self, publisher, model, data, previous_ids=()):
194 Create markers for each object of the model and publish it as MarkerArray
195 (also delete unused previously created markers)
197 from geometry_msgs.msg
import Point
198 from rospy
import get_rostime
199 from std_msgs.msg
import ColorRGBA, Header
200 from visualization_msgs.msg
import Marker, MarkerArray
204 frame_id=
"map", seq=self.
seq, stamp=get_rostime()
207 marker_array = MarkerArray()
208 for obj
in model.geometryObjects:
209 obj_id = model.getGeometryId(obj.name)
214 marker.header = header
215 marker.action = Marker.ADD
217 marker.color = ColorRGBA(*obj.meshColor)
219 if obj.meshTexturePath !=
"":
221 "Textures are not supported in RVizVisualizer (for "
224 category=UserWarning,
230 if WITH_HPP_FCL_BINDINGS
and isinstance(geom, hppfcl.ShapeBase):
232 if isinstance(geom, hppfcl.Cylinder):
233 d, fl = 2 * geom.radius, 2 * geom.halfLength
234 marker.type = Marker.CYLINDER
235 marker.scale = Point(d, d, fl)
236 marker_array.markers.append(marker)
237 elif isinstance(geom, hppfcl.Box):
239 marker.type = Marker.CUBE
240 marker.scale = Point(*size)
241 marker_array.markers.append(marker)
242 elif isinstance(geom, hppfcl.Sphere):
244 marker.type = Marker.SPHERE
245 marker.scale = Point(d, d, d)
246 marker_array.markers.append(marker)
247 elif isinstance(geom, hppfcl.Capsule):
248 d, fl = 2 * geom.radius, 2 * geom.halfLength
249 marker_array.markers.extend(
253 msg = f
"Unsupported geometry type for {obj.name} ({type(geom)})"
254 warnings.warn(msg, category=UserWarning, stacklevel=2)
258 marker.type = Marker.MESH_RESOURCE
259 marker.scale = Point(*
npToTuple(obj.meshScale))
260 marker.mesh_resource =
"file://" + obj.meshPath
261 marker_array.markers.append(marker)
264 new_ids = [marker.id
for marker
in marker_array.markers]
265 for old_id
in previous_ids:
266 if old_id
not in new_ids:
267 marker_remove = Marker()
268 marker_remove.header = header
269 marker_remove.id = old_id
270 marker_remove.action = Marker.DELETE
271 marker_array.markers.append(marker_remove)
274 publisher.publish(marker_array)
280 """Delete all the markers from a topic (use one marker with action DELETEALL)"""
281 from rospy
import get_rostime
282 from std_msgs.msg
import Header
283 from visualization_msgs.msg
import Marker, MarkerArray
290 marker.header = Header(frame_id=
"map", seq=self.
seq, stamp=get_rostime())
291 marker.action = Marker.DELETEALL
294 marker_array = MarkerArray(markers=[marker])
297 publisher.publish(marker_array)
300 """Set whether to display collision objects or not"""
304 """Set whether to display visual objects or not"""
308 from python_qt_binding.QtTest
import QTest
310 QTest.qWait(1e3 * dt)
313 raise NotImplementedError()
316 raise NotImplementedError()
319 raise NotImplementedError()
322 raise NotImplementedError()
325 raise NotImplementedError()
328 raise NotImplementedError()
331 raise NotImplementedError()
334 raise NotImplementedError()
337 raise NotImplementedError()
340 __all__ = [
"RVizVisualizer"]