First of all, thank you all for the help and suggestions. I am surprised for how quick the responses are!
First thing: I will use a voltage translator for the encoders thanks to MarkT remark, I wasn't aware of that.
I have tried using the QuadEncoder library withouth success, it did not work out of the box and I stopped trying. Are there any suggestions to use an other library ? I am open to try!
For the velocity estimation it is difficult to say, since it looses steps only when the cart of the pendulum accelerate quickly and the pendulum is rotating very fast. However I need to increase the tolerance in speed and acceleration, because I am planning on training RL agents on this thing.... and i would like to have to implement or calculate velocity limits.
As for why I know that the teensy is missing steps:
The encoder library accumulates pulses. I display the pulses on a simulation that reads those pulses and at the initialization I set the stable position at the bottom to 0.
When I start to move the pendulum slowly, my simulation is accurate and mirrors the physical system very well. however, when I am very aggressive and move both the cart and pendulum very fast, the angle of the pendulum in simulation is not in congruence with the real pendulum.
That means that the serial messages encoding the pulses of the pendulum are wrong. I have observed that this happens also more often when the touch sensors at the sides are activated.
As for the plan of action I will for sure implement the 2x counting method for at least the position sensor. But I would really like to achieve I high resolution on the pendulum encoder.
I will try to estimate a Max velocity for rotation and position.
If nothing changes I will try to utilize two teensyies one for the rotation of the pendulum and another for the position and the touch sensors. And here I have a question for u guys. Is it possible that In connecting two serial devices with this kind of output frequency I overload the serial chip on the raspberry pi ?
I already have some latency issues what is concerning the control loop which is running at 10 hz.. my actuation loop is running at 20 hz.... at the moment my SensorCollector loop which is getting the information from serial is "listening" to the serial input. I guess that with two teensyies i could easily run into some problems.. right ??
I am happy if I get some feedback and some solutions ! I appreciate your time ! and thanks in advance
P.S
I need the bounce library for the touch sensors, they are super bouncy, in fact... is someone has a suggestion for another kind of sensor that can help me with the callibration of the cart position and safety of the cart during operation... that would be great...