Hello All:
I am slowly getting all the components working correctly for an experimental marine Autopilot. The main sensor is the HMC6352 magnetic compass. The program follows a heading input, taken from the compass. The steering motor is driven with a Pololu 18v25 motor controller. In the final stage, the gear-reduced steering motor will actuate the hydraulic helm by means of a cog-belt and a manual clutch to the ships wheel.
However, I would like to turn the steering motor on/off in discreet steps to make the corrections gradually, not full ON right, or full ON left. After using delay's (simple, but not good) for on time and off time, the program is working pretty good. After trying many, many variations of millis(), the motor OFF time is working perfect, but I have hit the wall trying to get millis() working for the motor ON time.
Here is the motor timing code.
void Motor_state()
{
digitalWrite(relayPin, LOW);
//
if (millis() - previousMillis > interval) { // 1500 motor OFF time
previousMillis = millis();
digitalWrite(relayPin, HIGH);
}
delay (200); // motor ON timereturn;
}
The relayPin is the output to open or close a relay, in series with the Pololu motor controller PWM signal, effectively starting or stopping the motor. The millis() interval is 1500ms in the set-up.
The motor off time with millis() works fine, and the program does work correctly to my expectations. The motor speed is variable with a potentiometer, as well as the dead-band +/- degrees variable set by a potentiometer. Looking good, so far. I will add pots for the motor off time , as well as motor on time later, so it can be fine tuned in actual operation. The times used are estimates of what will move the "wheel" in discreet steps.
The delay lets the motor run for 200ms, but how can I use the millis() function for the motor ON time, and get rid of the dreaded "delay"?
I read a bunch of posts in the forum, looking for an answer, and might have missed one like mine.
After much head-banging, it's time to bring in the heavy artillery!
Thanks,
John