EnglishSvenska

This post is automatically translated to English by Google Translate.

Den självbalanserande roboten fungerar ganska bra




I videon kan man se att roboten håller sig på någorlunda samma ställe på golvet och klarar av att ta emot lättare stötar. För att uppnå detta kaskadkopplade jag två PID-regulatorer och la till lågpassfilter på både hjulens rotationshastighet och robotens lutning.

Mikroprocessorer

Eftersom en Arduino inte har väldigt mycket processorkraft valde jag att använda totalt 3 mikroprocessorer:

  1. En standalone Arduino Uno tar pulser från varvtalsmätaren på varje hjul och omvandlar detta till en hastighet. Hastigheten skickas till huvuddatorn.
  2. En till standalone Arduino Uno för att visa och justera parametrar. Driver också displayen. Parametrarna skickas till huvuddatorn.
  3. Arduino Leonardo är huvuddatorn. Den tar emot information från konsolen och motorhastighetsmätaren via I2C.

Reglerteknik

Två kaskadkopplade PID-regulatorer. Den första har hastighet som setpoint (alltid 0 i det här fallet) och lutning som output. Om roboten rullar framåt kommer regulatorn att få ett positivt är-värde och skicka ut en negativt utsignal. Detta innebär att roboten kommer att vilja luta bakåt för att bromsa upp hastigheten.

PID-regulatorn nummer 2 tar hand om robotens vinkel relativt golvet. Börvärdet är utsignal från den tidigare PID-regulatorn. Normalt kommer börvärdet att variera från -3 till 3. Noll motsvarar att roboten ska stå helt rakt upp. Utsignalen kopplas till motorstyrningen och varierar från -100 till 100. -100 motsvarar full spänning till motorerna i bakåtriktning.

För att få renare insignaler används FIR-filter på både vinkel och hjulens hastighet. Lågpassfilter gör att snabba förändringar (exempelvis sensorbrus) inte släpps igenom.

Till vinkeln relativt golvet används en IMU med accelerometer och gyro. Ett komplementärfilter kombinerar signalerna från dessa och ger en utsignal som går att använda.

Källkod

Jag hade som mål att all kod till detta projekt ska vara öppen och finnas att hämta på github. I readme finns länkar till bibliotek jag använt.

Förbättringar som skulle kunna göras

  • Bättre parametrar till FIR-filter. Mycket skulle nog kunna göras på hjulhastigheten för att inte få en lika hackig gång.
  • On-the-fly-programmering över luften med Xbee. Detta gör att man kan skicka helt ny kod till roboten utan usb-kabel. Gör programmeringen smidigare.
  • Radiostyrning vore kul.

Foton

Komponenter

Lägger också upp cad och ritningar.

