1 from ..
import pinocchio_pywrap
as pin
2 from ..utils
import npToTuple
4 from .
import BaseVisualizer
10 WITH_HPP_FCL_BINDINGS =
True 12 WITH_HPP_FCL_BINDINGS =
False 15 """ Make capsule using two sphere and one cylinder""" 16 from copy
import deepcopy
17 from visualization_msgs.msg
import Marker
18 from geometry_msgs.msg
import Point
19 displacment = pin.SE3.Identity()
21 displacment.translation[2] = l/2.
22 oMsphere_1 = oMg * displacment
23 displacment.translation[2] = -l/2.
24 oMsphere_2 = oMg * displacment
26 marker_cylinder = marker_ref
27 marker_cylinder.type = Marker.CYLINDER
28 marker_cylinder.scale = Point(d,d,l)
31 marker_sphere_1 = deepcopy(marker_ref)
32 marker_sphere_1.id += 10000
33 marker_sphere_1.type = Marker.SPHERE
34 marker_sphere_1.scale = Point(d,d,d)
37 marker_sphere_2 = deepcopy(marker_ref)
38 marker_sphere_2.id += 20000
39 marker_sphere_2.type = Marker.SPHERE
40 marker_sphere_2.scale = Point(d,d,d)
43 return [marker_cylinder, marker_sphere_1, marker_sphere_2]
46 """Converts SE3 matrix to ROS geometry_msgs/Pose format""" 47 from geometry_msgs.msg
import Pose, Point, Quaternion
49 xyz_quat = pin.SE3ToXYZQUATtuple(oMg)
50 return Pose(position=Point(*xyz_quat[:3]), orientation=Quaternion(*xyz_quat[3:]))
53 """A Pinocchio display using RViz""" 59 def initViewer(self, viewer=None, windowName="python-pinocchio", loadModel=False, initRosNode=True):
60 """Init RVizViewer by starting a ros node (or not) and creating an RViz window.""" 61 from rospy
import init_node, WARN
62 from rosgraph
import is_master_online
63 from rviz
import bindings
as rviz
64 from python_qt_binding.QtWidgets
import QApplication
66 if not is_master_online():
68 warnings.warn(
"Error while importing the viz client.\n" 69 "Check whether ROS master (roscore) is properly started",
70 category=UserWarning, stacklevel=2)
74 init_node(
'pinocchio_viewer', anonymous=
True, log_level=WARN)
78 self.
viewer.app = QApplication([])
79 self.
viewer.viz= rviz.VisualizationFrame()
80 self.
viewer.viz.setSplashPath(
"" )
81 self.
viewer.viz.initialize()
82 self.
viewer.viz.setWindowTitle(windowName+
"[*]")
94 """Create the displays in RViz and create publishers for the MarkerArray""" 95 from rospy
import Publisher
96 from visualization_msgs.msg
import MarkerArray
99 self.
visuals_publisher = Publisher(rootNodeName+
"_visuals", MarkerArray, queue_size=1, latch=
True)
100 self.
visual_Display = self.
viewer.viz_manager.createDisplay(
"rviz/MarkerArray", rootNodeName +
"_visuals",
True)
101 self.
visual_Display.subProp(
"Marker Topic").setValue(rootNodeName +
"_visuals")
107 self.
collision_Display.subProp(
"Marker Topic").setValue(rootNodeName +
"_collisions")
111 root_group = self.
viewer.viz_manager.getRootDisplayGroup()
120 """Delete all the objects from the whole scene """ 121 if hasattr(self,
'collisions_publisher'):
125 if hasattr(self,
'visuals_publisher'):
130 """Display the robot at configuration q in the viz by placing all the bodies.""" 133 pin.forwardKinematics(self.model,self.data,q)
135 if self.collision_model
is not None and hasattr(self,
'collisions_publisher'):
136 pin.updateGeometryPlacements(self.model, self.data, self.collision_model, self.collision_data)
139 if self.visual_model
is not None and hasattr(self,
'visuals_publisher'):
140 pin.updateGeometryPlacements(self.model, self.data, self.visual_model, self.visual_data)
143 def _plot(self, publisher, model, data, previous_ids=()):
144 """Create markers for each object of the model and publish it as MarkerArray (also delete unused previously created markers)""" 145 from rospy
import get_rostime
146 from std_msgs.msg
import Header, ColorRGBA
147 from geometry_msgs.msg
import Point
148 from visualization_msgs.msg
import MarkerArray, Marker
151 header = Header(frame_id=
'map', seq=self.
seq, stamp=get_rostime())
153 marker_array = MarkerArray()
154 for obj
in model.geometryObjects:
155 obj_id = model.getGeometryId(obj.name)
160 marker.header = header
161 marker.action = Marker.ADD
163 marker.color = ColorRGBA(*obj.meshColor)
165 if obj.meshTexturePath !=
"":
166 warnings.warn(
"Textures are not supported in RVizVisualizer (for " + obj.name +
")", category=UserWarning, stacklevel=2)
170 if WITH_HPP_FCL_BINDINGS
and isinstance(geom, hppfcl.ShapeBase):
172 if isinstance(geom, hppfcl.Cylinder):
173 d, l = 2*geom.radius, 2*geom.halfLength
174 marker.type = Marker.CYLINDER
175 marker.scale = Point(d,d,l)
176 marker_array.markers.append(marker)
177 elif isinstance(geom, hppfcl.Box):
179 marker.type = Marker.CUBE
180 marker.scale = Point(*size)
181 marker_array.markers.append(marker)
182 elif isinstance(geom, hppfcl.Sphere):
184 marker.type = Marker.SPHERE
185 marker.scale = Point(d, d, d)
186 marker_array.markers.append(marker)
187 elif isinstance(geom, hppfcl.Capsule):
188 d, l = 2*geom.radius, 2 * geom.halfLength
191 msg =
"Unsupported geometry type for %s (%s)" % (obj.name,
type(geom))
192 warnings.warn(msg, category=UserWarning, stacklevel=2)
196 marker.type = Marker.MESH_RESOURCE
197 marker.scale = Point(*
npToTuple(obj.meshScale))
198 marker.mesh_resource =
'file://' + obj.meshPath
199 marker_array.markers.append(marker)
202 new_ids = [marker.id
for marker
in marker_array.markers]
203 for old_id
in previous_ids:
204 if not old_id
in new_ids:
205 marker_remove = Marker()
206 marker_remove.header = header
207 marker_remove.id = old_id
208 marker_remove.action = Marker.DELETE
209 marker_array.markers.append(marker_remove)
212 publisher.publish(marker_array)
218 """Delete all the markers from a topic (use one marker with action DELETEALL)""" 219 from rospy
import get_rostime
220 from std_msgs.msg
import Header
221 from visualization_msgs.msg
import MarkerArray, Marker
228 marker.header = Header(frame_id=
'map', seq=self.
seq, stamp=get_rostime())
229 marker.action = Marker.DELETEALL
232 marker_array = MarkerArray(markers = [marker])
235 publisher.publish(marker_array)
238 """Set whether to display collision objects or not""" 242 """Set whether to display visual objects or not""" 246 from python_qt_binding.QtTest
import QTest
250 __all__ = [
'RVizVisualizer']
def _clean(self, publisher)
def displayVisuals(self, visibility)
def loadViewerModel(self, rootNodeName="pinocchio")
def displayCollisions(self, visibility)
def display(self, q=None)
def create_capsule_markers(marker_ref, oMg, d, l)
def _plot(self, publisher, model, data, previous_ids=())
def initViewer(self, viewer=None, windowName="python-pinocchio", loadModel=False, initRosNode=True)