/Balance_On_Wheels

Modeling and Control of Two-Legged Wheeled Robot: In this project, we will be building a two wheeled robot (with a hip and knee joint) which can balance at variable heights including a provision for jumping.

Primary LanguageCMIT LicenseMIT

Table of Contents


About the Project

Modeling and Control of Two-Legged Wheeled Robot: In this project, we will be building a two wheeled robot (with a hip and knee joint) which can balance at variable heights including a provision for jumping.


Tech Stack

  • C
  • Python
  • SolidWorks
  • ESP-IDF
  • AutoCad
  • Creality

File Structure

πŸ‘¨β€πŸ’» Balance_On_Wheels
 ┣ πŸ“‚ CAD Designs                          
 ┃ ┣ πŸ“‚ Final Design for Laser Cut (3mm)                      
 ┃ ┣ πŸ“‚ Design For Laser Cut (5mm)           
 ┃ ┣ πŸ“‚ Intermediate Design              
 ┃ ┣ πŸ“‚ Prototype 2            
 ┃ β”— πŸ“‚ Prototype                  
 ┃  
 ┣ πŸ“‚ Examples                      
 ┃ ┣ πŸ“œ Jump Code
 ┃ ┣ πŸ“œ Mpu Readings Code
 ┃ ┣ πŸ“œ Mpu Readings and Servo Rotation Code
 ┃ ┣ πŸ“œ Printing Info on terminal using Wifi Code                     
 ┃ ┣ πŸ“œ Self Balancing Code
 ┃ ┣ πŸ“œ Self Balance Servo set zero Code
 ┃ ┣ πŸ“œ Variable Height Code
 ┃ β”— πŸ“œ OLED Code
 ┃
 ┣ πŸ“‚ Assets                          
 ┃
 ┣ πŸ“‚ Notes
 ┃  ┣ πŸ“‚ Arsh Notes
 ┃  β”— πŸ“‚ Shreyas Notes  
 ┃
 ┣ πŸ“‚ Model 
 ┃ ┣ πŸ“œ calculation_of_parameters.py
 ┃ ┣ πŸ“œ calculation_of_angle_from_parameters.py
 ┃ β”— πŸ“œ graph.ipynb
 ┃
 ┣ πŸ“‚ Components
 ┃ ┣ πŸ“‚ sra-board-component
 ┃ β”— πŸ“‚ rosserial_esp32 
 ┃ 
 ┣ πŸ“‚firmware                               
 ┃ β”— πŸ“‚ Self_Balancing_Variable_Height
 ┃   ┣ πŸ“‚ components
 ┃   ┃ ┣ πŸ“‚ include
 ┃   ┃ ┃ ┣ πŸ“œ websocket_server.h
 ┃   ┃ ┃ β”— πŸ“œ websocket.h
 ┃   ┃ ┣ πŸ“œ CMakeLists.txt  
 ┃   ┃ ┣ πŸ“œ Kconfig
 ┃   ┃ ┣ πŸ“œ websocket_server.c
 ┃   ┃ β”— πŸ“œ websocket.c     
 ┃   ┣ πŸ“‚ frontend
 ┃   ┃ β”— πŸ“œ index.html
 ┃   ┣ πŸ“‚ main 
 ┃   ┃ ┣ πŸ“‚ include
 ┃   ┃ ┃ ┣ πŸ“œ tuning_websocket_server.h
 ┃   ┃ ┃ β”— πŸ“œ wifi_handler.h
 ┃   ┃ ┣ πŸ“œ CMakeLists.txt  
 ┃   ┃ ┣ πŸ“œ Kconfig
 ┃   ┃ ┣ πŸ“œ self_balancing.c 
 ┃   ┃ ┣ πŸ“œ servo_set.c
 ┃   ┃ ┣ πŸ“œ jump.c
 ┃   ┃ ┣ πŸ“œ tuning_websocket_server.c
 ┃   ┃ β”— πŸ“œ wifi_handler.c
 ┃   ┣ πŸ“œ CMakeLists.txt
 ┃   β”— πŸ“œ sdkconfig
 β”— πŸ“œ README.md

Getting Started

Prerequisites

  1. Used Solidworks 2022 for Designing our Robot.

  2. Used Creality Software used for 3D Printing

  3. Used ESP-IDF v4.4 for building and flashing the code on ESP-32 Microcontroller.

  4. Used Python Scripts for calculation of specifications of Bot.

  5. Used Matplotlib for plotting the graphs.

Installations

  1. Clone the Repository

    git clone git@github.com:KudoC0nan/Balance_On_Wheels.git

  2. Install ESP-IDF on your System

    For Windows

    For Linux and MacOS

