I have these stepper motors and drivers:
https://www.omc-stepperonline.com/index.php?route=product/isearch&search=1+Axis+Stepper+Kit+4.0Nm(566oz.in)+Nema+24+Stepper+Motor
566oz/in - I needed something beefy to drive the mecanum wheels.
Each Axle (2 motors) shares a 24v 7A battery pack. I currently have the drivers set at 1.2A.
Here is some super basic code:
#include <Stepper.h>
int sensorPin = A2;
int sensorValue = 0;
int mappedValue = 0;
int mtrSpeed = 0;
int currCmd = 1;
int serialCmd = 0;
boolean stationary = true;
String pinConfig = "forward";
//MotorPins
//Motor1 = 6,7
//Motor2 = 8,9
//Motor3 = 22,24
//Motor4 = 51,53
void origPinConfig() { //Orig = Forward
//Motor1
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
//Motor2
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
//Motor3
pinMode(22, OUTPUT);
pinMode(24, OUTPUT);
digitalWrite(22, LOW);
digitalWrite(24, LOW);
//Motor4
pinMode(51, OUTPUT);
pinMode(53, OUTPUT);
digitalWrite(51, HIGH);
digitalWrite(53, LOW);
Serial.println("Starting pin configuration set.");
}
void setup() {
Serial.begin(9600);
origPinConfig();
}
//All four wheels forward
void forward() {
//TODO
//Accelerate
//Decelerate
digitalWrite(7, HIGH);
digitalWrite(9, HIGH);
digitalWrite(24, HIGH);
digitalWrite(53, HIGH);
delayMicroseconds(mtrSpeed);
digitalWrite(7, LOW);
digitalWrite(9, LOW);
digitalWrite(24, LOW);
digitalWrite(53, LOW);
delayMicroseconds(mtrSpeed);
}
void loop() {
if(Serial.available()){
//Dont care yet
}
mtrSpeed = 2600;
if(currCmd == 1){
forward();
}
}
Here's a 10 second video clip of what the above code produces: Choppy stepper motion - YouTube
You can hear pretty easily that the steppers seem to be stepping too fast, yet still not translating to the RPM I was expecting.
I read Robin's excellent post about Stepper motors some time ago and I thought I had a good understanding of them - until I realized I was writing blocking code. This code will soon listen for a Serial command to change the direction of motion.
When I altered the code to be "non-blocking" the motors are now very choppy. I think it has something to do with the rate at which the Loop method is executed and calls the forward() method.
The drivers are currently set at 400 Steps per revolution. I am trying to get 60RPM - which will translate to 6-7 MPH with these 6" wheels. By my best guess, I am only getting 48-50RPM from this configuration.
I know steppers aren't meant to be "Super-smooth" but you can tell from the video that these are running really rough. If I had this project to do over again, I would probably go with DC motors. I had hoped to achieve a high degree of precision with stepper motors (this is a partially completed autonomous bot).
Any advice on how to "calm/quiet/smooth" these stepper motors?
TIA