借助传感器的值更新python字典

时间:2018-08-30 15:35:41

标签: python list sensor lidar

我有一个Python脚本来运行激光雷达传感器。它测量距离。我正在借助伺服电机移动激光雷达。所以我必须测量不同角度的距离。我正在尝试更新角度和距离的字典。但是字典总是显示错误的角度值。

部分代码如下。任何建议都会很有帮助

    angle_start =0
    angle_step = 2    #degree step     
    self.set_angle(angle_start)   #a method to set servo angle
    time.sleep(pos_time) 

    angle_dict = {}          #an empty dict
    angle=angle_start
    while angle <= angle_stop:

        self.set_angle(angle)
        time.sleep(0.05)

        distance = int(self.messure_distance())    #a method to measure the distance. it works fine.
        angle_dict[angle] = distance       #trying to update the dict. it stores right distance. but now the right angle.

        angle = angle + angle_step              #increasing angle

0 个答案:

没有答案