oc.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:srcsim2017 作者: ZarjRobotics 项目源码 文件源码
def draw_lidar(self):
        if self.lidar_msg is not None:
            pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 512, 20)
            a = pixbuf.get_pixels_array()
            camera_increment = (2 * 1.3962) / 512
            offset = (len(self.lidar_msg.ranges) - (2 * 512)) / 2
            scale = 255.0 / (self.lidar_msg.range_max - self.lidar_msg.range_min)
            for x in range(512):
                angle = -1.3962 + (camera_increment * x)
                distance = self.lidar_distance_for_angle(angle)
                self.lidar_depth[x] = round(distance, 2)
                if distance <= self.lidar_msg.range_min:
                    scaled = 0
                elif distance >= self.lidar_msg.range_max:
                    scaled = 255
                else:
                    scaled = distance * scale
                color = [ 0, 255 - int(scaled), 0 ]
                for y in range(20):
                    a[y, x] = color
                if round(math.degrees(angle), 0) % 30 == 0:
                    a[0, x] = [255, 0, 0]
                    a[19, x] = [255, 0, 0]
                if angle == 0.0:
                    a[0, x] = [255, 0, 0]
                    a[1, x] = [255, 0, 0]
                    a[18, x] = [255, 0, 0]
                    a[19, x] = [255, 0, 0]

            pixmap, mask = pixbuf.render_pixmap_and_mask()
            self.lidar.set_from_pixmap(pixmap, mask)


    # Ideally, we process in the main thread context, hopefully
    #  preventing bugs...
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号