EnglishSvenska

This post is automatically translated to English by Google Translate.

Självbalanserande ARM (uppdaterad och bättre)

Simplicity is the ultimate sophistication. I den förra versionen av den självbalanserande roboten använde jag totalt 3 mikroprocessorer men har nu designat och programmerat om den på en större ARM mikroprocessor. Med mer kräm i processorn ges en mängd fördelar:

  • Färre komponenter
  • Enklare kretsschema
  • Robust mekanisk design på grund av färre kablar
  • Ingen kommunikation mellan processorer är nödvändig vilket ger en mycket enklare kod
  • Ett litet RTOS sköter trådhanteringen (vilket inte gick på AVR)



Så bygger man en likadan (eller bättre)

Komponenter

Mekanisk design

Läs de äldsta inläggen på projektsidan för att se foton från hur man bygger ihop den. Det enda som behöver tillverkas är de tre plattorna för vilka det finns CAD och ritningar.

Kretsschema

Många har frågat om kretsschema så jag gjorde ett i Altium Designer.

Mjukvara

All kod ligger på Github.

Reglerteknik

Kort använder jag kaskadåterkopplade PID-regulatorer. Den yttre loopen reglerar hastigheten på roboten vilket mäts på tachometrar på motorerna. Den intre loopen reglerar robotens vinkel vilket mäts med en IMU. Den yttre loopen har långsam dynamik och den intre loopen är mycket snabbare. Rent teoretiskt ska det gå att göra en självbalanserande robot med endast den inre loopen men man får väldigt lätt ett beteende av att roboten långsamt rör sig framåt eller bakåt över golvet eftersom återkopplingen från hjulens hastighet saknas.

För att få ytterliggare bättre prestanda används gain scheduling på den inre loopen vilket innebär att regulatorparamterarna ändras beroende på robotens vinkel. En liten vinkel nära jämviksläget innebär konservativa regulatorparametrar där endast små justeringar görs för att hålla roboten stående. Är vinkeln stor är roboten nära att ramla och de aggressiva paramterinställningarna aktiveras med syfte att göra allt för att återfå stabilitet.

Information flow

Information flow

Cascade PID implementation theory

Cascade PID implementation theory

Ändra parametrar

Troligtvis kommer alla parametrar inte fungera utan att de justeras något. I koden finns en struct som kan sättas i setConfiguration(). Smartare är dock är att använda en seriell terminal för att ändra parametrar samtidigt som koden körs. På så sätt behöver man inte programmera om processorn varje gång man vill ändra en parameter. Öppna Serial Monitor i Arduino. Testa att skriva "print configuration" till Arduinon. Om allt fungerar som det ska kommer den svara med att skriva ut alla parametrar. Alla variabler i structen Configuration kan sättas från terminalen. Skriv bara "set" följt av variabelnamn och värde. Exempelvis "set speedPIDKp 1.5". För att aktivera debug skriver du "set debugLevel 2". Om du vill debugga IMU skriver du därefter "set angleRawDebug 1". För att stänga av en debug-variabel skiver du exempelvis "set angleRawDebug 0".

Att hitta rätt regulatorparametrar

Använd en realtidsplotter när du ställer in dina regulatorparametrar så går det enklare.

