Why This Matters in Robotics

Robots rely on sensors to understand the world around them:

  • Sensors measure distance, light, pressure, and more
  • But sensor readings are often noisy or imperfect
  • The raw reading rarely equals the true physical value
  • Linear regression helps model the relationship between a sensor reading and the true measurement

What is Linear Regression?

Linear regression fits a line to data to model the relationship between two variables.

\[y = \beta_0 + \beta_1 x + \varepsilon\]

  • \(x\) = sensor reading
  • \(y\) = actual distance
  • \(\beta_0\) = intercept
  • \(\beta_1\) = slope
  • \(\varepsilon\) = error

Example Dataset

A robot’s ultrasonic distance sensor was tested against a laser rangefinder (ground truth).

Sensor Reading Actual Distance (m)
5.1 5.5
6.3 6.6
7.0 7.4
8.4 8.7
9.2 9.8
10.5 10.9
11.0 11.4
12.1 12.5

Scatterplot of Sensor vs. Actual Distance

Regression Line Fitted to the Data

The shaded band shows the 95% confidence interval around the fitted line.

Fitted Equation and Prediction

Running lm() on this data gives the fitted model:

\[\hat{y} = 0.42 + 1.03x\]

Example prediction: If the robot’s sensor reads 10.0, the estimated actual distance is:

\[\hat{y} = 0.42 + 1.03(10) = 10.72 \text{ m}\]

This fitted line can be used in real-time to correct raw sensor output before feeding it into navigation algorithms.

Interactive Plot with Plotly

R Code: Fitting the Model

sensor <- c(5.1, 6.3, 7.0, 8.4, 9.2, 10.5, 11.0, 12.1, 13.3, 14.7)
actual <- c(5.5, 6.6, 7.4, 8.7, 9.8, 10.9, 11.4, 12.5, 13.8, 15.2)
df <- data.frame(sensor = sensor, actual = actual)

model <- lm(actual ~ sensor, data = df)
summary(model)

Interpretation

From the regression output:

  • The slope \(\hat{\beta}_1 \approx 1.03\) means for every 1-unit increase in sensor reading, actual distance increases by about 1.03 meters
  • The intercept \(\hat{\beta}_0 \approx 0.42\) is a small calibration offset
  • A high \(R^2\) value (close to 1) confirms the sensor readings are strongly linearly related to actual distance
  • This model can be deployed on the robot to convert raw sensor output into calibrated distance estimates in real time