Hello all,
I'm creating an ag robot for help in a wineyard, its basically a fancy cart that you can control with RC controller atm.
The robot has a solenoid for steering and two driver motors in the back, I created a simple electronic differential so one wheel turns slower while you're steering on either side. Now I'm moving on to enabling additional features which will be turned on with a simple relay board. Relays switch on when the output is LOW.
The problem I'm having is this - when you increase the two motor drivers to full power (PWM outputs) the two unrelated digital outputs get turned on as well. As far as I can see in the code the outputs are not interchangeable at all so I have no clue where the values might get mixed up or is this a hardware issue?
Here is the code:
#define RCPinin 13 //gas
#define Feedback A3 //feedback
#define RCPinout1 2 //output 1
#define RCPinout2 3 //output 2
#define RCPinr13 45 //rele 1 in
#define RCPinr13out 36 //rele 1 out
#define RCPinr2 47 //rele 1 in
#define RCPinr2out 37 //rele 1 out
#define RCPinr3out 34 //rele 1 out
int input;
float output1;
float output2;
int inputr13;
int fba;
int fbacalc;
float fbakontravolan;
int voznja;
int rikverc;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(Feedback, INPUT);
pinMode(RCPinin, INPUT);
pinMode(RCPinr13, INPUT_PULLUP);
pinMode(RCPinr13out, OUTPUT);
pinMode(RCPinr2, INPUT_PULLUP);
pinMode(RCPinr3out, OUTPUT);
pinMode(RCPinr2out, OUTPUT);
}
void loop() {
fba = analogRead(Feedback);
fbacalc = map(fba, 130, 740, 0, 100);
input = pulseIn(RCPinin, HIGH);
voznja = digitalRead(RCPinr13);
digitalWrite(RCPinr13out, voznja);
rikverc = digitalRead(RCPinr2);
if(rikverc == 1)
{
digitalWrite(RCPinr2out, LOW);
digitalWrite(RCPinr3out, LOW);
}else
{
digitalWrite(RCPinr2out, HIGH);
digitalWrite(RCPinr3out, HIGH);
}
output1 = map(input, 812, 2169, 0, 100);
output2 = map(input, 812, 2169, 0, 100);
analogWrite(RCPinout1, output1);
analogWrite(RCPinout2, output2);
if(output1 >= 10 && fbacalc <= 45 && fbacalc >= 0)
{
fbakontravolan = map(fbacalc, 45, 0, 3, 50);
output2 = output2 - (output2 * (fbakontravolan / 100.0));
analogWrite(RCPinout1, output1);
analogWrite(RCPinout2, output2);
}
if(output1 >= 10 && fbacalc >= 55 && fbacalc <= 100)
{
fbakontravolan = map(fbacalc, 55, 100, 3, 50);
output1 = output1 - (output1 * (fbakontravolan / 100.0));
analogWrite(RCPinout1, output1);
analogWrite(RCPinout2, output2);
}
Serial.print("Feedback:");
Serial.print(fbacalc);
Serial.print(",");
Serial.print("Output_1:");
Serial.println(output1);
Serial.print(",");
Serial.print("Output_2:");
Serial.println(output2);
Serial.print(",");
Serial.print("Feedback_kontra:");
Serial.println(fbakontravolan);
Serial.print("Voznja:");
Serial.println(voznja);
Serial.print(",");
Serial.print("Rikverc:");
Serial.println(rikverc);
Serial.print(",");
}
