I am working on the project that uses linear actuator as a drive, however I would like to limit the power of the actuator due to safety reasons.
My intention was to measure the current the actuator produces when working and shut it down when the current is too big.
I use VNH5019 shield which provides current in milliamps.
Unfortunately the actuator has huge starting current (nearly 3 amps), which is way to big for my safety limit. It just doesn't even start when I use a condition of max 1 amp as a safety limit.
How could I measure the current to avoid taking into computation motor starting current. Any code examples (or referals) would be usefull
The same way you are now, using the code you didn't post.
What you need to do, when deciding whether to shut the power off, is consider both the amount of current AND how long it has been since the device was turned on. The millis() function might be useful.
How could I measure the current to avoid taking into computation motor starting current.
Your program is presumably starting the motor so you know to expect a large current draw at that point, so set the trigger level for shutdown to a much higher level for a period of time.
As you can see it returns true once the actuator reaches to goal position.
I would like to measure current only when the engine is operating, so probably the whole safety mechanism shoulb be in the above function.
Could you advice where and how to structure it to get my result e.g. for the first 500 millisec. since DC motor starts the current will not be measured and than the current will be measured and if reaches the maximum level it will be stopped?
Sorry for such questions, this is my first useful programme with Arduino (I was never coding in any language before as well).
Using you function as a base for changes something like this maybe
unsigned long startTime = millis();
while (1)
{
if ((md.getM1CurrentMilliamps() > someValue) && (millis() - startTime > 5000)
{
//current is too high and 5000 milliseconds has passed so there is a fault
//code to deal with the fault.
}
However there is something odd about your function. For instance
if (Extending == false)
{
Extending = false;
Why set Extending to false when it is already false ? Why have 2 variables (Extending and Retracting) when the system must be doing either one or the other so you could have one variable and make it true or false.
I need to set the "if" condition like this (check if Extending) because otherwise the actuator starts oscilating. The condition allowes to run the "if" statement only once and then skip it until the actuator reaches final position.
Your second remark is acurate :)...however it was easier for me to understand what am I doing when coding. I could get rid of the redundant variable now