disabling with DMX
This commit is contained in:
parent
b92ed1a431
commit
a2e8c50392
24
src/main.cpp
24
src/main.cpp
@ -115,10 +115,7 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
if (DMXSerial.noDataSince() < 5000) {
|
|
||||||
targetPosition = (float)(DMXSerial.read(DMX_CHANNEL) - 101) / 100.0f; // 0 is disabled. position values are 1-201, 101 is center, <101 is CW, >101 is CCW. 1 & 201 are 360 degrees
|
|
||||||
digitalWrite(R_EN_PIN, HIGH);
|
|
||||||
digitalWrite(L_EN_PIN, HIGH);
|
|
||||||
|
|
||||||
if (micros() < prevSample) {
|
if (micros() < prevSample) {
|
||||||
// micros timer rolled over, so reset sample timer:
|
// micros timer rolled over, so reset sample timer:
|
||||||
@ -126,6 +123,12 @@ void loop() {
|
|||||||
prevSample = micros();
|
prevSample = micros();
|
||||||
currentPosition = encoderToPosition(encoderPosition);
|
currentPosition = encoderToPosition(encoderPosition);
|
||||||
} else if (micros() - prevSample >= SAMPLE_RATE) {
|
} else if (micros() - prevSample >= SAMPLE_RATE) {
|
||||||
|
if (DMXSerial.noDataSince() < 5000) {
|
||||||
|
int dmxVal = DMXSerial.read(DMX_CHANNEL);
|
||||||
|
if (dmxVal != 0) {
|
||||||
|
targetPosition = (float)(dmxVal - 101) / 100.0f; // 0 is disabled. position values are 1-201, 101 is center, <101 is CW, >101 is CCW. 1 & 201 are 360 degrees
|
||||||
|
digitalWrite(R_EN_PIN, HIGH);
|
||||||
|
digitalWrite(L_EN_PIN, HIGH);
|
||||||
// this can happen faster than control loop so that (TBD) smoothing function can be added
|
// this can happen faster than control loop so that (TBD) smoothing function can be added
|
||||||
prevPosition = currentPosition;
|
prevPosition = currentPosition;
|
||||||
double dt = (float (micros() - prevSample)) / (1.0e6f); // time since last sample (s)
|
double dt = (float (micros() - prevSample)) / (1.0e6f); // time since last sample (s)
|
||||||
@ -157,7 +160,6 @@ void loop() {
|
|||||||
Serial.print(" error: ");Serial.print(remainingDistance);
|
Serial.print(" error: ");Serial.print(remainingDistance);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
*/
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
if (pid.Compute()) {
|
if (pid.Compute()) {
|
||||||
// newPWM = motorPWM;
|
// newPWM = motorPWM;
|
||||||
@ -207,11 +209,21 @@ void loop() {
|
|||||||
// Serial.print(", mPWM: ");
|
// Serial.print(", mPWM: ");
|
||||||
// Serial.println(motorPWM);
|
// Serial.println(motorPWM);
|
||||||
}
|
}
|
||||||
// make sure DMX is still alive:
|
|
||||||
} else {
|
} else {
|
||||||
digitalWrite(R_EN_PIN, LOW);
|
digitalWrite(R_EN_PIN, LOW);
|
||||||
digitalWrite(L_EN_PIN, LOW);
|
digitalWrite(L_EN_PIN, LOW);
|
||||||
|
digitalWrite(LPWM_PIN, LOW);
|
||||||
|
digitalWrite(RPWM_PIN, LOW);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
digitalWrite(R_EN_PIN, LOW);
|
||||||
|
digitalWrite(L_EN_PIN, LOW);
|
||||||
|
digitalWrite(LPWM_PIN, LOW);
|
||||||
|
digitalWrite(RPWM_PIN, LOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// react to Serial input (new target position):
|
// react to Serial input (new target position):
|
||||||
// if (recvWithEndMarker()) {targetPosition = readNewTarget();}
|
// if (recvWithEndMarker()) {targetPosition = readNewTarget();}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user