Wednesday, 30 August 2017

Another typical control problem: balancing a ball on a beam

Balancing a ball on a beam is not a common problem you may face during your everyday life, however, this simple example of engineering can be extended to more complex problems and, in general, to other more interesting control problems such as

  • Control of temperature in a room
  • Control of robots
  • Control of automated cars
  • Control of industrial processes

The main problem tackled in this article is the design and implementation of a basic PID based controller to control the position of a ping pong ball on a beam. Ideally the controller should be able to set the position to whatever value of the x axis the user decides to apply. This is a simple scheme of the physical system

schema1

The aim of the project is to design a digital controller that can set the position of the ping pong ball and reject noise. I am going to use a controller of the PID family since it is simple and widely used in the industry.

The physical system

First of all comes the study of the physical system. The problem can be generalized to other dimensions however, for the sake of simplicity it is limited to one spatial dimension. Note that we are using a rotating reference frame which is joint to the moving stick. Below is the sketch of the free body diagram:

schema2

As you can see, there is basically only gravity as major force at play, the other forces will be used to write down the equations needed to determine the relationship between the angle of the support and the acceleration of the ball.

At this point, we can label our variables as follows:

1. The **controlled variable** is the $x$ position of the ball.
2. The **control variable** is the angle of the stick $\theta$. This is going to be the variable directly affected by the controller through the servomotor.

We can now write the equilibrium equations for the ball and solve for the acceleration

