Arduino Forum

Products => Arduino Education Kits => Arduino Engineering Kit => Topic started by: glenz on Nov 24, 2018, 04:16 pm

Title: PID parameters for self-balancing motorcycle
Post by: glenz on Nov 24, 2018, 04:16 pm
I would like to hear about the experiences of some other members regarding tuning the PID controller of the motorcycle.   I have had very little success  after several weeks of attempts to get the motorcycle to stay upright for more than 20 seconds.  I have the 6V motor, if that is significant. I have been "playing" with the parameters Kp, Kd, gain, and bias. The inertia wheel will never do more than one "zero crossing" before falling.
Even when it is temporarily  upright the slightest puff of wind will send it into instability from which it cannot recover. There is one video on You Tube which shows the motorcycle in stable motion but he/she does not respond to my enquiries. I have had some experience in writing/tuning PIDs in the context of straight line travel of wheeled robots so I am not totally naive. (I wish the inertia wheel was a laterally directed propellor)
My most successful parameter values are Kp = 80, Kd = 10, gain = 0.1, bias = 0.87
Am I the only one having this problem?
Title: Re: PID parameters for self-balancing motorcycle
Post by: Ajaj on Nov 26, 2018, 08:32 am
From my initial testing the bike has a number of problem making it not so stable. You can achieve some stability but it's not very robust.
First the motor max torque is low compared to the vehicule it should keep upright so it will easily saturate the controler.
Second it has to be very well balanced or "biased" or the wheel will quickly pick up speed and stop generating torque.

A motor with a bigger Torque constant would help, also a the algorithm should include dynamic bias to compensate for equilibrum offset and also speed compensation to to alleviate back EMF effect.
It would be more robust this way.
Title: Re: PID parameters for self-balancing motorcycle
Post by: gzwicker on Nov 26, 2018, 08:04 pm
Hi Ajaj,
  Thanks for responding.  Your comments mirror my thoughts exactly. Without dynamic bias adjustment gravity will win every time because it is relentless while the supply of (counter-torque x time) that can be supplied by the inertial wheel is very limited.
   Today I added a Ki branch to the controller circuitry and after some tuning was able to get the bike to stay upright indefinitely. I pushed it over, with a very slight force, after about five minutes because the motor was getting pretty hot. I can give you details on this mod if you are interested.
 
Title: Re: PID parameters for self-balancing motorcycle
Post by: Ajaj on Nov 27, 2018, 09:19 am
Yes i'm interested by your tuning, it(s always time consuming to go from concept to prototype that work. I'll try to add all mods i have in my mind at some point but i have a lot of teaching material to sort first. A ki on bias with small gain looks to be the way to go first.
Title: Re: PID parameters for self-balancing motorcycle
Post by: gzwicker on Nov 27, 2018, 06:28 pm
I'm using Kp = 90, Kd = 10,  Ki = 0.8, and master gain = 0.1.  As an integrator I  used the "DiscreteIntegrator" block with its limits set at +/- 50 and its other settings at default.  The limits prevent a large build-up of correction while the bike is still on the kickstand. Alternatively I suppose one could put a gate inline with the integrator controlled by the Fallen signal.
Title: Re: PID parameters for self-balancing motorcycle
Post by: gzwicker on Nov 27, 2018, 08:22 pm
Apparently my successful trial of yesterday was a fluke as I am not able to reproduce it today : (
Title: Re: PID parameters for self-balancing motorcycle
Post by: gzwicker on Dec 06, 2018, 07:01 pm
I also got some encouraging results with Kp = 45, Kd = 4, Ki = 1.9, gain = 0.1.    However, not being able to get consistent satisfactory results I am going to give up the project temporarily and go on to the Mobile Rover. Perhaps in the meantime there will be some helpful discussion about the self-balancing(?) robot here as others try that project.
Title: Re: PID parameters for self-balancing motorcycle
Post by: MadhuGovindarajan on Dec 14, 2018, 05:05 pm
The motorcycle's best balancing in the current format is about 45 seconds to 1 minute. For longer than that you have to dynamically tune the motorcycle over WiFi which is beyond the scope of the online learning materials.
Title: Re: PID parameters for self-balancing motorcycle
Post by: John_H_532641 on Dec 27, 2018, 03:46 pm
It would be very interesting to dispense with the flywheel and use turning the handlebars to maintain stability.  Basically, if the bike is leaning to the left, turn the handlebars to the left and this lifts the bike back to the vertical. 

Steering is similar but not intuitive as you need to turn the handlebars the "wrong" way to initiate the turn! 

Say the bike is upright and travelling straight and you want it to turn RIGHT. 
Turn the handlebars slightly to the LEFT. 
This causes the bike to lean to the RIGHT. 
When it has sufficient lean for the right turn, straighten the handlebars (or perhaps turn then very, very slightly to the right). 

It is called counter steering and is explained here together with a video: http://www.obairlann.net/reaper/motorcycle/beginner/countersteering.html

See this self balancing bike: https://www.youtube.com/watch?v=mT3vfSQePcs&feature=youtu.be
Title: Re: PID parameters for self-balancing motorcycle
Post by: titantomorrow on Jan 27, 2019, 06:34 am
Got the bike balancing, very rewarding. It lasted a total of 10 minutes, but the video just shows 5 minutes. I can reproduce, though I do need to adjust the bias to be pretty close when I put back the battery.

https://youtu.be/RWtfrmY-zEA

Here is it moving in a straight line, starting, stopping and finally falling over.

https://youtu.be/ipkUTBycZwM
Title: Re: PID parameters for self-balancing motorcycle
Post by: Mr_Bacon on Jan 30, 2019, 12:06 am
Awesome! thank you for sharing.. I'm your first like  :) 


Now if you can just video the process of building it :)
Title: Re: PID parameters for self-balancing motorcycle
Post by: glenz on Jan 30, 2019, 02:50 am
Very impressive, Titantomorrow! Are you going to share your PID values with us?
Title: Re: PID parameters for self-balancing motorcycle
Post by: MadhuGovindarajan on Jan 30, 2019, 09:16 pm
Really impressive work titantomorrow
Title: Re: PID parameters for self-balancing motorcycle
Post by: MadhuGovindarajan on Jan 31, 2019, 03:18 pm
@titantomorrow -

