Simulate IMU (2D gyro and accelerometer) data

If I have a robot path in 2D space,

i.e. a vector of (x,y) locations, and I need to generate artificial IMU data (simulate them), how would I go about it?

How do I model equations to generate the values given a time frame and positions?

I've come across imusim I'd like to know how to model them and generate using Matlab or something similar.

• are you trying to simulate robot behaviour in a graphical environment. or are you asking because you want to simulate hardware on robots where those devices aren't present? – Octopus Apr 1 '15 at 7:01
• latter. Don't have a physical IMU yet but need to simulate those. 1) Need to generate a fake path/trajectory (x,y,phi) 2) Using those, need to generate IMU data. – Raaj Apr 1 '15 at 15:20

This is really simple. First of all, you need to understand how the sensor works. In other words, you need understand whether the measurements is coming from linear or nonlinear model. Second, what is the type of the sensor's noise?

CASE STUDY: Let's say you want to simulate DC Voltemeter to measure a battery's voltage of 5 Volt. In an ideal case, the model of the system is

$$V_{b}(k+1) = V_{b}(k)$$ It is just a constant value whether you measure it now or in the future, the value is 5 Volt. In the reality, this is not the case. If you measure it now, you might get 4.9 Volt, later on 5.1 Volt. The measurements vary which means the sensor is noisy. In many cases, the noise is Gaussian with zero mean and some variance (i.e. $\mathcal{N}(0, \sigma^{2}))$. Therefore, the measurement model is

$$Z(k+1) = V_{b}(k+1) + \delta$$

where $\delta$ is the measurement noise (i.e. $\mathcal{N}(0, \sigma^{2})$).

To simulate this scenario in Matlab,

clear all; clc;
ideal_value = 5;
sigma = 0.01;
real_value = ideal_value + sigma*randn(5,1)

The output is then

real_value =
5.0009
5.0173
4.9939
4.9926
4.9825

In reality, there is no way to know the ideal value. If you want to decrease the accuracy of your sensor, you need to increase the value of the $\sigma$. In 2D laser scenario, the input of the sensor is the Cartesian location ($x, y$) and the output is the polar coordinates ($r, \phi$) with some Gaussian noise. Let's say we have a 2D laser sensor that is located in the origin and we have a tree in planar environment. The sensor with update rate 10 Hz provides the range $r$ and the bearing $\phi$ to the tree with some noise in both the range and the bearing. Therefore the following code simulates the scenario

clear all
clc

tree_x = 4;
tree_y = 4;

sigma_r = 0.1; % m

dt = 1/10;

t = 0:dt:0.5;
for i = 1:numel(t)
r(i) = sqrt( tree_x^2 + tree_y^2 ) + sigma_r*randn();
p(i) = atan2( tree_y, tree_x ) + sigma_p*randn();
end
r