Execution

  1. Open ESP-IDF Terminal on Windows or Terminal on Linux

  2. Run get_idf in Linux.

  3. Goto The Repository

    cd Balance_On_Wheels

  4. Goto firmware folder

    cd firmware

  5. Goto Self Balancing Code at Minimum Height

    cd Self_Balancing_Variable_Height

  6. Run Command for Building the Code

    idf.py build

  7. Run Command for Opening the Configurations Tab to Setup the WIFI.

    idf.py menuconfig

    When running the above command it will open a Configurations tab.

    Then select Component Config option.

    Then search for Wall-E Configurations and select this option.

    Then select Wifi Config option.

  8. Run Command on Flashing the Code on our Bot.

    idf.py flash monitor


Theory And Approach

Design

  • Our First Approach was to design our robot on Solidworks.

    We designed a Bi-Pedal BOT on the Pantograph Mechanism, which is a mechanical linkage connected in a manner based on parallelograms.

    The Kinematics of the Bot were Derived for Pentograph design from which the key parameters such as the length of the linkages were able to be modified and optimized during the design process.

    The Hip Joint is defined to rotate in a 180 degree arc which results in the legs moving between Parallel and Anti-Parallel configurations. The angle between the vertical and the legs is shown for both the parallel and anti-parallel configurations and defined as the angles $\phi$ 1 and $\phi$ 2 as shown in Figure. The trapezoid which represents the body of the robot.

    In the above Figure Leg extension is defined as the variable L is the vertical distance between the axis of the hip joints and the foot joint. The leg is shown at minimum extension Lmin the anti-parallel configuration and at maximal extension Lmax in the parallel configuration.

    The above figure shown when the bot is at an arbitary position. Here,

    L1 ---> Length of Upper Leg Segment (From Hip Joint to Knee Joint)

    L2 ---> Length of Lower Leg Segment (From Knee Joint to Foot Joint)

    L3 --> Length from the Hip joint to the Mechanism's axis of Symmetry.

  • Equations Used To Derive the System Design Variables

    In Above Image we have equations to calculate the $\phi$ 1, $\phi$ 2, L1, L2 and L3 . Also In above Image at end , it is the General Equation of Length (vertical distance between the axis of the hip joints and the foot joint) which was used to plot the graph between the leg extension vs change in driver motor angle which is given below. Here, G (Gear Ratio) which is taken to be 1 for our Bot.

    The above Graph gives is about change of Leg Extension wrt change in Driver Motor Angle. In the middle, the slope is large. This means that small changes in motor angle cause a large amount of leg extension.

    Link To Python Script Used

    LInk to Python Script to Plot the Graph

  • CAD Design

    CAD design consist of 3D modeling of Bot design. We needed to check if various other aspects of systems and mechanical design satisfy our requiements. So CAD design form a very important part of our project.

    • Parts Description

      Parts Description
      Base plate: Dimensions - 95mm x 107mm and thickness 3mm. Houses the PCB, Servos, MPU and Buck converter
      Leg L1: Dimensions - 45mm length and 3mm thickness
      Leg L2: Dimensions - 90mm length and 3mm thickness
      Leg 2 Extended: 11mm length and 3mm thickness with 2.5mm x 10mm cut for N20 mount
      N20 Mount: Dimensions 15mm x 2.5mm x 10mm. It is the mount on the leg for N20 motor .
      Servo Mount: Servo mount for mounting them on th base plate.
      N20 Motor shaft extension: Dimensions - 1cm length and 3mm hole for N20 shaft to be fixed
      It is used as an extension for L1 to extrude it outwards in so that the legs can overlap. Dimensions: 20mm diameter and thickness 3mm
    • CAD Model of Bot

  • Specfications of Bot

    Lmax = 13 cm

    Lmin = 4 cm

    $\phi$ 1 = $45{\textdegree}$

    $\phi$ 2 = $15{\textdegree}$

  • Hardware Bot

Components

  • Bot Parts of Acrylic Material (Laser-Cutted)
  • N20 motor Shaft for Wheels (3D Printed)
  • SRA PCB
  • N20 motors
  • MG90 Servo Motors (Connected to all Hip joint)
  • Buck Converter (LM2596) (Regulates 12v to 5v for SRA PCB and 12v to 6v for N20 Motors)
  • Bearings
  • Shafts

πŸ“ Note: SRA Board Components

πŸ“ Note: N20 Motors

πŸ“ Note: Mg90 Servo Motors

PID

A PID controller is one kind of device used to control different process variables like pressure, flow, temperature, and speed in industrial applications.

PID stands for Proportional,Derivative and Integral controller. It is used in our Project for Self Balncing the bot.

For self balancing our bot should be able to minimize pitch error ,i.e, difference between current pitch angle to the initial angle of reference (Set point).

In self balancing P-Term reduces the pitch error, but this correction leads to instability and oscillations.