Would be great if you can share your work via Arduino Project Hub so that others can learn from you as well.
Title: Re: PID parameters for self-balancing motorcycle
Post by: titantomorrow on Feb 02, 2019, 09:24 pm
I'm not sure about doing a write up. But I think the videos are interesting just to show what the bike can do as a low cost learning platform. Obviously it can do far more.

Anyway here are some more videos.

RC integration part on the desk
https://youtu.be/T6iC4rBEi-0

RC integration part demo
https://youtu.be/68zZfn8rCSY

responding to slopes
https://youtu.be/EZatXXvxVz8

responding to weight imbalance
https://youtu.be/b1NKk96fH1g

Title: Re: PID parameters for self-balancing motorcycle
Post by: glenz on Feb 03, 2019, 12:27 am
You da man!
Title: Re: PID parameters for self-balancing motorcycle
Post by: pauldanielcox on Feb 15, 2019, 05:02 pm
For those getting here after struggling to get the bike to balance for a long time, do not despair! It's not trivial and that's what makes it so rewarding when you solve it! A "dumb" PID is not enough, you need to supplement it. Some have talked about dynamic bias, I called it control with a leaky integrator, but in any case you need to add an element that makes "finding" or tracking the exact balance point which is always changing minutely for many reasons (sensor realities, weight distributions, etc) and in a naturally unstable system these tiny perturbations are enough to send simple control schemes. If you get a really good algorithm you need surprisingly little effort, while if the algorithm isn't the best you can sometimes compensate with a fully charged battery and lots of micro adjustments in gain and weight centering, but that kind of "cheating" will never lead to a long running balance as the motor heats up quickly (and the battery depletes quickly) in this scenario. So take heart and push forward, this is a challenge you can conquer with learning and perseverance!
Title: Re: PID parameters for self-balancing motorcycle
Post by: Wuanto on Mar 23, 2019, 06:44 pm
Got the bike balancing, very rewarding. It lasted a total of 10 minutes, but the video just shows 5 minutes. I can reproduce, though I do need to adjust the bias to be pretty close when I put back the battery.

https://youtu.be/RWtfrmY-zEA

Here is it moving in a straight line, starting, stopping and finally falling over.

https://youtu.be/ipkUTBycZwM
titantomorrow, would you mind sharing your work or at least give away some tips? I wish my motorcycle balanced like yours!!!
Title: Re: PID parameters for self-balancing motorcycle
Post by: juancarlossaavedra1997 on Jun 08, 2019, 09:23 am
Hello, I have the same problem. I've made a model of the self-balancing motorcycle and then I've exported it to Simulink to design the PID controller. In the model, the controller that I've designed works well, but when I put it in the self-balancing motorcycle, it fell down. Also, I've tried with a LQR controller and I've achieved 10 or 15 seconds of balance, only. I've modeled the inertial wheel motor to put it in the model, but I think the motor's parameters isn't correct. Could someone help me?
Title: Re: PID parameters for self-balancing motorcycle
Post by: Julian_ortiz_olaya on Jun 09, 2019, 10:55 am
I'm not sure about doing a write up. But I think the videos are interesting just to show what the bike can do as a low cost learning platform. Obviously it can do far more.

