BeagleBoard/GSoC/2021 Proposal/DhruvaGole

=Proposal for librobotcontrol support and Robotics Cape Compatibility for Beagleboard AI =

About Student: Dhruva Gole Mentors: Jason Kridner Code: librobotcontrol Wiki: http://elinux.org/BeagleBoard/GSoC/ProposalTemplate GSoC: GSoC entry

=Status= This project is currently just a proposal.

=Proposal= Completed all the requirements listed on the ideas page. The code for the cross-compilation task can be found here submitted through the pull request #149.

About you
IRC: dhruvag2000 Github: https://github.com/DhruvaG2000 School: Veermata Jijabai Technological Inst. Country: India Primary language : English, Marathi, Hindi Typical work hours: 10AM - 7PM Indian Standard Time Previous GSoC participation: I find embedded and IOT pretty interesting, given I have experience with ESP32, SIMCOM, ESP8266, Arduino UNO I think I will be able to excel in this project. This is the first time i am participating in GSoC.

About your project
Project name: librobotcontrol support for the Robotics Cape with the BeagleBone AI

Description
BeagleBone gets used a lot in automation tasks, be they in industrial, building, home or otherwise. Software that helps enable individual hobbyists, but can bridge into professional automation tasks, is strongly desired. The Robot Control Library package contains the C library and example/testing programs for the Robot Control project. This project began as a hardware interface for the Robotics Cape and later the BeagleBone Blue and was originally called Robotics_Cape_Installer. It grew to include an extensive math library for discrete time feedback control, as well as a plethora of POSIX-compliant functions for timing, threads, program flow, and lots more, all aimed at developing robot control software on embedded computers. The Robotics Cape (ref) brings the power of the BeagleBone Black to your robotics project with almost no setup time. Built by engineers for engineers, the Robotics Cape is loaded with innovative features and a library designed to effortlessly take your robotics concepts from design to reality. (source) It has the following Technical Specifications :- One may think that all BB Boards have the same form factor and run linux so where does the question of incompatibility arise right? To answer that question, let's just have a look at both their processors, actually they don't have common pins as BB AI has am572x and other beagleboards have am372x. As seen from the led library file and line 54 of led.c file that help control the LEDs on Robotics Cape and BeagleBone Blue, we initialize a single led file descriptor. like this, SYSFS_LED_DIR "%s" BRIGHTNESS_FILE, paths[(int)led] where SYSFS_LED_DIR is /sys/class/leds/ and BRIGHTNESS_FILE	"/brightness" and paths[(int)led] adds the LED number (eg. 0 for green). Let's say that user wants to control RC_LED_GREEN, which is at suppose gpio1_0 in the BBBWL/BBB + Robotics Cape. But this may not be the case, as the green LEC maybe at a different GPIO in the BBAI+Robotics Cape. (refer here). Similarly, ADC, PWM, eCAP, LCD, etc. have differences in the way that their Header Pins are linked in the system. This can cause massive issues while using the current version of Robot Control Library, as it takes into account only the BBBWL/BBB pins. Thus it is essential that we modify the libraries and maybe some of the DT overlays to support the BBAI without breaking support for the BBBWL/BBB.
 * Introduction
 * Robot Control Library
 * The Robotics Cape
 * 1) 2 Cell Lipo Charging, Balancing, and Protection
 * 2) Battery Charge Inidcator LEDs
 * 3) 4 H-Bridge DC Motors Controllers 1.2A each
 * 4) 8-Channel Servo/ESC Output Enabled by PRU
 * 5) 6V 4A Regulated Power Supply to Protect Servos
 * 6) 9-Axis IMU: Invensense MPU-9250, and many more on-board peripherals that any robotic enthusiast or developer can want!
 * Why does incompatibility arise?

Device tree overlays are a very important part of the main idea of this project which is to make the same user-space examples work with both BeagleBone Black and AI. The same references will be used in the drivers for peripherals assigned to the same pins between Black and AI. (ref) Although this has partially been done as part of GSoC2020(by lorforlinux, project proposal ), DT Overlays for the Robotics Cape were yet to be written. This project aims at resolving all such issues and providing DT Overlays for the Robotic Cape on the BBAI. The most recent issue has been raised here which indicated the need of BBAI users to use the librobotcontrol package on the BBAI, for which it will be necessary to make few changes in the libraries and add a few more DT overlays to expand cape compatibility to the Robotics cape
 * Device tree overlays

Built on the proven BeagleBoard.org® open source Linux approach, BeagleBone® AI fills the gap between small SBCs and more powerful industrial computers. Based on the Texas Instruments AM5729, developers have access to the powerful SoC with the ease of BeagleBone® Black header and mechanical compatibility. BeagleBone® AI makes it easy to explore how artificial intelligence (AI) can be used in everyday life via the TI C66x digital-signal-processor (DSP) cores and embedded-vision-engine (EVE) cores supported through an optimized TIDL machine learning OpenCL API with pre-installed tools. Focused on everyday automation in industrial, commercial and home applications. It uses the Dual Arm® Cortex®-A15 microprocessor subsystem and further specs can be found on the official website
 * Why to port it to the BeagleBone AI?

