# Stepper motor

## Motor model
Two detail steps ago we already looked in to stepper motors.
I implemented a model that I found on a [Github repository](https://github.com/SuYouge/Stepper-motor-modeling).
Sy Youge build a model of a stepper motor with a good explaination.

I could easily implement this.
I expended his bondgraph model with a phase controller.
I only have to put in the desired angle. However, this phase controller does not have any limiting.
Therefore, some control in required to make sure the physical part of the motor can keep up with the electrical rotation.

## Motor Control
This control is a seperate block.
There are two limitations to the controller.
First it has a limited speed, second it has a limited torque.
If you exceed this speed or torque the motor will stop operating.

The torque requires a good feed-forward model of the dynamic system.
However, I can just assume the max moment of inertia and then convert the torque in to a maximum acceleration.
This was the easiest option.

The result is that I have a setpoint for the angle. This is the setpoint for the first PD controller.
This is not a PID as the design of the stepper already solves the steady state error that would have been caused by gravity.
The first PD will then output the desired velocity. We limit this velocity and feed it in to the second PD controller.
This will output the desired acceleration. This is also limited. The acceleration is then integrated twice resulting in a position that is velocity and acceleration limited.
Which is fed in to the stepper motor model.

A nice feature of this setup is that has no feedback outside of the controller.
Therefore, we do not need any sensors in the system.
Maybe some initial setpoint.