To prevent the oscillations of the bot along the setpoint, we use D-Term, which tries to flatten the error trajectory in horizontal line which it achieves achieves by damping the force of P term which prevents overshooting the setpoint

Sometimes applied Force is not enough to bring the error to zero (bot is in steady state),to correct this error, we use I-term, which will increase
force as the time passes and will correct the steady state error.

πŸ“ Note: More on PID Explanation

Code Phase

  • Here, we First wrote the algorithm for Self-Balancing using the PID controller for the bot.

    For self-balancing the bot, we need to keep the bot a bit above our desired angle (Setpoint), since the bot is very fast and will fall down once it's past the desired angle.

    The pitch angle is required for Self-Balancing which is obtained from the Inertial Measurement Unit(IMU sensor) plug-in.

    πŸ“ Note:Link to Explanation of Self Balancing Code

  • After Successful Run of Self Balancing Code, we than wrote the code for Servo moving from Maximum to Minimum Length (Variable Height).

    Link to Code

  • After that we wrote the code of integrating Self Balancing Code with servos locking up at Minimum Height or Maximum Height for Self Balancing of Bot. PID is used for balancing along with servo set zero which servos lock the bot in minimum height or maximum height simultaneously so that the bot can remain stable at that position or otherwise the bot may collapse. Also before Balancing the bot we set servo zero first and then the self balancing code starts to function.

    Link to Code

  • After Which we wrote the Jumping Code for Bot to Jump from Minimum Position.

    Here, basically we are increasing the Height of the Robot in iterations rather than in a single movement.

    This is because, such movement with appropriate delays produce a thrust which pushes the bot upwards.

    Such thrust is not produced is a single down-up movement.

    πŸ“ Note:Link to Explanation of Jump Code

    Link to Code

  • After finally we wrote the code for Self Balancing at Variable Height, which is self balance algorithm integrated with servo movement from maximum to minimum position (Variable Height).

    Link to Code


Results and Demo

  • Bot moving from Min to Max Height

    servo_sweep.1.mp4
  • Bot given forward velocity when castor attached

    Forward.Vel_Castor_attached.1.mp4
  • Self Balancing Code with servos locking up at minimum height

    Self_Balance_Min_Ht.mp4
  • Self Balancing Code with servos locking up at maximum height

    Self_Balance_Max_Ht.mp4
  • Self Balancing Code with servos locking up at medium height

    SelfBalance_MiddleHt.1.1.1.mp4
  • Jumping of Robot

    Jumping_Bot.mp4
  • Self Balancing at Variable Height

    Self_Bal_Variable_Ht.mp4

Future Work

  1. Movement on uneven terrains like stairs using jump.

  2. Implementation of LQR controller for balancing and position control

  3. Implementation of Roll Stabilization

  4. Segway Bot (Assistant Type Robot)

  5. For obstacle avoiding (using Ultrasonic sensors or Lidar and Computer Vision)

    Link to Algorithm


Troubleshooting

  1. Mounting of motors at wheel joint. As we were using BO motors wheels, we weren't able to use for our N20 motors. The fix was we designed a mount in Solidworks and 3D printed that mount.

  2. In the Original Design of our Bot, Gears were used. But then Gears were removed from the design, considering much torque was lost due to the gear mechanism. Instead, MG90s servos were used.

  3. Length of legs and distance from the AOS were reconsidered many times.

  4. Base plate of the bot had some design flaws regarding placement of holes for Servos and Mpu. Currently we have made holes manually by Drilling and the changes has been made in CAD Design.

  5. No holes made in Base plate to for Castor Wheels (castor wheel used for experimental purposes like checking torque and rpm of motors in forward and backward direction). Currently we have made holes manually by Drilling and the changes has been made in CAD Design.

  6. N20 heating up within a few moments of testing. As we were giving 12V directly to 6V N20's due to which they were heating up. To fix this issue ,we used a LM2596 buck converter to convert the 12V to 6V.

  7. During a few tests of Jumping, we found that the MG90 Servo gears either got broken or got misaligned due to high strain (sudden Jerk) on it during jumping. To fix this issue, we opened the Servos and tried fixing it and if the gear was completely broken we had to replace it with spare Mg90 servos or in worst case used Sg90 servos until the workaround is found or to perform some other tasks.


Contributors

Arsh Khan

Shreyas Patil


Acknowledgements and Resources

Special Thanks to Our Mentors Marck Koothoor,Ayush Kaura,Priyal for Mentoring and Guiding us in our project.

Special Thanks to SRA VJTI for giving us the chance to do the project.

Resources

  1. ESP-IDF Docs

  2. SOLIDWORKS Playlist

  3. Reserach Paper for Reference (MIT Paper of Balancing and Jumping of Mono Pedal Bot

  4. Research Paper for Reference (Czech Technical University)

  5. Reference Paper for PID


License

MIT Licence