Hello,
PROJECT BACKGROUND
I am using a linear actuator which I control with a force sensor, i.e increasing force makes the stroke go forward and decreasing force makes the stroke go backwards. The linear actuator I am using is the Actuonix L12 P model, this means it does have potion feedback which I have checked works appropriately using the serial monitor.
PROBLEM
I would like to have a maximum and minimum position for the LA. So for example it will stop moving forward when it is in position 750, despite there still being increasing force. My linear actuator and my force code work. But the maximum and minimum position code does not.
Here is my code
void loop()
{ int fsrADC = analogRead(FSR_PIN);
(fsrADC != 0); // If the analog reading is non-zero
float fsrV = fsrADC * VCC / 1023.0;
float fsrR = R_DIV * (VCC / fsrV - 1.0);
float force;
float fsrG = 1.0 / fsrR; // Calculate conductance
(fsrR <= 600);
force = (fsrG - 0.00075) / 0.00000032639;
force = fsrG / 0.000000642857;
int actuator_position = analogRead(feedback);
if (actuator_position> 760 || actuator_position<250)
{ brake();
}
if (force > 100)
{fwd(100); direct =1;}
else if (force < 20)
{rev(100); direct = 2;}
Serial.print(direct);
Serial.print(" actuator_position) = ");
Serial.print(actuator_position);
Serial.print(" Force (g) = ");
Serial.println(force);
}//end void loop
void fwd(int speed)
{ digitalWrite(AIN1, HIGH);
digitalWrite(AIN2, LOW);
analogWrite(PWMA, speed);
}
void rev(int speed)
{ digitalWrite(AIN1, LOW);
digitalWrite(AIN2, HIGH);
analogWrite(PWMA, speed);
}
void brake()
{ digitalWrite(AIN1, HIGH);
digitalWrite(AIN2, HIGH);
analogWrite(PWMA,0);
}
void standby()
{ digitalWrite(STBY, LOW);
}
void enable()
{ digitalWrite(STBY, HIGH);
}
I am using a motor driver chip TB6612FNG, this comes with a library which has a Forward, Reverse and Break function. I am using the Forward and Reverse successfully in my code. But the Break is not working in the MIN Max statement. Link to the motor driver if you want more info (https://learn.sparkfun.com/tutorials/tb6612fng-hookup-guide/all).
FYI, the Forward, Reverse and Break all use the 3 same pins, with different HIGH/LOW settings which I got from the official supplier website. As FWD and REV work, I assume the issue is with my IF statements.
Any help would be greatly appreciated.