Two Wheeled Inverted Pendulum

Hi guys,
I am making a 2 wheeled inverted pendulum.
In order to do so, I did the modelling of the system. I have the state-space model where input is the torque of the 2 motors (I drive the 2 motors simultaneously), the output is the angle of the inverted pendulum. See WIP photo attached.
I then use a PID controller (Simulink as well), and tuning for Kp, Ki, Kd. However, the output signal from the PID controller that I simulated yield the output range much greater than the maximum torque of the motors.
I am quite sure that the modelling is correct, I am following this article: http://publications.lib.chalmers.se/records/fulltext/99385.pdf

My question is: I intend to do the map(pidout,fromlow,fromhigh,tolow,tohigh) to map the output range from the PID to range (0-255). And in order to do so:

  1. I simulink to get the Ki, Kp, Kd.
  2. I view the output signal from the PID controller after the simulate. Check for the maximum and minimum range.
  3. Use the map() function to map.

I have a concern that would it affect the system? Because now I scale the signal, I am pretty sure it will affect the outcome of my system.

Besides, other suggestions on how I can apply from simulink mathlab result to the programming would be appreciate.

Thanks.

WIP.png

You need to fix your model to model the torque limits of the motor - you've tuned for a setup you physically don't have which has very high power motors.

At the very least start again and watch the output amplitude as you tune up and avoid pushing the gain too high. Clamp the output in the model to realistic values if that's possible.

Also you'll propbably find you haven't modelled any backlash in the gearing, and backlash can have a strong effect on loop-stability as its effectively a non-linear delay element.