What I like most about librobotcontrol, is that it allows new users to get a very intuitive hardware interface for the board it is being used on. Currently it only supports Robotics Cape and the BeagleBone Blue and Black. But with the evolution of AI on the edge, porting this library to be used onboard the BeagleBone® AI will prove to be very useful to a lot of hardware enthusiasts, AI/ML developers and hobbyists to deploy edge computing solutions along with easy to program hardware.


 * Features to be implemented:
 * 1) Implement the librobotcontrol package to support the BeagleBone® AI.
 * 2) Implement all the existing examples to run on BeagleBone® AI.
 * 3) Add the necessary docs on librobotcontrol website.

Details of implementation
The above cape needs the Robot Control Library (ref documentation) to function. Currently, this is only available for the BeagleBone Blue and Black. However, the BeagleBone® Blue lacks TI C66x digital-signal-processor (DSP) cores and embedded-vision-engine (EVE) cores which the AI board has. This enables machine learning tools to be integrted with a device capable of programmable hardware IOs. However it still lacks a proper hardware interface which is where the need to provide librobotcontrol support comes in. The beaglebone AI has many programmable PRU General-Purpose Output and Input pins as give on device docs page Implement all libraries under Robot Control Library (repo here to simplify tasks like writing to a pin, reading from a pin, delay, motor control, etc. Most recent PR#183 that was merged to the official librobotcontrol repository has done addition of BeagleBone AI model in the makefile and model.h header files. Other than that it has been able to get adc, LEDs, and servos working under the version 1.1. This project aims to continue on those lines to support the rest of the cape support for BBAI.  I intend to port as many examples as the board can support using it's hardware to the examples directory.
 * Reimplement stock examples in librobotcontrol repository
 * 1) bare_minimum
 * 2) blink
 * 3) read and write operation of UART buses
 * 4) test_adc and many such more...

Inorder to accomplish the above tasks, I will go through the pins of the beagle AI and accordingly make changes in the header files. For this, I have familiarized myself with the device tree for BeagleBone® AI. Also, I will be using the SRM(System Ref. Manual) which is given on this page and the BeagleBone cape interface spec is here. This is a list of symlink interfaces based on BeagleBone Cape header pins. and many more like ADC, PWM, eCAP, LCD, etc. have differences in the way that their Header Pins are linked in the system. The current librobotcontrol version running with the Device Tree Overlay in place here seems to be causing issues with the PWM, eQEP, and i2c. Thus I will be working on adding more stability to the robotics cape compatibility and then once the interfaces (links) are stable, update the library. One can find the template for the Device tree overleays here. Only Pins that are being actively used are to be commented out. It can be seen below from the device tree overlay syntax bone_i2c_1: &i2c5 { symlink = "bone/i2c/1"; }; that at location bone/i2c/1 is the symbolic link pointing to i2c5 port. If you look this up Code: &ocp { P9_18_pinmux { pinctrl-0 = <&P9_18_i2c_pin>; }; /* i2c sda */ P9_17_pinmux { pinctrl-0 = <&P9_17_i2c_pin>; }; /* i2c scl */ }; In the BBB /dev/bone/i2c/1 points to I2C1, but in the BBAI to I2C5. The above overlay fixes that by using the DT Overlay mentioned above. However, the above mentioned issue contains the following errors: ERROR: i2c1 driver not loaded ERROR: i2c2 driver not loaded Upon further investigation, I was unable to find the proper code in the librobotcontrol repo that enables BBAI support for the rest of the I2C ports. Also, ERROR: ti-pwm driver not loaded for hrpwm0 ERROR: ti-pwm driver not loaded for hrpwm1 ERROR: ti-pwm driver not loaded for hrpwm2 ERROR: ti-eqep driver not loaded for eqep0 ERROR: ti-eqep driver not loaded for eqep1 ERROR: ti-eqep driver not loaded for eqep2 All these errors indicate that even though cape compatibility at the Device Tree Level has been brought to the BBAI to somewhat make it look like a BB Blue, there are still many changes lacking in the user space code that constrict the full usage of librobotcontrol package. Thus my work will aim at first creating the overlay for Robotics cape! and adding user space code in librobotcontrol. I will also be testing everything to ensure that no bugs are encountered after the period of my project gets over. For example, if the code is built on a BBAI, the function rc_model which prints the current BealgleBoard model the software is running on. I will add if conditions like if(rc_model==MODEL_BB_AI || rc_model==MODEL_BB_AI_RC) inside which will be code written specific for the BBAI keeping it's pins in mind. In the else condition will be the code for the regular Blue and Black, so that while adding BBAI support, the blue and black boards are not made obsolete. Macros like ADC2AI(x) (x==0?4:(x==1?6:(x==2?7:(x==3?5:(x==4?3:(x==5?2:(x==6?0:-1))))))) will have to be written, in this case the ADC pins are reconfigured to match the BBAI pins. However similar steps will have to be followed to enable compatibility with the rest of the pins as well. The project requires the use of the device tree compiler (dtc) for compiling the device tree source (ex. *.dts, *.dtsi) files. It also uses the C programming language for re-programming the headers and source files and the gcc compiler along with other build tools will be used for compiling the C source code (*.c).
 * The How
 * 1) LEDs: The compatibility layer helps in connecting an LED driver to any GPIO pin and using the LED driver instance name to map to the same header pin, despite whatever GPIO it is on. (see here. For example, in the BBBWL/BBB, /sys/class/leds/led_P8_03 links to gpio1_6 whereas in the BBAI it is linked to gpio1_24. It is to be noted that pins gpio3_18,19,20 that are there in BBBWL/BBB are simply non existent in the BBAI.
 * I2C: Compatibility layer provides simple I2C bone bus nodes for creating compatible overlays for BBBWL, BBB, & BBAI.
 * SPI: SPI bone bus nodes allow creating compatible overlays for BBBWl, BBB, & BBAI.
 * 1) UART: UART bone bus nodes allow creating compatible overlays for BBBWl, BBB, & BBAI.
 * DT Overlays level
 * user space level
 * Software required and Programming Languages:

