I am trying to make a system that can launch a ball kind of like how a catapult would do. I'm going to be using an Arduino and an H-bridge with PWM but I'm not sure how I can control both speed and position. I want to be able to launch the ball so it is perfectly horizontal at a set speed.

I'm frankly not that great at understanding control systems beyond how to calculate transfer functions. Does anyone know how I can set up code in Simulink so that I can get my system to be going at the desired speed at a set position, and then reverse the direction of the motor so that the ball releases at that point? Would I just use PIDs or would I have to include blocks that have the rest of the motors transfer function?

I've included a picture of my current Simulink code which uses 2 PIDs, one for speed control and one for position control, but I think this is wrong because both would interfere with each other. My system reads encoder values from 2 channels on the motor to get the position and angular speed.enter image description here

  • \$\begingroup\$ How can you have a desired speed at a set position? This can only possibly happen at a brief instant in time. If it’s moving then position is definitely not fixed. \$\endgroup\$
    – Chu
    Aug 2, 2022 at 14:56

1 Answer 1


The first thing you need to do is come up with a physical model. A pendulum model will be sufficient. Then you need to come up with a system of equations that will make sense for your simulink model.

The system will most likely need to track two states. One could be angular position and the other angular velocity. You will need to factor friction, gravity and mass in if you want it to track real physical system and if you are driving a physical system you will need to get real physical values for all non-negligible values. I would recommend state space. Also pendulums are non-linear over the full range of motion.

You can then plug in the encoder values for angular position and come up with an estimate for velocity, the problem with using a positional encoder is resolution, at low speeds you might get a few ticks and not be able to come up with a really good estimate for speed.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.