I've been working on my stepper motor/Uno project and have come to realize I likely need a closed loop motor with an encoder to achieve my objectives.
Basically imagine the stepper is connected to a cog and rotates in certain patterns and speeds. This is not for a printer. As part of a game, a person tries to grab the cog, but not necessarily with enough strength to halt the stepping. I want the program to be able to detect any sudden change in resistance on the cog, and to perform other actions.
I've been looking into buying the MKS Servo42C for my purposes. Link is here.
Will the MKS work for this purpose? Does anyone have any example code to detect stepper resistance? I can't seem to find any code/functions on this. I'm currently using Mobatools for my open loop stepper, not sure if that'll still be viable.
This project has nothing to do with injuring people or torture if that's what you were thinking. No one's actually putting fingers into cogs, but the concept of placing physical resistance against the stepper is similar.
If I understand right you want to detect mechanical "resistance"
with using the correct tecnical terms You want to detect an increase of torque while a cog is rotating.
A stepper-motor is designed to STEP
This means by any chance rotate to the next FINISHED step.
If you apply a higher torque to a stepper-motor the stepper-motor will finish its step completely if the torque that the stepper-motor creates is higher than the mechanical torque applyed
or
loose a step completely if the torque that the stepper-motor creates is smaller than the mechanical torque applyed
The electrical current that flows through the stepper-motor will always be the same.
Regardless if the stepper-motor is "free-wheeling" or works against any amount of torque.
Because the current flows through the stator = the still standing not moving part of the stepper-motor.
All in all a stepper-motor even a closed loop stepper-motor is not suitable for detecting a change in mechancical torque
If you want the community and its knowledge to really help you with your application
the best thing is to describe in detail what your device is.
No idea if a device that is able to measure mechanical torque is the right thing for you.
Other motors like classical DC-motors or brushless motors are easier to use for measuring mechanical torque.
It looks like the MKS-Servo42C gives a measure of error between the steps called for and the steps moved:
command 4: e0 39 tCHK
read the error of the motor shaft angle.
Return e0, error(int16_t), rCHK.
The error is the difference between the angle you want to control minus the real-time angle of the motor, 0-FFFF corresponds to 0~360°, for example, when the angle error is 1°, the return error is 65536/360= 182.444, and so on.
The correct design for this product is a flexible coupling between the stepper shaft and the device it turns. Timing the difference between a step of the motor and a step of the device will tell you the resistance of the device.
Edit: I used the wrong term for the coupling. It should be a resilient coupling so it will return to it's original state when the torque difference is removed.
I would likely be looking at a rotary torque cell to sense the load and when the load increases do whatever you choose your motor to do. A rotary torque sensor for example will monitor your free running torque and if a load is applied the torque will increase and when it hits your preset limit you decide what you want to happen.
which means set a max torque. What the TO wants sounds like request actual torque at any time, receive actual torque and send the torque-value towards the microcontroller.
The github manual isn't particularly helpful. StefanL38, do you have any suggestions on how to implement torque mode in Arduino IDE? I'm not familiar with working with hex.
You have described:
"cog will be rotating (instead of standing still) a person tries to grab the cog which will apply extra torque to the stepmotor-shaft"
very unprecise description.
There is nothing like implementing the torque-mode into the arduino-IDE
The torque-mode is something the motordriver is adjusted to.
If you go on beeing that unprecise I highly doubt that you will get things working.