Hardware required:
The hardware listed below will be necessary for testing that my code implementation work correctly on the hardware.
 * 1) BeagleBone AI.
 * 2) BeagleBone Robotics cape:
 * 3) Robotics Cape.
 * 4) Additional hardware for using capes:
 * 5) JST SH Jumper 4 Wire and 6 Wire.
 * 6) Grove Universal 4 Pin to Beaglebone® 6 Pin Female.
 * 7) Grove Universal 4 Pin to Beaglebone® Blue 4 Pin Female.
 * 8) Servo motor.
 * 9) DC Motor.
 * 10) Groove Modules:
 * 11) Grove - Servo.
 * 12) Grove - Vibration Motor.
 * 13) Grove - Line Finder v1.1.
 * 14) Grove - I2C Color Sensor V2.
 * 15) Grove - Rotary Angle Sensor.
 * 16) Grove - Adjustable PIR Motion Sensor.
 * 17) Grove - 6-Position DIP Switch.
 * 18) Grove - 16x2 LCD (White on Blue).
 * 19) Grove - Speaker.
 * 20) Grove - Buzzer.
 * 21) Grove - GPS Module.
 * 22) Grove - Digital Light Sensor - TSL2561.
 * 23) Grove - Temperature Humidity Sensor (High-Accuracy & Mini).
 * 24) FTDI Serial TTL-232 USB Cable.
 * 25) SD Card Reader.
 * 26) SD Card
 * 27) 5V 3A USB type-C power supply
 * 28) Must have lab tools like:
 * 29) Solder, flux, and soldering iron.
 * 30) Screwdriver set.
 * 31) Tweezers and pliers.

Experience and approach

 * 1) I have used C++, C and Python programming languages over the past 3 years in a variety of projects involving embedded systems using the ESP32, Arduino UNO, ESP8266 and am also well-versed with freeRTOS.
 * 2) I have an aptitude for writing good reports and blogs, and have written a small blog on how to use a debugger.
 * 3) I recently did a project using ESP32, in which I used the DHT11 sensor to display humidity and temperature on a local HTML server . Other than that I have worked on developing hardware and making documentation for a 3 DOF arm based on an ESP32 custom board.
 * 4) I also interned at an embedded device startup where I
 * 5) Interfaced ADS1115 ADC with the ESP32 and used it to read battery voltage.
 * 6) Used UART for ESP32 and SIMCOM SIM 7600IE communication to gain LTE support.
 * 7) Published local sensor data to the cloud via LTE.
 * 8) I actively contribute to open source (most recently, I contributed to the ADS1115 library for ESP32 on the unclerus repo and can be seen here).
 * 9) Currently I am working on designing a Development board for the Raspberry Pico (RP2040) using KiCAD.
 * 10) I also do a lot of mini projects throughout the year, you can find my several more interesting projects at my github page

Contingency
I believe that if I get stuck on my project and my mentor isn’t around, I will use the resources that are available to me. Some of those information portals are listed below.


 * 1) Derek Molly's beagle bone guide provides all the information needed for getting up and running with my beagle.
 * 2) Content on e-ALE.org is very useful for information that ranges from tutorials and walkthroughs to the level of very advanced stuff.
 * 3) BeagleBone cookbook from Mark A. Yoder & Jason Kridner is the best source for test projects during the prototyping period.
 * 4) The technical reference manuals provided by TI on am3358 and am5729 are the best source for getting the insights on the SoC used in Black and Ai.
 * 5) Beaglebone: Introduction to GPIOs - Using Device Tree Overlays

(above is referred from here )

Benefit
librobotcontrol uses specific GPIO, I2C, SPI ports and the indexes all need to be updated to use the Cape Compatibility layer in a way that causes old BeagleBone Black + RC and BeagleBone Blue without the Cape Compatibility layer not to break.
 * -Jason Kridner

You have to write DT overlay for robotics cape and change the sysfs references in library.
 * -Deepak Khatri