How to use IMU with Raspberry Pi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this tutorial we will learn about center fusion we will use gyroscope accelerometer and magnetometer to calculate orientation of an object getting precise orientation of the robot is very important in motion control what is imu imu stands for inertial measurement unit imus are used to calculate orientation of a body imu is an essential part for aircrafts spacecrafts and missiles the first imus were huge complicated and expensive devices but nowadays they have become cheaper smaller and more affordable as was mentioned previously imu consists of three sensors accelerometer gyroscope and magnetometer accelerometer measures proper acceleration which is the acceleration a body experiences relative to free fall there are several types of acceleration sensors and each type has a different operating principle here is one of them an electrode is connected to a mass into a fixed outer body as acceleration occurs the mass moves and the distance between electrodes changes since each pair of electrode forms a capacitor capacitance changes as the distance between electrodes changes by measuring the difference in capacitance acceleration is calculated a gyroscope is a device used for measuring angular velocity as with accelerometer there is a lot of types of gyroscopes with various working principles but almost all gyroscopes for hobby use are me ms gyroscopes for example there are elements which change their vibration mode if a force is applied to them when these sensors are rotated coriolis force is applied on them by measuring voltage which emerges due to change of vibration mode of the elements we can get angular velocity a magnetometer is a device that measures magnetic field in imu it used to get absolute orientation most of the cheap sensors are using hall elements by measuring voltage that emerges when a magnetic field is applied perpendicular to the hall element the current direction of the sensor can be calculated for orientation calculation hrs algorithm is used hrs stands for attitude and heading reference system this algorithm combines gyroscope accelerometer and magnetometer data into a single measurement of orientation relative to the earth in this tutorial we will not discuss mathematical operations but we will take a look at parameters that affect calculation result there are four parameters the first is gain gain determines the influence of the gyroscope relative to other sensors a large value of k will mean an increased rate of convergence but also a greater sensitivity to linear accelerations and temporal magnetic distortions the second is acceleration rejection acceleration rejection is a threshold used by the acceleration rejection feature the accelerometer is only omitted if the measured magnitude of gravity exceeds limits for a specified period of time the third is magnetic rejection magnetic rejection is a threshold used by the magnetic rejection feature magnetic measurements that deviate from the expected intensity of the earth's magnetic field are rejected to prevent magnetic distortions from corrupting the algorithm output the fourth is rejection timeout rejection timeout defines for how many steps the input from accelerometer or magnetometer will be rejected for data transferring from a sensor to a microcontroller i swear c communication is often used i square c stands for inter integrated circuit it is a bus interface connection protocol incorporated into devices for serial communication it was originally designed by philips semiconductor in 1982. recently it is a widely used protocol for short distance communication it is also known as two-wired interface the wiring is very simple we have to connect power ground sda and scl pins of raspberry pi and the sensor since it is difficult to remember the function of every pin when working with gpios it is convenient to have a schematic drawing of this kind now we have to choose which sensor we are going to use ideally the sensor should be chosen based on the required robot specification but if you don't have one it can be chosen by budget limitation or availability in this tutorial we will use this sensor it meets our requirements and also has good documentation which is also very important for example here we can find information about how to connect which libraries are required and how to use this sensor now we are going to install the required libraries to use the sensors go to the previous page and copy these two lines the first library is necessary to use accelerometer and magnetometer the second library is installed to use gyroscope to use i-square-c communication on the raspberry pi we should change configuration go to raspberry pi configuration open the interfaces tab check the i square c section to on now let's check whether our sensor is recognized correctly open the terminal execute the i square c detect command the address of each sensor should appear now we are going to install a library to do imu fusion in this tutorial we will use this library on this page you can find detailed explanation of the algorithm and reference to related papers but we don't have to clone and build this library since it can be installed using pip so just execute the pip 3 install imu fusion command finally we are going to install gui related libraries install pi qt5 qt is set of cross-platform c plus plus libraries that implement high-level apis for accessing many aspects of modern desktop and mobile systems next install the pi qt graph package pi qt graph is a pure python graphics and gui library built on pi qt pi side and non pi now let's look into the code here instances of i-square-c communication and sensors are created note that we configure sensor setting while instantiation in this part imu fusion algorithm parameters are defined the algorithm works fine with default parameters but here gain value is set higher the default value here the queue of size 20 is defined these dequeues are used to plot graphs in this part various graph properties are set these properties mostly affect appearance of a graph in this section timer is defined update plot data function is called each 10 milliseconds here data from each sensor is obtained and converted to non-pi array here sensor fusion is performed since update function returns quaternions quaternions are converted to euler angles by the two euler function here each angle is appended to dequeue and plotted now we are ready to run our program execute the imu measure pi script you
Info
Channel: robot mania
Views: 10,218
Rating: undefined out of 5
Keywords: Raspberry Pi, python, robotics, programming, ROS
Id: yW22igLjkjY
Channel Id: undefined
Length: 9min 41sec (581 seconds)
Published: Sat Aug 20 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.