1
import roslib;roslib.load_manifest('mrol_ros')
4
import tf.transformations
5
import rosutils_mrol.rosutils_mrol as rosutils
13
import mrol_mapping.log as log
16
from thread import allocate_lock
17
from threading import Thread
19
TRAJECTORY = "/trajectory"
23
logger = log.getLogger('visualiser.rviz')
24
logger.setLevel(logging.DEBUG)
28
def __init__(self, npts=100000, Rotate=False, title=''):
29
self.point_cloud = None
30
self.point_cloud_lock = allocate_lock()
32
self.trajectory_point = tf.transformations.identity_matrix()
33
self.trajectory_point_lock = allocate_lock()
35
inthandler = signal.getsignal(signal.SIGINT)
36
# overrides signal handler
37
rospy.init_node('visualiser', anonymous=True)
38
def newhandler(signum, frame):
40
signal.signal(signal.SIGINT, newhandler)
41
t = Thread(target=self._publisher_thread)
42
t.daemon = True # die when no other non-daemon thread is around
44
t = Thread(target=self._transform_thread)
45
t.daemon = True # die when no other non-daemon thread is around
48
def _transform_thread(self):
49
br = tf.TransformBroadcaster()
50
logger.debug("****** Started transform thread *****")
52
while not rospy.is_shutdown():
53
with self.trajectory_point_lock:
54
if self.trajectory_point is None:
57
with self.trajectory_point_lock:
58
translation = tuple(self.trajectory_point[:3, 3])
59
quat = tf.transformations.quaternion_from_matrix(
60
self.trajectory_point)
61
br.sendTransform(translation,
70
def _publisher_thread(self):
71
pub = rospy.Publisher(MROL_TOPIC, sensor_msgs.msg.PointCloud2)
72
logger.debug("Started publishing thread")
73
rate = rospy.Rate(1.0)
75
while not rospy.is_shutdown():
76
with self.point_cloud_lock:
77
if self.point_cloud is not None:
78
pub.publish(self.point_cloud)
83
def addmappts(self, xyzs, colour=None):
85
with self.point_cloud_lock:
86
self.point_cloud = rosutils.xyzs2pc2(
87
xyzs, rospy.Time.now(), self.seq, frame_id=GLOBAL_FRAME)
88
self.seq = self.seq + 1
90
def setrobotpose(self, transform_mat):
91
"""Display robot position with given pose"""
92
with self.trajectory_point_lock:
93
self.trajectory_point[:3, :3] = transform_mat[:3, :3]
95
def addtrajectorypoint(self, xyz):
96
"""Display robot position at given coordinate"""
98
with self.trajectory_point_lock:
99
self.trajectory_point[:3, 3] = np.array(xyz)
101
def getkeypress(self):
104
def setminmax(self, colourmin, colourmax):
107
def setautominmax(self, Bool=True):
110
def set_orthographic(self, Bool=False):
113
def setleftpts(self, xyzs, M=None):
116
def setrightpts(self, xyzs, M=None):
119
def setspinpts(self, xyzs, M=None):
125
def setinfostr(self, labeltext):