I have the "x", "y" and "z" readings of gyroscope and accelerometer. From these readings I want to interpret that wether my robot took a right turn or left turn. Can some one guide me how should I proceed?
Expanding on the answer given by C.O Park and comment by Ben.
The gyroscope and accelerometer will give you 6 sensor values corresponding to the $x$/$y$/$z$ linear accelerations and the $x$/$y$/$z$ angular velocities. If you are looking to interpret whether your robot is turning left or right at any particular moment then you can simply check the sign of the angular velocity about the z-axis (assuming you are taking z to be the vertical direction). If you are looking to interpret whether your robot has turned left or right relative to its original direction then you can keep track of an accumulated angle through numerical integration. A simple algorithm for this would be the following:
Let $\theta(t)$ denote the rotation about the vertical axis (also called heading angle) at time $t$. Let $\omega(t)$ denote the angular velocity about the vertical axis at time $t$. Every $t_s$ seconds you will take a measurement of $\omega(t)$ from your gyroscope sensor. The rotation can then be estimated by $$\theta((k+1)t_s) = \theta(kt_s)+\omega(kt_s)t_s,$$ where $k$ is an integer that denotes how many measurements you have taken so far. $\theta(0)$ can be assumed zero since it is your initial direction. In words, the heading angle at timestep $k+1$ is the heading angle at timestep $k$ plus the rotation that occurred during that timestep. Then to interpret whether your robot has turned left or right relative to its original direction you can look at the sign of $\theta$. In pseudocode:
# intialize heading angle estimate theta = 0; # update information every ts seconds loop: # read sensor and update estimate omega = read_rotation_rate(); theta = theta + omega*ts; # check turning direction if omega > 0: turning = left; else if omega < 0: turning = right; # check net direction if theta > 0: turned = left; else if theta < 0: turned = right;
In practice there will be some complications like sensor noise and drift that will result in errors in your estimate of the heading angle, but this should provide you with a starting point.
Just monitor the rotation velocity of z-axis (z value from gyroscope or any other axis according to your setup).
If the value is over some threshold and the sign is positive, it is turning left. If the sign is negative it is the right turn.
The right way to do this is to accumulate the value stream and see if the accumulated angle is near to 90 or -90 degree. But it would be difficult for you.
Some common accelerometer/gyro chips have built-in processor that performs integration for you. An example I am familiar with is MPU-6050.
Given that capabilty, you can get the ready-made data for current direction of your chip directly from the chip using I2C.
Please search for "mpu 6050 dmp" to see some examples.