d r o n e s i t l b r i n g u p w i t h t h e i i o f r a ...€¦ · my experiments with bringing...
TRANSCRIPT
![Page 1: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/1.jpg)
1 . 1
DRONE SITL BRINGUP WITH THE IIO FRAMEWORKBandan Das <[email protected]>
Open Source Summit, Europe, 2018
![Page 2: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/2.jpg)
2 . 1
WHAT'S THIS ABOUT ?My experiments with bringing up sensors on a x86 boardUnderstanding the IIO framework
Interfacing the framework with SITL code to verify sensors are working
![Page 3: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/3.jpg)
3 . 1
WHAT ISN'T THIS ABOUT ?FlyingDrones, I am a newbie!
![Page 4: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/4.jpg)
4 . 1
ACKNOWLEDGEMENTSReal Time systems group at BU
Microkernels, Cache scheduling algorithms, Virtualization, Predictabletime
https://www.cs.bu.edu/~richwest/index2.html
![Page 5: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/5.jpg)
5 . 1
STATE OF THE ART
![Page 6: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/6.jpg)
5 . 2
HARDWARE
Image © PX4 Dev Team. License: CC BY 4.0
Most drone boards belong to the STM32 familyBecoming faster/powerful everyday!Low power requirements
![Page 7: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/7.jpg)
5 . 3
SOFTWAREArdupilot, Beta�ight, iNav, Clean�ight
![Page 8: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/8.jpg)
6 . 1
WHY X86 ?Increasingly complex tasks and onboard peripheralsProcessing powerThe case for reactive dronesLow power x86 boards are a reality although not common
![Page 9: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/9.jpg)
7 . 1
WHY LINUX ?Robust operating systemDrivers for a wide variety of sensors/peripheralsChoice of schedulers
![Page 10: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/10.jpg)
8 . 1
A LOOK AT THE INTEL AERO COMPUTE BOARD
Aero as a Companion Computer
![Page 11: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/11.jpg)
9 . 1
HOWEVER…The Aero is a powerful computerOnboard sensors to run standalone as a �ight controllerAccess to GPIO pins/motor outputs through onboard FPGA
![Page 12: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/12.jpg)
10 . 1
MOVING FC OPERATIONS TO A X86 BOARDReinventing the wheel
Customized Linux that jumps to a �ight controller loop with speci�ctasks
Leverage on existing solutionsRun an existing �ight controller software as a process
![Page 13: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/13.jpg)
11 . 1
INTERFACING WITH THE ONBOARD SENSORSspidev/i2cdev - userspace driversLinux already has drivers for most sensors
exposed by the Industrial IO interface (IIO)Advantages
Minimizes latencyDisadvantages
Crashes can be deadly
![Page 14: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/14.jpg)
12 . 1
AN INTRODUCTION TO THE IIO INTERFACEIndustrial Input/Output
Examples include Humidity Sensors, Temperature sensors,Magenetometer etcv4.18: ~20 classes, each containing numerous device driversMost devices connected via I2C or SPI
IIO provides a hardware abstraction layer over these devicesSharing of infrastructureDeveloper focus on device function rather than knowledge of plumbinginternalsConsistent application development frameworkData buffer for continuous data and single shot access via sysfs
![Page 15: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/15.jpg)
13 . 1
GETTING STARTED WITH IIODevice drivers
BMI 160 Inertial Measurement Unit
BMM 150 3 axis Geomagnetic Sensor
MS5611 Pressure Sensor
ls drivers/iio/imu/bmi160/ bmi160_core.c bmi160_i2c.c bmi160_spi.c
ls drivers/iio/magnetometer/ bmc150_magn.c bmc150_magn_i2c.c bmc150_magn_spi.c
ls drivers/iio/pressure/ ms5611_core.c ms5611_spi.c ms5611_i2c.c
![Page 16: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/16.jpg)
14 . 1
GETTING STARTED WITH IIOKey components
Device driversChannelsBuffersTriggers
![Page 17: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/17.jpg)
15 . 1
GETTING STARTED WITH IIOChannels - One of the many functions provided by the device
BMI160
BMM150
cat /sys/bus/iio/devices/iio\:device0/name bmi160 ls /sys/bus/iio/devices/iio\:device0/ in_accel_x_raw in_accel_y_raw in_accel_z_raw
cat /sys/bus/iio/devices/iio\:device1/name bmc150_magn ls /sys/bus/iio/devices/iio\:device1 in_magn_x_raw in_magn_y_raw in_magn_z_raw
![Page 18: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/18.jpg)
16 . 1
GETTING STARTED WITH IIOBuffers
Raw continuous data read from the deviceSpeci�c channels can be enabled
Data format speci�ed by channels
Example:
K�fo backedRead using standard �leops by accessing /dev/iio:deviceXmmap based interface supported by a DMA backend (high speeddevices)
cat /sys/bus/iio/devices/iio\:device1/scan_elements/in_magn_x_type le:s32/32>>0
![Page 19: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/19.jpg)
17 . 1
GETTING STARTED WITH IIOTriggers
Capture data only when neededBased on a hardware eventUser initiated (eg: via sysfs)Software trigger (eg: hrtimer based)Enabling trigger enables data capture
![Page 20: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/20.jpg)
18 . 1
GETTING STARTED WITH IIOInitializing SPI/I2C devices
Not enumerated at the hardware levelSPI (BMI160)
Device treeACPIBoard initialization �le
Example:static struct spi_board_info imu_board_info __initdata ={ .modalias= "bmi160", .bus_num= SPIDEV_SPI_BUS, .chip_select= SPIDEV_SPI_CS, .max_speed_hz= SPIDEV_SPI_HZ, }; ... master = spi_busnum_to_master(SPIDEV_SPI_BUS); ... dev = spi_new_device(master, &imu_board_info); ...
![Page 21: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/21.jpg)
19 . 1
GETTING STARTED WITH IIOInitializing SPI/I2C devices
I2C (BMM150)
Device treeBoard initialization �lesysfs interfaceExample:echo bmc150_magn 0x12 > /sys/bus/i2c/devices/i2c-2/new_device
![Page 22: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/22.jpg)
20 . 1
CREATING A TRIGGERmkdir /sys/kernel/config/iio/triggers/hrtimer/trigger0 echo 5000 > /sys/bus/iio/devices/trigger0/sampling_frequency cd /sys/bus/iio/devices/iio:device0 #Associate trigger with BMI160 echo trigger0 > trigger/current_trigger echo 1 > scan_elements/in_accel_x_raw echo 1 > buffer/enable
![Page 23: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/23.jpg)
21 . 1
SHIM LAYER: LIBIIO
libiio: Building blocks
Library that interfaces with the IIO APIEase of developer interacting with the IIO framework
![Page 24: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/24.jpg)
22 . 1
SIMULATION FRAMEWORKS (SITL/HITL)SITL
Modi�ed �ight controller software running in a simulator environmentControl signals come from software or a controllerSimulator feeds sensor data back to �rmware feedback loopActuator outputs fed to simulator
HITLFlight controller software runs on the actual boardSensor data and outputs fed to a simulatorEnables testing in closer to real-world conditions
![Page 25: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/25.jpg)
23 . 1
SITL SETUP IN BETAFLIGHT
Basic SITL setup in Beta�ight/Clean�ight
![Page 26: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/26.jpg)
24 . 1
SENSOR DATA FORMAT typedef struct { double timestamp; double imu_angular_velocity_rpy[3]; double imu_linear_acceleration_xyz[3]; double imu_orientation_quat[4]; double velocity_xyz[3]; double position_xyz[3]; } fdm_packet;
![Page 27: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/27.jpg)
25 . 1
PLUGGING IN IIO DATA IN THE SITL LOOP
![Page 28: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/28.jpg)
26 . 1
PLUGGING IN IIO DATA IN THE SITL LOOPVisual indication of correct functioning of sensorsSensors output in a more readable format or graph (eg. Clean�ightCon�gurator)
![Page 29: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/29.jpg)
27 . 1
BETAFLIGHT TASKS/* TASK_COUNT = ~30 */ cfTask_t cfTasks[TASK_COUNT] = { ... [TASK_GYROPID] = { .taskName = "PID", .subTaskName = "GYRO", .taskFunc = taskMainPidLoop, .desiredPeriod = TASK_GYROPID_DESIRED_PERIOD, .staticPriority = TASK_PRIORITY_REALTIME, }, [TASK_ACCEL] = { .taskName = "ACC", .taskFunc = taskUpdateAccelerometer, .desiredPeriod = TASK_PERIOD_HZ(1000), // 1000Hz, every 1ms .staticPriority = TASK_PRIORITY_MEDIUM, }, [TASK_ATTITUDE] = { .taskName = "ATTITUDE", .taskFunc = imuUpdateAttitude, .desiredPeriod = TASK_PERIOD_HZ(100), .staticPriority = TASK_PRIORITY_MEDIUM, }, ... #ifdef USE_MAG [TASK_COMPASS] = { .taskName = "COMPASS", .taskFunc = compassUpdate, .desiredPeriod = TASK_PERIOD_HZ(10), // Compass is updated at 10 Hz .staticPriority = TASK_PRIORITY_LOW, }, #endif ...
![Page 30: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/30.jpg)
... };
28 . 1
IMU LOOP COUNT
Standard upstream kernelNo specialized con�g
![Page 31: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/31.jpg)
29 . 1
IMU LOOP COUNT
Standard upstream kernelisolcpus=2-3irq thread on CPU 2 and read process on CPU 3
![Page 32: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/32.jpg)
30 . 1
REFERENCES (Code snippets for the SITL/IIO
interface) (Secrets of the Ftrace function tracer)
(Beta�ight source)
(IIO, a new kernel subsystem) (Library for interfacing with IIO
devices) (APM on Linux: Porting
Ardupilot to Linux1) (Using the Linux
IIO framework for SDR) (Rich West's Home page)
(Intel Aero Wiki)
https://bitbucket.org/bdas/iio_sensors
https://lwn.net/Articles/370423/https://github.com/beta�ight/beta�ighthttps://archive.fosdem.org/2012/schedule/event/693/127_iio-a-new-subsystem.pdf
https://github.com/analogdevicesinc/libiio
https://www.youtube.com/watch?v=ealH3qP_pBE
https://archive.fosdem.org/2015/schedule/event/iiosdr/
https://www.cs.bu.edu/~richwest/index2.htmlhttps://github.com/intel-aero/meta-intel-aero/wiki
![Page 33: D R O N E S I T L B R I N G U P W I T H T H E I I O F R A ...€¦ · My experiments with bringing up sensors on a x86 board Understanding the IIO framework Interfacing the framework](https://reader034.vdocuments.us/reader034/viewer/2022042311/5ed8dab86714ca7f4768b111/html5/thumbnails/33.jpg)
31 . 1
WRAP UP NOTESRunning a �ight controller software as a processInterfacing with IIO appears to be straightforwardFurther investigation on latency and performanceRunning a PREEMPT_RT kernelMore experiments with af�nities