User Tools

Site Tools






The purpose of our project is to demonstrate the techniques involved in balancing an unstable robotic platform on two wheels. The objective is to design a complete discrete digital control system that will provide the needed stability.The Bot will be characterized by the ability to balance on two wheels and spin on the spot.This additional maneuverability allows easy navigation on various terrains.The toughest challenge to be faced by us is the implementation of PID control algorithm and filtering the data of IMU using KALMAN FILTER.!

We aim to extend this summer project THE SELF BALANCING BOT to a self balancing UNICYCLE.

One can find out about unicycle more at the following link



16th, 17th, 18th May

We found ourselves quite confused amidst the variation in the structure of the robot . Thinking in the direction of our ultimate aim,unicycle and also the self balancing platform ,a slight variation from our project, confused us a lot . So , we could not progress much in the project during these days. We also had a doubt whether we would use the servo motors or not.

19th May

We met the mentor and the final structure of the self balancing bot was decided amongst the 2-3 methods available to us. We were thinking that use of kalman filter was optional but it became quite sure to us that we had to use it .However we were quite familiar with the fact that no one has implemented KALMAN filter ever but still we want to give a try at least (apart from kalman we have a choice of complementary filter as well).

20th May

We finally planned how to make the project and divided the tasks among the team members . We started studying about the filters and IMUs to be used in the project .

22th May

Few team members read about the accelerometer and gyroscope .we came to know that only accelerometer can be used as a tilt sensor and gyroscope is only used to improve the data of accelerometer but for that we need a strong algorithm like kalman. A Now we had the algorithm of using the accelerometer and the gyroscope to get the angle of the bot.

24th May

We read about the kalman filter . It is based on linear quadratic estimation . It is based on weighted average giving more weightage to the reading which is more certain .

25th May

We got a c++ code which read the reading from accelerometer and gyroscope and using kalman filter gave the necessary output . It made us understand a lot about the IMUs and the kalman filter .

26th May

Prepared for the mid term evaluation 1 and made a powerpoint presentation putting in all the concepts used in the project and our progress in it .

28th May

Divided the team and divided the tasks amongst us . We also set a deadline to ensure that the project is completed in time . Whole team was divided in 3 groups. Objective of first was to understand the code for kalman filter and IMU which we got from the net(we have already understood the basics). The second group was given the responsibility of the hardware part of the bot(arranging DC motors, mica sheets, wheels and then to start making it).The third group had to complete PID control(starting from the basics to the final code).

29th May

We decided upon the structure of the robot . It will be 3 platformed structure with two simple wheels which move by the use of DC motors of RPM 200-300. We needed a motor which could apply enough torque so that we can get enough rise angle without compromising the senstivity of the robot . We also decided upon simple wheels on which we could put cricket bat grip if required to increase the friction . The IMUs and the arduino will be attached to the different platforms of the robot . blog.tkjelectronics.dk_wp-content_gallery_balancingrobot_img_2780.jpg

31st May

We worked upon the structure of the robot. We made the platforms using mica sheets in the robotics club . We also decided how to join them by screws which will allow us to vary the height of the robot . We couldn't complete as we needed motors . Also everything can only be fixed after fixing the components needed in the self balancing robot .

1st-2nd June

The theory part of PID control for the robot was almost complete. We have the final code with us. Now all we need is to change it according to our needs. A proportional–integral–derivative controller (PID controller) is a generic feedback controller. It can be used whenever a mean position has to be achieved but the controls of the system do not react instantaneously and accurately. The PID algorithm, takes in account the following 3 things- the existing error, the time the system has stayed away from the mean position and the possibility of overshooting the mean position. Using these 3 quantities, the system is controlled better, allowing it to reach the mean position faster and without over shooting it.

3rd-4th June

Now getting started with our 6DOF IMU, we got to know that it transfers the output using I2C protocol, and has an inbuilt ADC. Having inbuilt ADC saves us from a little bit coding and a lot of circuiting. 'I2C' stands for Inter-Integrated Circuit and allows communication of data between I2C devices over two wires. It sends information serially using one line for data (SDA) and one for clock (SCL).

Data transfer sequence

A basic Master to slave read or write sequence for I2C follows the following order: I2C Tutorial : I2C basic command sequence.

  1. Send the START bit (S).
  2. Send the slave address (ADDR).
  3. Send the Read(R)-1 / Write(W)-0 bit.
  4. Wait for/Send an acknowledge bit (A).
  5. Send/Receive the data byte (8 bits) (DATA).
  6. Expect/Send acknowledge bit (A).
  7. Send the STOP bit (P).

5TH June

Finally implemented I2C. We checked our IMU output using a complementary filter(DCM). It was displayed as a 3D rectangular box on the processing software.

6-8th June

Now coming back to our Kalman filter code, we finally completed it in 3-4 days (after a lot of frustration). The IMU of ours gave a 16 bit output. We got a kalman filter library for arduino on internet, but there was a lot to be changed. The input on arduino was 16 bit digital, but the library was designed for an analog input. Understanding the whole library was also challenging. After seeing a lot of other codes and examples, we finally were able to print the final deviation of the bot from the vertical axis measuring the angle about the y-axis.

9th June

We got our high torque dc motors needed for the bot, and we started making our mechanical model using the CAD model we had.

10-11th June

Mechanical model is finally complete. Here is a pic :

