Hello All -
This is my first sketch, so any feedback is welcome.
I'm making a machine that bonds two plastic discs together. The discs are cicular and are joined with solvent.
I have one stepper that spins the discs and one stepper that applies the solvent. The stepper that applies the solvent is a linear stepper (lead screw) that pushes on the plunger of a syringe.
The discs only need to spin one revolution to apply one bead of solvent.
I want to be able to vary:
(1) The rotational speed of the discs
(2) The amount of sovent dispensed
I want to be able to keep constant:
(1) Discs must only rotate one revolution in order to apply one bead of solvent all the way around.
(2) Both motors must start and stop at the same time.
The issue I am having is that I cannot get the two steppers to stop at the same time. In my application, if the motors don't stop at the same time, there will either be lack of solvent (the solvent stopped dispensing before the disc could rotate a full turn) or there will be too much solvent (the solvent continues to dispense into a puddle after the disc stops rotating).
I am using:
Two Big Easy Drivers
Arduino UNO R3
AccelStepper library
I chose the AccelStepper library because it allows the independent and simultaneous control of two steppers. However, I don't think I need the ability to accelerate the two steppers. For my application, I think it would be fine to start/stop as instantaneous as possible. I'm wondering if this time to accelerate is where my problem is (the motors not stopping at the same time) coming from. In an attempt to mitigate this error, I set the acceleration to max "999999999" to get the motors up to speed quickly. Is is possible to remove acceleration all together?
Please take a look at my code. Since time is the same for both motors, my attempt is to calculate the "linear_travel" (steps) based on the rotational speed, rotational travel and dispensing speed.
When this code is run, the rotary stepper runs for a longer period of time than the linear stepper. I don't understand why.
I'm fine with scrapping this code if there is a better option for getting motors to start/stop at the same time.
Thanks.
#include <AccelStepper.h> // This section introduces the "AccelStepper" library (a pre-written set of instructions) to this program
// This sketch controls two stepper motors. The motors run at the same time, but at different speeds, distances and accelerations.
// There is one steppper called "rotator" that turns the filter and there is one linear stepper called "dispenser" that applies the solvent.
// The program only runs once (application of solvent to one part) and stops.
// The steppers are each controlled by their own Big Easy Driver connected to an Arduino UNO R3.
// Rotator stepper wiring:
// Connect the "Direction" pin of the Big Easy Driver (BED) to pin "8" of the Arduino UNO
// Connect the "Step" pin of the BED to pin "9" of the Arduino UNO
AccelStepper rotator(1, 9, 8); // This instruction declares the physical Direction & Step connections noted above
// Dispenser stepper wiring:
// Connect the "Direction" pin of the Big Easy Driver (BED) to pin "6" of the Arduino UNO
// Connect the "Step" pin of the BED to pin "7" of the Arduino UNO
AccelStepper dispsenser(1, 7, 6); // This instruction declares the physical Direction & Step connections noted above
int rotational_speed = 300; // This is where the spinning speed of the filer is set (steps per second).
int rotational_travel = 3200; // This is where the amount of steps is defined for the rotary stepper.
// This stepper motor has 200 steps per one full rotation (1.8 degrees).
// Per default, the BED provides 16 microsteps per motor step, so 200 x 16 = 3200 steps per one full rotation.
// To dispense the solvent on the filter, we only want the filter to rotate around once.
// So, this "rotational_travel" will stay around 3200 (more if we want some overlap of solvent application)
int dispenser_speed = 15000; // This is where the amount of solvent dispensed can be adjusted;
// the higher the number, the more solvent is dispensed.
int linear_travel = ( rotational_travel / rotational_speed ) * dispenser_speed;
// This calculation defines the linear travel (amount of microsteps) of the dispenser.
// This value is calculated in order to stop the two stepper motors at the same time.
// Since distance = (time * speed) for each motor
// and since the time for each motor is required to be equal for this application
// then, distance divided by speed for each motor are equal.
void setup()
{
rotator.setMaxSpeed(rotational_speed); // This is the fastest speed that the rotator will achieve (steps per second)
rotator.setAcceleration(999999999); // This is the acceleration of the rotator as it ramps up to max speed
dispsenser.setMaxSpeed(dispenser_speed); // This is the fastest speed that the dispenser will achieve (steps per second)
dispsenser.setAcceleration(999999999); // This is the acceleration of the dispenser as it ramps up to max speed
}
void loop()
{
rotator.moveTo(rotational_travel);
dispsenser.moveTo(linear_travel);
rotator.run();
dispsenser.run();
}
Moderator edit: Code tags added