Hello, I've got a carriage that moves backwards and forwards via a hybrid servo motor connected to a ballscrew. This carriage needs to pause when an external shaft stops rotating (max speed of the shaft is 1.2 rmp) and then continue its loop when the shaft starts rotating again.
The loop is running really fast as it's driving the pulse signal to the hybrid servo driver (30micros between pulses/loop) The induction sensor has 12 'pick ups' at 30degrees. How do I compute whether the shaft is turning and allow for the fact that the shaft might stop while giving a 'HIGH' signal as it over one of the 'pick ups'?
Do I need this part of the program to be run by a separate arduino to give a high low signal which I can use in the original program to 'do nothing' while said Pin = HIGH. I've only been writing code for a few months so my knowledge is patchy. The rest of the program deals with 6 buttons (AUTO/MANUAL, START, STOP, HOME, FORWARDS, BACKWARDS) , 2 limit sensors and the outputs to the servo driver which Ive written.
Any help would be greatly appreciated, thanks for your time.
Hi,
Thanks for your input. The shafts maximum speed would be 1.2rpm and the slowest would be 0.48rpm. I like the idea of the 'heartbeat' approach. The lag time between when the shaft stops turning and when my servo stops doesnt matter too much. The project is an automatic belt washing machine. If the slow shaft is turning this means that the belt is moving past the carriage and it (the carriage) needs to continue moving as it is holding the pressure washer nozzles, which in turn are cleaning the belt.
What Im struggling to understand is how to approach writing a program which can 'recognise' whether the heartbeat state is 'true'.
Look at the state change example in the IDE. When your induction sensor input changes, record the time using millis. If it hasn't changed in a while, stop.
const int sensorPin = 2; // the pin that the pushbutton is attached to
int lastSensorState = 0; // previous state of the sensor
bool isRunning = false;
cont unsigned long maxInterval = 1000; // 1 second for demo, adjust to true RPM
void setup() {
pinMode(buttonPin, INPUT);
Serial.begin(115200);
}
void loop() {
int sensorState = digitalRead(sensorPin);
if (sensorState != lastSensorState) {
// still moving
lastMovementTime = millis()
}
lastSensorState = sensorState;
// check if we are rotating
if ( millis() - lastMovementTime >= maxInterval ) {
// nothing has changed in too long so stop
isRunning = false;
}
else {
isRunning = true;
}
if ( isRunning == true ) {
// do appropriate things here
}
}
I understand how to approach it now. I was overcomplicating things in my head. I really appreciate the help from everyone, Ill give this a whirl this afternoon.
What is the maximum speed that is considered "stopped". If 0 RPM is the maximum speed for 'stopped' you will need to wait an infinite amount of time to determine if the shaft is stopped. Please pick a non-zero value.
1.2 RPM = 0.833 minutes per revolution = 4.166 seconds per pulse.
If you allow the shaft to run at 0.5 RPM without counting as 'stopped' you will need to wait at least 10 seconds since the last pulse to determine if it has stopped.
Most people would use one proximity sensor and a toothed wheel rather than one 'tooth' and 12 sensors. Maybe 60 teeth? That would get you a speed value in 1/5th the time.