$$
\left\{\begin{matrix}
N - mg\cos \theta = 0
\\
mg\sin \theta + m\ddot{x} + T = 0
\\
RT - J_d \dot{\omega_d} = 0
\end{matrix}\right.
$$

where:

the angular velocity:
$$\dot{\omega_d} = \ddot{\theta} = \frac{\ddot{x}}{R}$$

$J_d$ is the moment of inertia of the ball (which has no mass inside of it):
$$J_d = \frac{2}{5}mR^2$$

By solving the equation we find out that the acceleration on the x axis is equal to:

$$\ddot{x} = -\frac{5}{7}g\sin \theta$$

Now we need to approximate theta since the $\sin$ function is not very manageable.
For small $\theta$, angles we can approximate $\sin theta$ to be equal to $\theta$. This approximation is usually good, however, we might want to remember this when designing the controller later.

The continuous transfer function of the system

The continuous transfer function of the system can be found by applying the Laplace transform to both sides of the last equation and dividing the output variable by the input variable:

$$s^2 X(s) = \frac{5}{7} g \Theta (s)$$

$$\frac{X(s)}{\Theta(s)} = G(s) = \frac{5}{7}g\frac{1}{s^2} = \frac{k}{s^2}$$

We ended up with a very simple transfer function with two poles in the origin. This function can be studied in MATLAB although it is not that interesting:

bode_g


Finding the appropriate controller in a closed loop

By putting the transfer function in a closed negative feedback loop we need a controller to be used to steer our system towards the desired goal.

cloop

The system, on its own, is unstable. A controller is needed. Since there are already two poles in the origin, without a controller (ie with R(s) = 1) the phase margin is zero and the system is unstable. While a proportional controller is not enough and a PI controller would worsen the problems, a PD controller is perfect for the task at hand. A pure PD controller though does not exist in practice therefore, an approximated version is needed:

$$ R(s) = k_p + D \frac{N}{1+\frac{N}{s}}$$

The closed loop function $L(s) = N(s)/D(s)$ becomes

$$L(s) = R(s)G(s)

Since the transfer function from $\theta$ to $x$ in a closed loop is given by $\frac{L(s)}{1+L(s)}$ The closed loop poles are given by the following equation

$$1 + L(s) = N(s) + D(s) = 0$$

The closed loop poles depend on the parameters of the controller. We can now tweak those parameters in order to modify the response of the system. By using the *pidTuner* function in MATLAB you can easily choose the best parameters according to the needs of your project. The pidTuner function is awesome since it lets you easily visualize crucial parameters such as overshoot, rise time and settling time.

In this case, the following values were chosen: $k_p = 0.38$, $D=0.5$ and $N=50$.


It is possible to calculate the phase margin directly by using the margin function in MATLAB:

phase_margin

the phase margin appears to be about 73 degrees which is nice to see. The gain of the system is 1 as expected and confirmed by the step response:

step_sys

The root locus shows how poles move in the complex plane by varying the gain of the closed loop function from 0 to infinity:

rlocus

As the gain tends to infinity, the closed loop poles tend to the zeros of the closed loop function (or infinity if there are less poles than zeros). Note that the zero of the controller is exactly -9.09 which is also a zero of the L function.

Simulink, a nice shortcut to model a system and design a controller

Using Simulink, one could have avoided most of the trouble of simplifying the system or why not compare the simplified and the complete system. Below you can find the schematics of the complete system. The minus sign in the transfer function of the system is needed since I switched the x axis.

simulink1

Detail of the Subsystem modelling the physical system

simulink2

Complete Simulink schematics

Note that a saturation bloc is needed since it is probably best to limit the output of the PD controller. In case that the simplified system is used, a saturation bloc is needed to ensure that $\theta < \frac{\pi}{6}$. It is worth noting that by limiting $\theta$, the differences between the simplified and the complete model are very small if noticeable at all.

Tuning of the controller can be done directly within Simulink

PID

The results of the simulation are displayed in the graph below

untitled

In orange is displayed the set point, in blue the position on the x axis of the ball and in yellow the output of the PD controller (in radians). The settling time is about 4 seconds.

Note that the output of the PD controller has been restrained

PID_OUT

PD output

How would I go to make such controller though?

Well, an old school option is to use old fashioned op amps!

Image 15

You can find the Simulink and LTspice files here. I hope you enjoyed this article! Have fun!

20 comments:

  1. Hiv disease for the last 3 years and had pain hard to eat and cough are nightmares,especially the first year At this stage, the immune system is severely weakened, and the risk of contracting opportunistic infections is much greater. However, not everyone with HIV will go on to develop AIDS. The earlier you receive treatment, the better your outcome will be.I started taking ARV to avoid early death but I had faith in God that i would be healed someday.As a Hiv patent we are advise to be taking antiretroviral treatments to reduce our chance of transmitting the virus to others , few weeks ago i came on search on the internet if i could get any information on Hiv treatment with herbal medicine, on my search i saw a testimony of someone who has been healed from Hiv her name was Achima Abelard and other Herpes Virus patent Tasha Moore also giving testimony about this same man,Called Dr Itua Herbal Center.I was moved by the testimony and i contacted him by his Email.drituaherbalcenter@gmail.com We chatted and he send me a bottle of herbal medicine I drank it as he instructed me to.After drinking it he ask me to go for a test that how i ended my suffering life of Hiv patent,I'm cured and free of Arv Pills.I'm forever grateful to him Drituaherbalcenter.Here his contact Number +2348149277967...He assure me he can cure the following disease..Hiv,Cancer,Herpes Virus,Epilepsy, fibromyalgia ,ALS,Hepatitis,Copd,Parkinson disease.Genetic disease,Fibrodysplasia Ossificans Progressiva,Factor V Leiden Mutation ,Fatal Familial Insomnia ,Dupuytren's disease,Fibrodysplasia Ossificans Progressiva,Fluoroquinolone Toxicity Syndrome,Inflammatory bowel disease ,Huntington's disease ,Diabetes,Fibroid...

    ReplyDelete
  2. Online Assignment Help Calgary provides outstanding assignment support for university students by delivering high-quality, original assignments tailored to individual needs, accompanied by professional guidance across various subjects.

    ReplyDelete
  3. I read a lot of interesting posts here. Probably you spend a lot of time writing, Thanks for sharing.

    Looking for reliable Laptop Repair Service in Gurugram. If you are in Gurgaon and facing laptop issues, look no further than call our Laptop Repair in Gurgaon. Acer Service Center in Gurugram

    ReplyDelete
  4. I would say this is one of the best article I’ve read.. From beginning to end you nailed it totally. To write this you might have worked hard for research.
    Thanks for sharing this good article.

    Discover reliable HP Service Center in Pune for all your laptop and computer repairs. Expert technicians ensure quick and efficient service. We specialize in repairs and maintenance for all HP laptop. Call HP Service Center in Pune

    ReplyDelete
  5. Explore the complete guide to ATMA 2025 on KollegeApply — get all key details on exam dates, registration process, and syllabus.

    ReplyDelete
  6. This is a great read! Finding reliable used cars in Austin under $5000 can definitely be challenging, especially with so many listings that don’t always match what’s advertised. I’ve recently come across 1 Click Auto Auction, and they make the process so much easier. Their platform lists affordable used cars with clean titles, verified history, and transparent pricing — perfect for students, first-time buyers, or anyone on a budget.
    If you’re looking to save time and avoid the hassle of traditional car shopping, it’s worth checking them out here: https://1clickautoauction.com/used-cars-austin-under-5000-for-sale/

    ReplyDelete
  7. Just checked out the new Jeep Grand Cherokee inventory at River Oaks Chrysler Dodge Jeep Ram, and I’m seriously impressed! The selection is diverse, with options that perfectly balance luxury, power, and technology. The website is easy to navigate, making it simple to explore trims and pricing.
    If you’re in Houston and considering a new SUV, the Grand Cherokee lineup here is definitely worth a look.
    River Oaks Chrysler Dodge Jeep Ram
    📍 4807 Kirby Dr, Houston, TX 77098
    ☎️ (713) 292-5000
    🌐 https://www.riveroakscars.com/new-inventory/index.htm?search=&gvModel=Grand+Cherokee
    Great job to the River Oaks team for keeping things transparent and customer-focused!

    ReplyDelete
  8. I recently visited Helfman Imports in Houston, and the experience was outstanding from start to finish. The staff was knowledgeable, courteous, and genuinely passionate about luxury cars. They took the time to walk me through the different Maserati and Alfa Romeo models, explaining each vehicle’s performance and features in detail. The dealership’s environment was comfortable and professional, which made the entire car-buying process smooth and enjoyable.
    What really stood out to me was how transparent they were with pricing and financing options — no pressure, just honest advice to help me make the best decision. Whether you’re looking for a new Maserati, an Alfa Romeo, or a certified pre-owned luxury vehicle, I’d highly recommend stopping by Helfman Imports. They truly represent what premium customer service should feel like in the automotive industry.
    Check out Helfman Imports luxury cars in Houston for a wide range of new and pre-owned vehicles.
    Helfman Imports
    📍 7720 Katy Freeway, Houston, TX 77024
    📞 (713) 533-6100
    🌐 https://www.helfmanimports.com

    ReplyDelete
  9. If you’re searching for luxury Alfa Romeo cars in Houston, look no further than Helfman Alfa Romeo of Houston. Located at 7720 Katy Freeway, Suite C, Houston, TX 77024, they offer a wide range of new and pre-owned Alfa Romeo vehicles, including the Giulia, Stelvio, and Tonale. Their expert team provides personalized guidance to help you find the perfect car that matches your style and driving needs. Helfman Alfa Romeo of Houston For more details or to schedule a test drive, call 713-533-6190 or visit their website: https://www.alfaromeousaofhouston.com. Whether you value Italian performance, luxury design, or advanced technology, Helfman Alfa Romeo of Houston delivers a premium car-buying experience that’s hard to beat.

    ReplyDelete
  10. Looking for reliable lighting solutions and powerful tools to boost your dealership’s online presence? Check out ZenLitePro, located in Tucson, Arizona 85742. ZenLitePro offers a wide range of innovative, energy-efficient lighting products as well as specialized tools like the Facebook Marketplace Auto Poster for car dealerships and trucks. Their expert team is ready to help you choose the best solutions to improve your business efficiency and enhance your online visibility. For more information or support, call (877) 848-2216 or visit their website to explore the full range of products and services. ZenLitePro combines technology, convenience, and professional guidance to ensure your business stays ahead in today’s competitive market.

    ReplyDelete
  11. If you’re looking for a trusted online platform for chemical trading and industry solutions, visit Echemhub. Based in the USA, Echemhub connects chemical buyers and suppliers worldwide, offering a reliable marketplace for high-quality raw materials and industrial chemicals. Their platform ensures transparency, verified suppliers, and seamless transactions to make sourcing more efficient. Whether you’re in pharmaceuticals, manufacturing, or research, Echemhub provides tools and support to simplify your chemical procurement process. Explore their website to learn more about their services and discover how they are transforming the chemical trade industry.

    ReplyDelete
  12. Looking for a reliable and innovative chemical supplier? Explore CD Chem Group, a trusted name in the global chemical industry. They specialize in providing high-quality research chemicals, intermediates, and custom synthesis services for industries such as pharmaceuticals, biotechnology, and materials science. With a strong focus on innovation, quality assurance, and customer satisfaction, CD Chem Group ensures that every product meets international standards. Their team of experts is dedicated to supporting clients with tailored solutions and technical expertise. Visit their website to learn more about their extensive product range and discover how CD Chem Group is driving progress in the chemical and scientific community.

    ReplyDelete
  13. If you’re looking for premium-quality specialty chemicals, visit ChemHub, a trusted source for high-purity flavor and fragrance ingredients like Maple Furanone Synthetic. Known for their commitment to quality, ChemHub supplies fine and specialty chemicals to industries including food, cosmetics, and pharmaceuticals. Their products are manufactured under strict quality control standards to ensure consistency and performance. Whether you need small-scale lab quantities or bulk production, ChemHub provides reliable solutions and exceptional customer service. Explore their website to learn more about their product range and how they support innovation in the chemical and fragrance industries.

    ReplyDelete
  14. Looking for a trusted technology partner to help your business grow? Visit Gaurish Technologies Pvt. Ltd., a leading IT solutions provider specializing in web development, digital marketing, custom software, and e-commerce solutions. With a focus on innovation, reliability, and customer satisfaction, Gaurish delivers high-quality digital products tailored to meet unique business needs. Their team of experienced developers and designers ensures every project is built with precision and creativity. Whether you’re a startup or an established enterprise, Gaurish offers scalable solutions to help you achieve digital success. Explore their website to learn more about their services and discover how they can take your online presence to the next level.

    ReplyDelete