BTS7960D / Linear Actuator Library and Multiple control guidance needed

Hi All,

I have created the library below

https://github.com/digitalbirth/BTS7960AD

BTS7960AD is an Arduino library for controlling a linear actuator using a BTS7960 motor driver module.

I would like to get some insight into how I can control 2 or more actuators at the same time

I would define and initialize the actuators as below.

BTS7960AD actuator1(R_EN, R_PWM, R_IS, L_EN, L_PWM, L_IS, sensor, strokeLength, debug);
BTS7960AD actuator2(R_EN, R_PWM, R_IS, L_EN, L_PWM, L_IS, sensor, strokeLength, debug);

void setup() {
    Serial.begin(115200);               // setup Serial Monitor to display information
    actuator1.init();                         // reset actuator EEPROM id's

    actuator1.begin();                    // set up actuator pins
    actuator2.begin(); 

    actuator1.enable(true);           // enable driver pins
    actuator2.enable(true);

    actuator1.calibrate(127);         // set min / max actuator values
    actuator2.calibrate(127)
}

void loop() {

  Serial.println("Extending 50mm full speed");
  actuator1.actuateByDistance(strokeLength, 1, 255);   //this will complete first
  actuator2.actuateByDistance(strokeLength, 1, 255);   //then this will start after first has completed
}

To get the actuators moving at the same time, the only way I can think of is to create a loop to set the distance 1mm at a time for each actuator.

But this is why I am here, is there any other way I could do this?

I would ideally like to keep the code in the library rather than the sketch

how can I control both instances in the library? do I set a global variable?

There is no such. Trying to do it in the code or in a library makes no difference. The library is compiled like any other code.
Using common I/O pins could be a possible way to make things happen at the same time. This implies the actuators move at the same speed. Using enable signals on actuator could be stopped before the other one. Enabling both they cold start at the same time, using the same I/O signals for direction and move.

I was wondering if I could capture all instances, i.e. actuator1 and actuator2 and command them to move

Im just not able to understand how they did it

This code is from a servo library

https://forum.arduino.cc/t/two-servos-at-once-with-millis/520964/4

void Sweep::moveAllTo(int newPosition) {
  if (newPosition > 180) {
    newPosition = 180;
  } else if (newPosition < 0) {
    newPosition = 0;
  }
  for (auto i : instances)
  {
    setTargetPosition(i, newPosition);
  }
}

Hi,
Is this the module?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Yes, if you look at the the GitHub library, there should be a picture the same as the module you have shown

I think I may have solved the problem, by accessing the instances of the constructors and moving each actuator a tiny bit at a time

I have used BulldogLowell - code, it was a major help.

Here is the code, it still needs fully testing but if anyone is interested to give it a go, id love to hear your feedback or optimisations.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.