Skip to main content

An Improved Q-learning Approach with Kalman Filter for Self-balancing Robot Using OpenAI


A two-wheeled self-balancing robot (SBR) is a typical example in control systems that works on the principle of an inverted pendulum. In this paper, we experiment to see how the learning and stability performance varies based on Kalman filter introduction for IMU noise filtering and controlling the robot using reinforcement learning. All the implementation is performed in ROS and Gazebo, and Q-learning is implemented using OpenAI (toolkit for development of Reinforcement learning) for ROS, i.e., Openai_ros package. Our work deals with a novel approach of providing the angular output from IMU to Kalman filter and passing it to the input of Q-learning for balancing control. Finally, we analyze the results with and without using Kalman filter from the output of IMU before passing it to Q-learning and evaluate the performance based on robot’s learning behavior and its robustness.

This is a preview of subscription content, access via your institution.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9
Fig. 10

Code Availability

The code will be available based on the request.


  • C.Watkins (1989) Learning from Delayed Rewards. PhD thesis, Cambridge University, Cambridge, England.

  • 2021. geometry_msgs/Wrench Documentation. [online] Available at: < h.html> [Accessed 14 June 2021].

  • Jayakody, D. P. V. J., & Sucharitharathna, K. P. G. C. (2019). Control unit for a self-balancing prototype. The Global Journal of Researches in Engineering. Available at: Accessed 22 Aug 2021.

  • Kalman, R. E. (1960). A new approach to linear filtering and prediction problems. Transaction of the ASME - Journal of Basic Engineering, 82, 35–45.

    Article  MathSciNet  Google Scholar 

  • Kober, J., Bagnell, J. A., & Peters, J. (2013). Reinforcement learning in robotics: A survey. The International Journal of Robotics Research, 32(11), 1238–1274.

    Article  Google Scholar 

  • Madhira, K., Gandhi, A., & Gujral, A. (2016). Self balancing robot using complementary filter: Implementation and analysis of complementary filter on SBR. In: 2016 International conference on electrical, electronics, and optimization techniques (ICEEOT), pp. 2950–2954.

  • Montella, C. (2011). The kalman filter and related algorithms: A literature review. ResearchGate. Available online: Accessed 20 Oct 2019.

  • Rahman, M. M., Rashid, S. M. H., & Hossain, M. M. (2018). Implementation of Q learning and deep Q network for controlling a self balancing robot model. Robot. Biomim., 5, 8.

    Article  Google Scholar 

  • Sun, F, Yu, Z & Yang, H. (2014). A design for two-wheeled self-balancing robot based on Kalman filter and LQR. pp. 612–616.

  • Technical Note Q-Learning Christopher J.C.H. Watkins and Peter Dayan Centre for Cognitive Science, University of Edinburgh, Scotland Machine Learning, 8, 279–292(1992).

  • Watkins, C. J. C. H., & Dayan, P. (1992). Q-learning. Machine Learning, 8(3), 279–292.

    MATH  Google Scholar 

  • Zamora, I., Lopez, N.G., Vilches, V.M., & Cordero, A.H. (2016). Extending the OpenAI Gym for robotics: A toolkit for reinforcement learning using ROS and Gazebo. ArXiv, abs/1608.05742.

Download references



Author information

Authors and Affiliations


Corresponding author

Correspondence to Aditya Srichandan.

Ethics declarations

Conflict of interest

The authors hereby declare that there is no conflict of interest in this research work/paper.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Reprints and Permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Srichandan, A., Dhingra, J. & Hota, M.K. An Improved Q-learning Approach with Kalman Filter for Self-balancing Robot Using OpenAI. J Control Autom Electr Syst 32, 1521–1530 (2021).

Download citation

  • Received:

  • Revised:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: