Greetings,
I was wondering if anyone has any advice on 2 major issues I am seeing with my current project.
Summary: I have an Arduino Micro attached to 2 speed controllers whose rpm's are determined by a simple hall effect throttle. The design uses an RFID reader that acts as a security gate such that the speed controllers are shut down when not authenticated.
Problems:
-
I am getting slight jolting movements on the engines attached to my speed controllers. when the user of this device is not authorized or throttle is off I am sending a 1 ms pulse to the speed controllers. As documented in the device's pdf this is the correct "off" setting. This jolting movement is intermittent but occurs when the throttle is off. It seems like it might be some sort of electronic echo but I am not a electrical engineer.
-
when running the engines using the hall effect throttle to control rpm's occasionally one engine will just shut down and the other keeps running. then if i power down and start up again the engines will run well for awhile but the issue is frequent enough that it has to get fixed. I am using 2 Servo instances to send messages to the speed controllers.
here is my code. :
#include <Servo.h>
#include <SoftwareSerial.h>
//Virtual Serial Port RX,TX
SoftwareSerial rfidPort(10,11);
//RFID variables
char davidHoff[13] = "7C00563B9988";
String testID;
char tagID[12];
char tagRead;
int loopIndex = 0;
int readIndex = 0;
int ignoreIndex = 0;
int awayCount = 0;
int RFIDResetPin = 12;
boolean userAuthorized = false;
boolean completeTagRead = true;
unsigned long startTime;
unsigned long currentTime;
boolean startFound = false;
//Throttle Variables and Servo objects
Servo jetLeft;
Servo jetRight;
int hallLow = 22;
int hallHigh = 894;
int throttleHigh = 872;
int pulseBase = 1000;
int pulseInterval = 20000;
int calibrated = 1;
int jetPinLeft = 4;
int jetPinRight = 9;
//LED variables
int led = 7;
void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(RFIDResetPin, OUTPUT);
digitalWrite(RFIDResetPin, HIGH);
rfidPort.begin(9600);
jetLeft.attach(jetPinLeft);
jetRight.attach(jetPinRight);
}
void loop()
{
if(loopIndex == 0) {
resetRfidReader();
}
if (!rfidPort.available()) {
digitalWrite(led, LOW);
userAuthorized = false;
}
//wait for RFID Reset to occur
if(loopIndex > 15 ) {
if (rfidPort.available()) {
tagRead = rfidPort.read();
if(ignoreIndex > 4) {
if (tagRead == davidHoff[0]) {
startFound = true;
readIndex++;
loopIndex = 16;
} else {
if(startFound == true) {
if (tagRead != davidHoff[readIndex]){
completeTagRead = false;
}
readIndex++;
}
}
}
ignoreIndex++;
} else {
digitalWrite(led, LOW);
userAuthorized = false;
}
}
int pulseLength = readThrottle();
delay(10);
if (userAuthorized == true) {
digitalWrite(led, HIGH);
jetLeft.writeMicroseconds(pulseLength + pulseBase);
jetRight.writeMicroseconds(pulseLength + pulseBase);
delayMicroseconds(pulseInterval - pulseLength);
} else {
digitalWrite(led, LOW);
jetLeft.writeMicroseconds(1000);
jetRight.writeMicroseconds(1000);
delayMicroseconds(1900);
}
loopIndex++;
if (readIndex == 12 && completeTagRead == true) {
userAuthorized = true;
awayCount = 0;
}
if (completeTagRead == false) {
userAuthorized = false;
}
if (awayCount > 1) {
userAuthorized = false;
}
if (readIndex >= 12 || loopIndex >= 32) {
loopIndex = 0;
readIndex = 0;
ignoreIndex = 0;
startFound = false;
completeTagRead = true;
awayCount++;
}
}
int readThrottle()
{
int rawHE = analogRead(A5);
rawHE = rawHE - 22;
if (rawHE < 0 ) {
rawHE = 0;
}
int invert = throttleHigh - rawHE;
float ratio = invert/872.0;
int pulseLength = int(ratio * 1000.0);
return pulseLength;
}
void resetRfidReader()
{
///////////////////////////////////
//Reset the RFID reader to read again.
///////////////////////////////////
digitalWrite(RFIDResetPin, LOW);
digitalWrite(RFIDResetPin, HIGH);
}
any thoughts would be greatly appreciates.
Thanks!