LiDAR Lite data from I2C

This is a simple computation on the raw data obtained by the LiDAR Lite For more details on using LiDAR Lite see https://learn.sparkfun.com/tutorials/lidar-lite-v3-hookup-guide.

df <- read.table("D:/R_Files/tdata5.txt", header = FALSE)
head(df)
##         V1     V2 V3       V4    V5  V6
## 1 Position (deg):  0 Distance (cm): 147
## 2 Position (deg):  1 Distance (cm): 147
## 3 Position (deg):  2 Distance (cm): 147
## 4 Position (deg):  3 Distance (cm): 148
## 5 Position (deg):  4 Distance (cm): 149
## 6 Position (deg):  5 Distance (cm): 153

1. Plot the raw data (angle, distance)

After import the raw data into your local R folder, you can plot the raw data

x1=df$V3
y1=df$V6
plot(x1, y1, main="Raw Data from LiDAR Lite", sub="(Data:02/09/2018)",
     xlab="Angles(degree)", ylab="Distances(cm)",
     xlim=c(0, 180), ylim=c(0, 250))

2. Plot the convert data to point position (x,y)

Simple rcos(theta) and rsin(theta) will do if you had your LiDAR at the (0,0) position to start with

x=df$V6*cos((df$V3)*pi/180)
y=df$V6*sin((df$V3)*pi/180)
plot(x, y, main="Calculated Data from LiDAR Lite", sub="(Data:02/09/2018)",
     xlab="Distance(cm) from LiDAR in X", ylab="Distances(cm) from LiDAR in Y",
     xlim=c(-200,200), ylim=c(0, 150))
lines(x,y)

3. Plot the Normalized positions (x,y)

Since my LiDAR was tilt at an angle, I need to rotated it back in computation

x=df$V6*cos((df$V3-11)*pi/180)
y=df$V6*sin((df$V3-11)*pi/180)
plot(x, y, main="Data from LiDAR Lite after Normalization", sub="(Data:02/09/2018)",
     xlab="Distance(cm) from LiDAR in X", ylab="Distances(cm) from LiDAR in Y",
     xlim=c(-200,200), ylim=c(0, 150))
lines(x,y)