13th June

Time:22:28—-Our frustated mind and tired body finally got relief when after 14 hrs both the motors of the bot worked . We first tried with L293 but only one of the motors was moving . Then after contacting the seniors we tried with L298 . Still we faced the same problem . Then we came to know that a PCB of L298 is available . We got back to work with a new hope . Still it didn't move . We found out that we were making a mistake in using 7805 . When we used the circuit with a battery charger our aim was finally fulfilled at 22.28 . It was really a cherishable moment for us so I am mentioning the time too :)

15th june

Since Our mechanical model was ready and both the motors were working fine,it was the time time for final circuiting and final caliberataion ( PID Control ). Today mounted all the components(Arduino Mega,L298,IMU) and did the circuiting.While mounting the IMU,we had to take care of its axis. Axis marked on the IMU must be parallel and perpendicular to the bot. We were happy.We thought we would be completing our project before time.We had no idea what all problems were waiting for us…:-)

16-18th June

Now we were thinking to start with caliberation and test our bot on the ground but….as mentioned above,problem came again…Our motors were not working properly.Motors were rotating well in our hands but as soon as we put it on ground it stopped.We had no idea of why did that happen. Motors were starting to work again if we just shake our circuit or re-power our system. We thought there might be some loose connections in our circuit( and it was there ),so we did all the circuiting again. Problem still continued. We were starting to get frustrated now. We met many seniors and discussed our problem with them. Then we analyzed that the motors stopped whenever we gave jerk to our bot. Then on 18th we got to know our biggest mistake. We had to supply 12v power to the arduino but we were supplying 5v only. We supplied 12v and both of our motors started to work continuously. We were happy again. :-)

Note:-It is not at all true that our three days were just wasted because of that 12v and 5v. These three days were quite fruitful for us. we learnt many new things from our seniors while discussing our problems with them. Also, there were other problems too which were sorted out in these three days. It was just that changing 5v to 12v was our last debugging which made our bot to work well.

19-21 June

We finally started with PID control. It is a control algorithm to balance a system about any mean position ( as in our case, we need to balance our bot about vertical position ). It was one of the most challenging part of our project. We read a lot about it. But it didn't help us much. PID control was all about setting three constants (kp,ki,kd). All these three terms in PID control have different functions in PID control which collectively control the system. Then what was so challenging in it??? Actually we had to manually tune these three constants and we had no idea where to start from. Isn't there any formula to get kp,ki,kd??? Yes,It is there. But it was of no help to us. Ziegler Nichols was one of the methods which could use but it needed a proper oscillation which we were not getting in our system. So we had to go for Manual Tuning.

22 June

So we started with manual tuning of PID.We had used clamp on both sides the bot to prevent it from damage as it was going to fall many times during tuning. We started with kp keeping ki and kd zero. The bot started to oscillate but it was not free oscillation. Everytime it goes to one side, only after the clamp striked with the ground. We were to trying to make the bot oscillate freely with whatever amplitude but without striking of the clamp with the ground. We changed ,changed and changed the kp for this to happen but it didn't happen.


We thought it's time to apply ki and kd too. We applied ki and kd separately with kp. Bot became a bit more stable staying at mean position for 1-2 sec. But it never returned without the collision of clamp with ground. We applied all three constants together and many other combinations. Nothing helped. We discussed with our coordinators and found several mistakes. There was a error with our PID formula. There was also some problem with loop time(associated with complete code) and sample time(associated with PID) We made the required changes. But the performance of the bot didn't improve much. There were more problems we found out. First, both the motors had different RPM. And the most important one which we observed—whenever we gave jerk to the bot, motors rotated opposite to the expected direction. On further analysis, we got to know that this happened due to the garbage output of the IMU. Whenever we gave jerk to the bot and hence to the IMU, it gave garbage output and too some time to stabilize.

24 june

Today we had to complete our project. The next day,we had presentation. We knew the problem but not the solution. We tried and tried. We read all code for IMU and kalman. And yes we got the mistake. :-) .In the code for IMU we had used dt for gyroscope 30 ms while the loop time was just 4-5 ms. We changed dt from 30 to 5 ms anddd magic happened…. The bot was balanced for few seconds and it returned without the collision. We were very happy and excited. We were too close too our goal. We started again with PID tuning.Same method,keep ki and kd zero and set kp and all that. We kept on tuning PID. And hurray, the bot was balanced for 10 seconds. Further tuning made it around 20 seconds. We were almost done with our project. We just thought if we could balance it for more duration. By working for some more hours on it we realized that it was not possible with our mechanical system. We needed a better mechanical system, a more stable one. We needed two new motors with better precision and with same RPM (same RPM could be done by using encoder) and a pair of new wheels with better grip.

So we had learnt and implemented all the concepts(IMU, Kalman, PID and a lot about mechanical model) involved. We had balanced our bot for almost 20 seconds. We knew well how we could improve the performance of our bot. We were happy. We had completed our project.

Thanks to all the seniors who helped us in completing our project. Without their help and assistance we could never had completed such a challenging project in this short span of time.

Thanks to E Club, SnT council, Gymkhana Club and IIT Kanpur to provide us a with such a nice opportunity to explore the world out there without any limitation and to do whatever experiment we want to do.


/srv/http/ · Last modified: 2013/06/22 05:27 (external edit)