Tagged with: , ,
Posted in Självbalanserande robot
18 Comments »Den självbalanserande roboten fungerar ganska bra
  1. Lukas says:

    Riktigt kul att se. Bra jobbat

  2. Magnus says:

    Kul!
    Tror du att det skulle bli lättare att få roboten att balansera "stabilare" om stängerna inte flexade så mkt... fler hyllplan?

    • sebnil says:

      Stängerna är någorlunda stabila även om det kanske inte syns i videon. Det jag tror skulle göra störst skillnad just nu är bättre filtrering på insignalen från hjulens hastighet. Bättre lågpassfiltrering skulle nog göra gången mycket behagligare.

  3. chay says:

    !!!

    You wrote:
    -->
    The setpoint is the output of the previous PID controller. Normally, the setpoint will vary between -3 och 3 där 0 corresponds to the robot to stand completely straight up.
    <--

    I don't understand och or dar and a google search hasn't helped. I wonder what these terms mean. Any chance you could point me to a reference or give me a short explanation?

    Great project. Thanks for sharing.

    • sebnil says:

      It is a bad automatic translation. Should be "Normally the setpoint will vary between -3 and 3 where 0 corresponds to the robot standing completely straight.". So the output from the first PID will be an angle between -3 and +3 angles.

  4. geejay says:

    1. arduino for reading accelerometer and gyro, convert them to angles in degrees then send to the leonardo
    2. another arduino for just reading the motor speed and direction, then send it to leonardo
    3. the leonardo then read the PID parameters for the wheel and angle, then control motors? is this the way it works? or you can elaborate further?

    • sebnil says:

      No but quite close.
      1. Arduino for reading motor speed and direction.
      2. One arduino for the console. Drives the lcd and the buttons.
      3. Arduino Leonardo with motorshield as the brain. Communicates with 1 and 2 via i2c. Reads angle from the IMU (also via i2c). Handles the PIDs and outputs voltage to the motors.

  5. geejay says:

    No but quite close.
    1. Arduino for reading motor speed and direction.
    2. One arduino for the console. Drives the lcd and the buttons.
    3. Arduino Leonardo with motorshield as the brain. Communicates with 1 and 2 via i2c. Reads angle from the IMU (also via i2c). Handles the PIDs and outputs voltage to the motors.

    -------

    If this is the case, I can only use two arduino if I will be using potentiometers to set the PID values and no LCD display.

    All PID's exist in the leonardo and even the reading of the angle from the IMU only the motors has dedicated mcu for interpretation of the wheel encoders..

    In your source codes, which is for the 1st arduino, 2nd arduino and for the leonardo? thanks.

  6. Rick Bonart says:

    I was wondering if you might help me. I have succesfully used my arduino and a 5DOF analog IMU to accurately get my robots tilt with a complimentary filter.

    My difficulty is making the thing balance. My first attempt was to simple use the map function input from the IMU to 0 to 255 and sent it to a Sabertooth motor controller. It kind of works but was very jittery.

    Then I advance to the PID library. But very hard to tune. It drifts. I can send my code and processing graph. Any tips?

    • sebnil says:

      Do you have any feedback from the speed of the robot? Mine drifted a lot and that is why I have two cascaded PIDs instead of just one. Here is a video without feedback from wheel speed http://www.youtube.com/watch?v=gl07a232G98
      You can see that it drifts quite a lot.

      • Rick Bonart says:

        I do have the ability to get encoder position and but haven't implimented yet. I'm having a great deal of difficulty with basic balancing. If I could make mine balance like yours in the video link with drift I would consider myself very well off.

        I used the PID library developed by Brett but can't make it work.

        What did you use for input, setpoint and tuning.

        I used an a mapped quantity from the IMU for input: input = map( compAngle, 57,117,0,255);

        That's 8 bit resolution to an adjusted verticle angle of 87degrees. I used 127 as the setpoint.

        Problem is the PID output is zero at verticle and scale for one direction of tilt to 255 but won't go below zero in the oposite direction.

        • sebnil says:

          > What did you use for input, setpoint and tuning.
          Input is the angle. 0 means it is standing straight.
          Setpoint 0.
          For tunings see https://github.com/sebnil/Selfbalancing-robot/blob/master/selfbalancingrobot/configurations.txt

          >Problem is the PID output is zero at verticle and scale for one direction of tilt to 255 but won’t go below zero in the oposite direction.
          This is a problem. You will not get it working without an input error that is either negative or positive depending on the angle. Try to rotate the dof to see if that solves the problem.

          • Rick Bonart says:

            OK I tried again using the raw angle as input and changing setpoint to zero (vertical). The input error as I tip robot side to side has both positive and negative values. But the output increases in value as robot tips to one side but once I reach the setpoint zero and tip to other side the output will not change.

            It's definitely the problem, but it's the PID. Or a least that's what the processing graph shows. And correlates to the documentation that output will be 0 to 255. I'm just stuck on how to make zero degree tilt equal 127 output. Which would be balanced for the motors.

  7. Rick Bonart says:

    The issue is resolved. I just needed to use the SetOutputLimit function. Now the output is scaled.

    May I ask how did you tune the PID?

    • sebnil says:

      Good to hear! I tuned it with the console on the top just trying new values. I figured that I needed quite large values to keep it stable. Perhaphs I will do a proper mathematical model in the future but probably not.

  8. shoaib says:

    can u tell me the name of microcontroller gyrometer and accelerometer and pid use in it... so that i easily purchase thm from market.. thanx

Leave a Reply

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

*