Anyway here are some more videos.

RC integration part on the desk
https://youtu.be/T6iC4rBEi-0

RC integration part demo
https://youtu.be/68zZfn8rCSY

responding to slopes
https://youtu.be/EZatXXvxVz8

responding to weight imbalance
https://youtu.be/b1NKk96fH1g


Hello

Can you help us with your enhancements for the bike?

Thanks you
Title: Re: PID parameters for self-balancing motorcycle
Post by: angelo_ug on May 15, 2020, 11:27 am
Hello,

I came across this topic while struggling for balance with the self-balancing motorcycle.

I know this topic hasn't been posted for a while now, but I thought I would share my experience in case someone will find the same issue in the future.

The "secret" to make the controller work perfectly is to accurately evaluate the bias. My problem is that all those manual tests suggested by the course notes required too much precision for me. Also, the USB cable or any slight change of the position of the battery would change the actual value of the bias.

So I started seeking a method for the controller to automatically evaluate this bias every time, and I found that the integral of the torque command (the one after the manual switch) over time is a good bias value. It also helps to compensate for the centrifugal force in a big radius turn.

The drawback is that the bias will constantly change, causing the system to lose stability momentarily. But in this way, I went from a very stable system that saturated the inertia wheel speed in less than 20 seconds, to a slightly unstable system that stands upright indefinitely every time I switch it on.

I hope someone will find this useful.
Title: Re: PID parameters for self-balancing motorcycle
Post by: booster44 on May 29, 2020, 11:53 am
Hello, everyone,

I've been working on this project for weeks and I'm not getting anywhere.
My individual components are working perfectly. ( rear wheel, servo motor )
My big problem is to calibrate the wheel of balance.
When I run the program and set up the bike, the bike stands up and is also in the middle. The only problem is that the balance wheel starts to rotate too fast (it rotates over 6000 revolutions within a few seconds).
I have already changed all parameters and I can't find the error.
I hope someone with the same problem can help me.

Booster44

Title: Re: PID parameters for self-balancing motorcycle
Post by: angelo_ug on Jun 10, 2020, 12:16 pm
Hello, everyone,

I've been working on this project for weeks and I'm not getting anywhere.
My individual components are working perfectly. ( rear wheel, servo motor )
My big problem is to calibrate the wheel of balance.
When I run the program and set up the bike, the bike stands up and is also in the middle. The only problem is that the balance wheel starts to rotate too fast (it rotates over 6000 revolutions within a few seconds).
I have already changed all parameters and I can't find the error.
I hope someone with the same problem can help me.

Booster44


Change the bias. The inertia wheel accelerates too fast because you're not targeting the actual center of equilibrium.

If you don't want to manually change the bias every time the mass distribution of the bike changes, you need to find a way for the system to adjust the bias automatically. As I said in my post before yours, in my case the integral over time of the torque command (after the manual switch, so you don't start integrating when the weel is not working) was a good estimate of the bias.

I hope this helps.
Title: Re: PID parameters for self-balancing motorcycle
Post by: booster44 on Jun 24, 2020, 11:45 am
Thanks a lot Angelo.  :)

You've been very helpful.
And I understand where my mistake lies.
Could you send me the parameters you set?

Thanks a lot :)
Booster44
Title: Re: PID parameters for self-balancing motorcycle
Post by: booster44 on Jun 24, 2020, 12:01 pm
So my exact question is, how did you manage to write the integral of the torque command into the preload regulator.


Booster44
Title: Re: PID parameters for self-balancing motorcycle
Post by: angelo_ug on Jul 02, 2020, 07:09 pm
Hi booster,

I took the torque command after the manual switch (first attached picture), and gave it in input to a subsystem I called bias generator (second attached picture) in which there is discrete-time integrator.

As you can see, I have enabled a reset connected to a constant block. This block is connected to a push-button outside the subsystem. I use it every time I need to reset the integral.


Then, I directly add the output of the block to the theta angle before it enters the controller subsystem.

I hope this helps.
Title: Re: PID parameters for self-balancing motorcycle
Post by: booster44 on Jul 13, 2020, 03:34 pm
Hello, Angelo :smiley-small: ,

Thank you very much !
For sending us the screenshots. The bike keeps its balance better than before.
But not yet permanently. Some value does not fit apparently yet.
I do not know any more.
Can you send me pictures of every single component for comparison ? With this you would help me a lot.

I thank you in advance.
Beautiful and healthy days

Booster44 8)   :smiley-wink: