This is my code to read the LDS sensor. LDS sensor is used to estimate the distance from robot to walls. I can print the data(estimate distance) in the terminal but I cant write it in the csv file automatically. I would like to write about 1000 data into csv file by using python code enter image description here.
#! /usr/bin/env python
import rospy
import csv
from sensor_msgs.msg import LaserScan
def callback(msg):
d = msg.ranges [90]
print d
rospy.init_node("read")
sub = rospy.Subscriber('/scan', LaserScan, callback)
rospy.spin()
f= open("\\testread.csv", "w")
c=csv.writer(f)
for x in range(1000):
c.writerow(d)
f.close()