Interpreting Gyroscope and Accelerometer Data

Typically: "How do I... ", "How can I... " questions
Post Reply
Stigran
Posts: 4
Joined: 08 Mar 2018, 18:53

Interpreting Gyroscope and Accelerometer Data

Post by Stigran » 09 Mar 2018, 15:30

Good day to everyone.

I am doing a university project which requires me to interface VREP to Matlab using remote APIs.
In particular i am recieving data from a gyroscope and a accelerometer mounted on a moving robot, and the connection works. My problem is that i can't understand the data i recieve in Matlab.

Using(among other things)

VREP side:
h=simGetObjectAssociatedWithScript(sim_handle_self)
simSetStringSignal('Accelerometer',simPackFloats(simGetObjectPosition(h,-1)))

Matlab side:
[res,data1]=vrep.simxGetStringSignal(clientID,'Accelerometer',vrep.simx_opmode_buffer);
if (res==vrep.simx_return_ok)
accelData=vrep.simxUnpackFloats(data1)

i recieve in Matlab a vector named accelData with 3 elements every simulation cycle.
1) Are the three elements of the vector the x,y,z components of the acceleration/angular velocity? If yes, the values are in m^2/s and rad/s or something else?
2) If the three elements of the vector are indeed the x,y,z components of the acceleration/angular velocity. The robot is moving on a flat surface, so there is no acceleration on the z axis, but the gyroscope still reads 3 non-zero values at all times. How is this possible?

I hope i was clear with my question. Thank you for your time.

Stigran
Posts: 4
Joined: 08 Mar 2018, 18:53

Re: Interpreting Gyroscope and Accelerometer Data

Post by Stigran » 09 Mar 2018, 16:06

I think i realize where part of the problem is: im using the wrong function in VREP

simSetStringSignal('Accelerometer',simPackFloats(simGetObjectPosition(h,-1))) should give me the sensor's position not acceleration or angular velocity (and that's why both sensors give the same values in readings...).
So it also makes sense that the z axis reading is not zero i think - the Surface on which the robot moves is not at "0 level" (the third value of every reading is fixed at every cycle of simulation, it never changes).

Still, given that i have messed up there, how do i get the data from the sensors? I have looked in the help files but i only found
simGetObjectVelocity
simGetObjectOrientation

But they don't seem to give me exactly what i need.
Again, thank you for your time.

fferri
Posts: 173
Joined: 09 Sep 2013, 19:28

Re: Interpreting Gyroscope and Accelerometer Data

Post by fferri » 09 Mar 2018, 21:05

Hi Stigran,

There is an actual accelerometer (using a mass + force sensor) and an gyroscope. Refer to the models in the model browser:

models/components/sensors/Accelerometer
models/components/sensors/GyroSensor

Stigran
Posts: 4
Joined: 08 Mar 2018, 18:53

Re: Interpreting Gyroscope and Accelerometer Data

Post by Stigran » 10 Mar 2018, 08:50

I do have an accelerometer and a gyroscope already installed on the robot. A connectiontube has already been created to transmit the data. But i don't understand which function let's me read the data from the sensors.

fferri
Posts: 173
Joined: 09 Sep 2013, 19:28

Re: Interpreting Gyroscope and Accelerometer Data

Post by fferri » 10 Mar 2018, 12:29

The sensor models Accelerometer and GyroSensor contain comments in their child script that explain how to do that too.

Stigran
Posts: 4
Joined: 08 Mar 2018, 18:53

Re: Interpreting Gyroscope and Accelerometer Data

Post by Stigran » 10 Mar 2018, 14:51

Thank you for your reply fferri!

I did as you said and added the code to the robot's script, but now i am not recieving any data on the Matlab client.
Should i pack the data into a string and then set it as a signal first to be able to send data from server to client?

fferri
Posts: 173
Joined: 09 Sep 2013, 19:28

Re: Interpreting Gyroscope and Accelerometer Data

Post by fferri » 10 Mar 2018, 15:19

The sensors from the model folder use communication tubes by default.
You can read those using sim.tubeRead like explained in the sensor's child script comments.

If you want to use signals, you have to uncomment the relative section (the one with sim.setFloatSignal); then you can read the signal with sim.getFloatSignal.

Post Reply