Tagged with: , , , ,
Posted in Självbalanserande robot
22 Comments »Självbalanserande ARM (uppdaterad och bättre)
  1. Rand Vibe says:

    Hello,

    Very interesting and clean balancing robot. Can you elaborate on how you fed back the encoder speed and position? Your "Cascade PID implementation theory" diagram in your website shows "Speed Error" converted to "Angle Setpoint" in the outer control loop. How do you get robot angle from encoder speed? Thank you.

    Rand

  2. sebnil says:

    I dont get robot angle from encoder speed. Encoder speed is measured, and so is robot angle. Encoder speed is used in the outer loop PID controller, and the output is used as angle Setpoint in the inner loop.

    /Sebastian

    • Jean Khoury says:

      Hello Sebastian,

      the encoders count the number of ticks ( incremental or decremental ) depending on the sens of the wheels. Just wanted to know how do you calculate the speed out of it, since it's the input for the outer loop, am I correct? or did you just use the number of counts as input and the derivative Term of the PID is actually the one calculating the speed?

  3. Rand Vibe says:

    So you're saying you have a separate PID calculation using the encoder measurements to come up with the Tilt-Angle-Setpoint that feeds the main Tilt-Angle PID controller.

    Since you have a separate outer-loop PID calculator, do you feed it more than encoder velocity (D term), and include position (P term) and integral of encoder position (I term)? Is this outer loop calculated at the same sample rate as the main loop?

    Thanks.

    • sebnil says:

      Encoder velocity is actually the P term. (D term is angular accellerationm, and I term is postion). Read the code to get sample rates and so on.

      /Sebastian

  4. Rand Vibe says:

    Okay, I got my balancing robot to finally work using encoder position and velocity using the same sample rate as the main PID loop.

    Before the encoders, my bot would balance nicely, but would slowly drift and oscillate. I then put in the encoders but had trouble deciding how to implement the measurements in the feedback loop.

    Thanks for your help. I'll try removing encoder position and put in acceleration as you suggested. My guess is that it will be a bit noisy as was velocity, so I may need to filter acceleration. I'll try it with and without filtering. Too many filters contribute to the overall system lag, which is especially not good for unstable systems.

    • sebnil says:

      Nice! Please post a link to a youtube clip or something. It would be interesting to see how it behaves.

      And you are right. The lag is a problem for inherently unstable systems. The trick with using cascaded PIDs (inner and outer loops) is that the inner loop is fast without much lag, and the outer loop is slow and is filtered much more. It means that the angle is corrected quickly and the speed is corrected much slower.

  5. scolog says:

    Hi

    Great project <3, what type of ARM processor did you use?

    I'm new to this and was thinking of trying to recreate your design..

    Do you think you could build a BB8 (Star Wars 7) robot...?

    scolog

  6. Gabriel says:

    Hello Sebastian,

    I am interest with your projects"Self-balancing ARM and Realtime data plotter", I want to learn more about your projects, I have some questions about your projects
    1. Why speed need and use kalman filter in your projects?
    2. About your PID cascade (speed setpoint 0 -> SpeedPID -> angle setpoint -> AnglePID -> motor voltage),whether the motor voltage controlled speed and angle simultaneously or motor voltage controlled individually (voltage motor-> speed, voltage motor-> angle) or the motor voltage is controlled only angle?
    3. How did you tune the PID and kalman filter so the self balance robot work fine? Are you tuned it with the console on the top just trying new values or the calculation of the mathematical model?
    Thank you Sebastian

    Regards,
    Gabriel

    • sebnil says:

      1. Because the signal is noisy.
      2. Please read the control theory bit. It explains how the loops are done. But voltage to motors control angle. Angle != 0 will give you an accelleration of the robot, which will give you a speed. Speed setpoint is always 0 though.
      3. Manually just tried myself to values that work. No modelling.

      /Seb

      • Gabriel says:

        Thanks for the reply, can i use Arduino Motor Shield Rev3 for motor controller in arduino due? because the Arduino Due board runs at 3.3V. The maximum voltage that the I/O pins can tolerate is 3.3V. Applying voltages higher than 3.3V to any I/O pin could damage the board.
        Thank you Sebastian

        Regards,
        Gabriel

  7. Kenny says:

    That's a great bot, and nice information regarding the usage of encoders to change the bot behaviour depending on whether the bot is operating close to equilibrium or not. Would be nice to have 1 more video where the bot stays in the balanced (no movement) position for say 10 seconds or so. Great work.

  8. Kenny says:

    If the outer loop develops a velocity error signal, which then goes through a PID controller, and then fed into the inner loop as a 'set point' signal, then placing the bot at a tilted angle (but at zero velocity) would lead to an angle set point of zero, right? Does this mean that the tilted position at which the bot was placed becomes 'zero' reference angle?

    • sebnil says:

      Yes, if I understand you correctly. For example, you should be able to have the robot stand still on a tilted surface with a angle offset.

      Also the zero angle almost never is absolute zero. It is difficult to calibrate the zero angle perfectly. In practical use the reference angle when the robot is standing still at close to zero velocity will not be zero in angle. Hope that clears things up.

  9. Gabriel says:

    Hello Sebastian,
    My robot and feedback motors worked well with no problems, I 've changed the parameters so that the robot can be stable balanced as your video on youtube but My Robot can't be stable balanced,
    I use SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345,Whether the location of the sensor affects the balance of the robot in addition to heavy robot and point of weight the robot? Where the exact location sensor that the robot can be balanced with stable? or i must use 9 Degrees of Freedom IMU so that the robot can be stable balanced?

    Thank you Sebastian

    Regards,
    Gabriel

    • sebnil says:

      Yes, location of the sensor will affect the raw data. If the sensor is far from the wheel axis you will probably need to compensate for it. 6 DOF should be fine depending on how you place it. Good luck!

      • Gabriel says:

        Thanks for the reply, I will try
        how to determine configuration.calibratedZeroAngle , whether from the calculation angleRaw or roll angle IMU sensor? I define configuration.calibratedZeroAnglfrom the calculation angleRaw ? Is that true?

        Thank you Sebastian

        Regards,
        Gabriel

  10. Gabriel says:

    Hello Sebastian,
    My robot and feedback motors worked well with no problems, I 've changed the parameters so that the robot can be stable balanced as your video on youtube but My Robot can't be stable balanced,
    I use SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345,Whether the location of the IMU sensor affects the balance of the robot in addition to heavy robot and point of weight the robot? Where the exact location IMU sensor that the robot can be balanced with stable? or i must use 9 Degrees of Freedom IMU so that the robot can be stable balanced?

    Thank you Sebastian

    Regards,
    Gabriel

  11. Gabriel says:

    Hello Sebastian, in your code arduino Selfbalancing-robot-v2

    else if (abs(anglePIDInput) > 30){
    // fell down
    started = false;
    }
    whether the program is used to determine the angle of the robot falling ? how to determine the value of the angle parameter robot fall ?

    Thank you Sebastian

    Regards,
    Gabriel

  12. Escape Velocity Labs says:

    I'm developing the Falling-Up Robot, a balancing inverted pendulum bot, using the Teensy 3.6 microcontroller with Arduino IDE 1.6.12. I want to practice feedback control systems with this robot. I want to keep it from falling over while roaming autonomously and interacting with its environment. I'm building this in stages. So far, the brain and chassis is in place, and the basic balancing control system is in place. Here's the first video.

    https://youtu.be/Xmt67HTI2Hg

    I used stepper motors to take advantage of high torque at low RPM and zero backlash (or zero freeplay). Dealing with the high mechanical vibration was an issue, but was solved with analog filters and an Extended Kalman Filter in software.

Leave a Reply

Your email address will not be published. Required fields are marked *

*