ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
This is a simple code to transform scan point cloud to base link. Use a separate script for class laser_to_points2d:
for ease of use.
class laser_to_points2d:
def __init__(self,):
self.base_link_point2d=PointCloud()
self.base_link_point2d.header.frame_id = "base_link"
def update(self,scandata,angle_min,angle_max,angle_increment):
self.base_link_point2d.points=[]
self.base_link_point2d.channels=[]
for i in xrange(len(scandata)):
angle=angle_min+i*angle_increment
if not math.isnan(scandata[i]):
r=scandata[i]
else:r=0.0
px=float(r)*cos(angle)
py=float(r)*sin(angle)
self.base_link_point2d.points.append(Point32(px,py, 0.0))
self.base_link_point2d.channels.append(0)# add some information if needed
You need to listen to the transformation for Odom to base_link and subscribe the scan topic
def scanCb(msg):
py,px=[],[]
scandata=msg.ranges
angle_min=msg.angle_min
angle_max=msg.angle_max
angle_increment=msg.angle_increment
range_min=msg.range_min
range_max=msg.range_max
points2d.update(scandata,angle_min,angle_max,angle_increment)
if __name__ == "__main__":
rospy.init_node('main', anonymous=True) #make node
rospy.Subscriber("/scan", LaserScan, scanCb,queue_size = 1)
rate = rospy.Rate(5) # 5hz
points2d=laser_to_points2d()
listener = tf.TransformListener()
while not rospy.is_shutdown():
listener.waitForTransform("/base_link", "/odom", rospy.Time(0),rospy.Duration(1.0))
p=listener.transformPointCloud("odom",points2d.base_link_point2d)
rate.sleep()
2 | No.2 Revision |
This is a simple code to transform scan point cloud to base link. Use a separate script for class laser_to_points2d:
for ease of use.
class laser_to_points2d:
def __init__(self,):
self.base_link_point2d=PointCloud()
self.base_link_point2d.header.frame_id = "base_link"
def update(self,scandata,angle_min,angle_max,angle_increment):
self.base_link_point2d.points=[]
self.base_link_point2d.channels=[]
for i in xrange(len(scandata)):
angle=angle_min+i*angle_increment
if not math.isnan(scandata[i]):
r=scandata[i]
else:r=0.0
px=float(r)*cos(angle)
py=float(r)*sin(angle)
self.base_link_point2d.points.append(Point32(px,py, 0.0))
self.base_link_point2d.channels.append(0)# add some information if needed
You need to listen to the transformation for Odom to base_link and subscribe the scan topic
import rospy
import roslib
from sensor_msgs.msg import LaserScan
import tf
def scanCb(msg):
py,px=[],[]
scandata=msg.ranges
angle_min=msg.angle_min
angle_max=msg.angle_max
angle_increment=msg.angle_increment
range_min=msg.range_min
range_max=msg.range_max
points2d.update(scandata,angle_min,angle_max,angle_increment)
if __name__ == "__main__":
rospy.init_node('main', anonymous=True) #make node
rospy.Subscriber("/scan", LaserScan, scanCb,queue_size = 1)
rate = rospy.Rate(5) # 5hz
points2d=laser_to_points2d()
listener = tf.TransformListener()
while not rospy.is_shutdown():
listener.waitForTransform("/base_link", "/odom", rospy.Time(0),rospy.Duration(1.0))
p=listener.transformPointCloud("odom",points2d.base_link_point2d)
rate.sleep()
3 | No.3 Revision |
This is a simple code to transform scan point cloud to base link. Use a separate script for class laser_to_points2d:
for ease of use.
class laser_to_points2d:
def __init__(self,):
self.base_link_point2d=PointCloud()
self.base_link_point2d.header.frame_id = "base_link"
def update(self,scandata,angle_min,angle_max,angle_increment):
self.base_link_point2d.points=[]
self.base_link_point2d.channels=[]
for i in xrange(len(scandata)):
angle=angle_min+i*angle_increment
if not math.isnan(scandata[i]):
r=scandata[i]
else:r=0.0
px=float(r)*cos(angle)
py=float(r)*sin(angle)
self.base_link_point2d.points.append(Point32(px,py, 0.0))
self.base_link_point2d.channels.append(0)# add some information if needed
You need to listen to the transformation for Odom to base_link and subscribe the scan topic
import rospy
import roslib
from sensor_msgs.msg import LaserScan
import tf
def scanCb(msg):
py,px=[],[]
scandata=msg.ranges
angle_min=msg.angle_min
angle_max=msg.angle_max
angle_increment=msg.angle_increment
range_min=msg.range_min
range_max=msg.range_max
points2d.update(scandata,angle_min,angle_max,angle_increment)
if __name__ == "__main__":
rospy.init_node('main', anonymous=True) #make node
rospy.Subscriber("/scan", LaserScan, scanCb,queue_size = 1)
rate = rospy.Rate(5) # 5hz
points2d=laser_to_points2d()
listener = tf.TransformListener()
while not rospy.is_shutdown():
listener.waitForTransform("/base_link", "/odom", rospy.Time(0),rospy.Duration(1.0))
p=listener.transformPointCloud("odom",points2d.base_link_point2d)
rate.sleep()
4 | No.4 Revision |
This is a simple code to transform scan point cloud to base link. Use a separate script for class laser_to_points2d:
for ease of use.
from math import sin, cos, pi,tan, atan2,log
import tf
import numpy as np
from sensor_msgs.msg import PointCloud
from geometry_msgs.msg import Point32
class laser_to_points2d:
def __init__(self,):
self.base_link_point2d=PointCloud()
self.base_link_point2d.header.frame_id = "base_link"
def update(self,scandata,angle_min,angle_max,angle_increment):
self.base_link_point2d.points=[]
self.base_link_point2d.channels=[]
for i in xrange(len(scandata)):
angle=angle_min+i*angle_increment
if not math.isnan(scandata[i]):
r=scandata[i]
else:r=0.0
px=float(r)*cos(angle)
py=float(r)*sin(angle)
self.base_link_point2d.points.append(Point32(px,py, 0.0))
self.base_link_point2d.channels.append(0)# add some information if needed
You need to listen to the transformation for Odom to base_link and subscribe the scan topic
import rospy
import roslib
from sensor_msgs.msg import LaserScan
import tf
def scanCb(msg):
py,px=[],[]
scandata=msg.ranges
angle_min=msg.angle_min
angle_max=msg.angle_max
angle_increment=msg.angle_increment
range_min=msg.range_min
range_max=msg.range_max
points2d.update(scandata,angle_min,angle_max,angle_increment)
if __name__ == "__main__":
rospy.init_node('main', anonymous=True) #make node
rospy.Subscriber("/scan", LaserScan, scanCb,queue_size = 1)
rate = rospy.Rate(5) # 5hz
points2d=laser_to_points2d()
listener = tf.TransformListener()
while not rospy.is_shutdown():
listener.waitForTransform("/base_link", "/odom", rospy.Time(0),rospy.Duration(1.0))
p=listener.transformPointCloud("odom",points2d.base_link_point2d)
rate.sleep()
5 | No.5 Revision |
This is a simple code to transform scan point cloud to base link. Use a separate script for class laser_to_points2d:
for ease of use.
from math import sin, cos, pi,tan, atan2,log
import tf
import numpy as np
from sensor_msgs.msg import PointCloud
from geometry_msgs.msg import Point32
class laser_to_points2d:
def __init__(self,):
self.base_link_point2d=PointCloud()
self.base_link_point2d.header.frame_id = "base_link"
def update(self,scandata,angle_min,angle_max,angle_increment):
self.base_link_point2d.points=[]
self.base_link_point2d.channels=[]
for i in xrange(len(scandata)):
angle=angle_min+i*angle_increment
if not math.isnan(scandata[i]):
r=scandata[i]
else:r=0.0
px=float(r)*cos(angle)
py=float(r)*sin(angle)
self.base_link_point2d.points.append(Point32(px,py, 0.0))
self.base_link_point2d.channels.append(0)# add some information if needed
You need to listen to the transformation for Odom to base_link and subscribe the scan topic
import rospy
import roslib
from sensor_msgs.msg import LaserScan
import tf
def scanCb(msg):
py,px=[],[]
scandata=msg.ranges
angle_min=msg.angle_min
angle_max=msg.angle_max
angle_increment=msg.angle_increment
range_min=msg.range_min
range_max=msg.range_max
points2d.update(scandata,angle_min,angle_max,angle_increment)
if __name__ == "__main__":
rospy.init_node('main', anonymous=True) #make node
rospy.Subscriber("/scan", LaserScan, scanCb,queue_size = 1)
rate = rospy.Rate(5) # 5hz
points2d=laser_to_points2d()
listener = tf.TransformListener()
while not rospy.is_shutdown():
listener.waitForTransform("/base_link", "/odom", rospy.Time(0),rospy.Duration(1.0))
p=listener.transformPointCloud("odom",points2d.base_link_point2d)
rate.sleep()
6 | No.6 Revision |
This is a simple code to transform scan point cloud to base link. Use a separate script for class laser_to_points2d:
for ease of use.
from math import sin, cos, pi,tan, atan2,log
cos
import tf
import numpy as np
from sensor_msgs.msg import PointCloud
from geometry_msgs.msg import Point32
class laser_to_points2d:
def __init__(self,):
self.base_link_point2d=PointCloud()
self.base_link_point2d.header.frame_id = "base_link"
def update(self,scandata,angle_min,angle_max,angle_increment):
self.base_link_point2d.points=[]
self.base_link_point2d.channels=[]
for i in xrange(len(scandata)):
angle=angle_min+i*angle_increment
if not math.isnan(scandata[i]):
r=scandata[i]
else:r=0.0
px=float(r)*cos(angle)
py=float(r)*sin(angle)
self.base_link_point2d.points.append(Point32(px,py, 0.0))
self.base_link_point2d.channels.append(0)# add some information if needed
You need to listen to the transformation for Odom to base_link and subscribe the scan topic
import rospy
import roslib
from sensor_msgs.msg import LaserScan
import tf
def scanCb(msg):
py,px=[],[]
scandata=msg.ranges
angle_min=msg.angle_min
angle_max=msg.angle_max
angle_increment=msg.angle_increment
range_min=msg.range_min
range_max=msg.range_max
points2d.update(scandata,angle_min,angle_max,angle_increment)
if __name__ == "__main__":
rospy.init_node('main', anonymous=True) #make node
rospy.Subscriber("/scan", LaserScan, scanCb,queue_size = 1)
rate = rospy.Rate(5) # 5hz
points2d=laser_to_points2d()
listener = tf.TransformListener()
while not rospy.is_shutdown():
listener.waitForTransform("/base_link", "/odom", rospy.Time(0),rospy.Duration(1.0))
p=listener.transformPointCloud("odom",points2d.base_link_point2d)
rate.sleep()
7 | No.7 Revision |
This is a simple code to transform scan point cloud to base link. Use a separate script for class laser_to_points2d:
for ease of use.
from math import sin, cos
import tf
import numpy as np
from sensor_msgs.msg import PointCloud
from geometry_msgs.msg import Point32
class laser_to_points2d:
def __init__(self,):
self.base_link_point2d=PointCloud()
self.base_link_point2d.header.frame_id = "base_link"
def update(self,scandata,angle_min,angle_max,angle_increment):
self.base_link_point2d.points=[]
self.base_link_point2d.channels=[]
for i in xrange(len(scandata)):
angle=angle_min+i*angle_increment
if not math.isnan(scandata[i]):
r=scandata[i]
else:r=0.0
px=float(r)*cos(angle)
py=float(r)*sin(angle)
self.base_link_point2d.points.append(Point32(px,py, 0.0))
self.base_link_point2d.channels.append(0)# add some information if needed
You need to listen to the transformation for Odom to base_link and subscribe the scan topic
import rospy
import roslib
from sensor_msgs.msg import LaserScan
import tf
def scanCb(msg):
py,px=[],[]
scandata=msg.ranges
angle_min=msg.angle_min
angle_max=msg.angle_max
angle_increment=msg.angle_increment
range_min=msg.range_min
range_max=msg.range_max
points2d.update(scandata,angle_min,angle_max,angle_increment)
if __name__ == "__main__":
rospy.init_node('main', anonymous=True) #make node
rospy.Subscriber("/scan", LaserScan, scanCb,queue_size = 1)
rate = rospy.Rate(5) # 5hz
points2d=laser_to_points2d()
listener = tf.TransformListener()
while not rospy.is_shutdown():
listener.waitForTransform("/base_link", "/odom", rospy.Time(0),rospy.Duration(1.0))
p=listener.transformPointCloud("odom",points2d.base_link_point2d)
rate.sleep()
8 | No.8 Revision |
This is a simple code to transform scan point cloud to base link. Use a separate script for class laser_to_points2d:
for ease of use.
from math import sin, cos
import tf
import numpy as np
from sensor_msgs.msg import PointCloud
from geometry_msgs.msg import Point32
class laser_to_points2d:
def __init__(self,):
self.base_link_point2d=PointCloud()
self.base_link_point2d.header.frame_id = "base_link"
def update(self,scandata,angle_min,angle_max,angle_increment):
self.base_link_point2d.points=[]
self.base_link_point2d.channels=[]
for i in xrange(len(scandata)):
angle=angle_min+i*angle_increment
if not math.isnan(scandata[i]):
r=scandata[i]
else:r=0.0
px=float(r)*cos(angle)
py=float(r)*sin(angle)
self.base_link_point2d.points.append(Point32(px,py, 0.0))
self.base_link_point2d.channels.append(0)# add some information if needed
You need to listen to the transformation for Odom to base_link and subscribe the scan topic
import rospy
import roslib
from sensor_msgs.msg import LaserScan
import tf
from file_name_your_ class _laser_to_points2d import laser_to_points2d
def scanCb(msg):
py,px=[],[]
scandata=msg.ranges
angle_min=msg.angle_min
angle_max=msg.angle_max
angle_increment=msg.angle_increment
range_min=msg.range_min
range_max=msg.range_max
points2d.update(scandata,angle_min,angle_max,angle_increment)
if __name__ == "__main__":
rospy.init_node('main', anonymous=True) #make node
rospy.Subscriber("/scan", LaserScan, scanCb,queue_size = 1)
rate = rospy.Rate(5) # 5hz
points2d=laser_to_points2d()
listener = tf.TransformListener()
while not rospy.is_shutdown():
listener.waitForTransform("/base_link", "/odom", rospy.Time(0),rospy.Duration(1.0))
p=listener.transformPointCloud("odom",points2d.base_link_point2d)
rate.sleep()
9 | No.9 Revision |
This is a simple code to transform scan point cloud to base link. Use a separate script for class laser_to_points2d:
for ease of use.
from math import sin, cos
import tf
import numpy as np
from sensor_msgs.msg import PointCloud
from geometry_msgs.msg import Point32
class laser_to_points2d:
def __init__(self,):
self.base_link_point2d=PointCloud()
self.base_link_point2d.header.frame_id = "base_link"
def update(self,scandata,angle_min,angle_max,angle_increment):
self.base_link_point2d.points=[]
self.base_link_point2d.channels=[]
for i in xrange(len(scandata)):
angle=angle_min+i*angle_increment
if not math.isnan(scandata[i]):
r=scandata[i]
else:r=0.0
px=float(r)*cos(angle)
py=float(r)*sin(angle)
self.base_link_point2d.points.append(Point32(px,py, 0.0))
self.base_link_point2d.channels.append(0)# add some information if needed
You need to listen to the transformation for Odom to base_link and subscribe the scan topic
import rospy
import roslib
from sensor_msgs.msg import LaserScan
import tf
from file_name_your_ class _laser_to_points2d import laser_to_points2d
def scanCb(msg):
py,px=[],[]
scandata=msg.ranges
angle_min=msg.angle_min
angle_max=msg.angle_max
angle_increment=msg.angle_increment
range_min=msg.range_min
range_max=msg.range_max
points2d.update(scandata,angle_min,angle_max,angle_increment)
if __name__ == "__main__":
rospy.init_node('main', anonymous=True) #make node
rospy.Subscriber("/scan", LaserScan, scanCb,queue_size = 1)
rate = rospy.Rate(5) # 5hz
points2d=laser_to_points2d()
listener = tf.TransformListener()
while not rospy.is_shutdown():
listener.waitForTransform("/base_link", "/odom", rospy.Time(0),rospy.Duration(1.0))
p=listener.transformPointCloud("odom",points2d.base_link_point2d)
rate.sleep()
10 | No.10 Revision |
This is a simple code to transform scan point cloud to base link. Use a separate script for class laser_to_points2d:
for ease of use.
from math import sin, cos
import tf
import numpy as np
from sensor_msgs.msg import PointCloud
from geometry_msgs.msg import Point32
class laser_to_points2d:
def __init__(self,):
self.base_link_point2d=PointCloud()
self.base_link_point2d.header.frame_id = "base_link"
def update(self,scandata,angle_min,angle_max,angle_increment):
self.base_link_point2d.points=[]
self.base_link_point2d.channels=[]
for i in xrange(len(scandata)):
angle=angle_min+i*angle_increment
if not math.isnan(scandata[i]):
r=scandata[i]
else:r=0.0
px=float(r)*cos(angle)
py=float(r)*sin(angle)
self.base_link_point2d.points.append(Point32(px,py, 0.0))
self.base_link_point2d.channels.append(0)# add some information if needed
You need to listen to the transformation for Odom to base_link and subscribe the scan topic
import rospy
import roslib
from sensor_msgs.msg import LaserScan
import tf
from file_name_your_ class _laser_to_points2d import laser_to_points2d
def scanCb(msg):
py,px=[],[]
scandata=msg.ranges
angle_min=msg.angle_min
angle_max=msg.angle_max
angle_increment=msg.angle_increment
range_min=msg.range_min
range_max=msg.range_max
points2d.update(scandata,angle_min,angle_max,angle_increment)
if __name__ == "__main__":
rospy.init_node('main', anonymous=True) #make node rospy.Subscriber("/scan", LaserScan, scanCb,queue_size = 1)
rate = rospy.Rate(5) # 5hz points2d=laser_to_points2d()
listener = tf.TransformListener()
tf.TransformListener()
while not rospy.is_shutdown():
listener.waitForTransform("/base_link", "/odom", rospy.Time(0),rospy.Duration(1.0))
p=listener.transformPointCloud("odom",points2d.base_link_point2d)
p=listener.transformPointCloud("odom",points2d.base_link_point2d)
rate.sleep()