Go Down

Topic: PID parameters for self-balancing motorcycle (Read 3555 times) previous topic - next topic


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?


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.


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.


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.


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.


Apparently my successful trial of yesterday was a fluke as I am not able to reproduce it today : (


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.


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.


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


Jan 27, 2019, 06:34 am Last Edit: Jan 28, 2019, 06:18 am by titantomorrow
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.


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



Awesome! thank you for sharing.. I'm your first like  :) 

Now if you can just video the process of building it :)


Very impressive, Titantomorrow! Are you going to share your PID values with us?



@titantomorrow -

Would be great if you can share your work via Arduino Project Hub so that others can learn from you as well.


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

RC integration part demo

responding to slopes

responding to weight imbalance

Go Up