Ok, well here is a full explanation.
First picture shows our actuator. It goes into the motor controller and is supplied by the GND and 12V wire that is unplugged(circled), it is wrapped in a type of tape(forgot name) to try to defer the interference by did not help.
i.imgur.com/7cMzW.jpg
Second picture is the whole back of cart with all the wiring. Shows the actuator wiring in red, 5V rail, 12V rail and 36V rail. The green are the signal wires going into the arduino from the pots in the front. Have the +5V coming from the pots and the black wire from the pots to GND.
i.imgur.com/M1FBk.jpg
So, my main problem is interference with the possible 12V wire that is going to the motor controller for the actuator(circled in red). When this 12V wire is disconnected and not powering the actuator…I can press all the pots and everything prints out great with no interference.
When I connect the actuator up, I press the brake pot and I get a lot of the steering pot interference without it even being touched. The Gas pedal pot is fine. When I turn the steering pot I get no interference with anything…it’s only when I press the brake pot is when I get interference from the steering pot and it records values without even being touched. We have tried moving wires, disconnecting the steering pot from the +5V but it still records a little(if I remember correctly). Only thing we can think of right is is to run the 12V/GND source to the actuator motor controller underneath the piece of wood everything is on. Or wrap the wire in the tape we have(forgot name, I did not do it).
Any possible solutions or thoughts?
Here is my code that it could possible have a problem, but like I said…it outputs perfect for all pots when the actuator is not powered.
typedef enum {
NONE, GOT_B, GOT_G, GOT_S, GOT_W}
states;
#include <SoftwareSerial.h>
#define rxBrake 3 //not used
#define txBrake 5 //pin5 connects to RX motor controller
SoftwareSerial brake = SoftwareSerial(rxBrake, txBrake);
#define errorPin 4 //pin for error, high or low
// current state-machine state
states state = NONE;
// current partial number
unsigned int currentValue;
void setup ()
{
Serial.begin (9600);
brake.begin(9600);
brake.write(0xAA);
state = NONE;
exitSafeStart();
} // end of setup
void exitSafeStart()
{
brake.write(0x83);
}
int processBrake (const unsigned int value)
{
// do something with brake
Serial.print ("Brake = ");
Serial.println (value);
static int previousValue = 0;
if(value > 200)
{
if(value > 900)
{
Serial.println("All the way");
setBrake(-3200);
}
else if(value > previousValue)
{
Serial.println("Brake is applied");
//int PWMval = map(value, 0,1023, 0,64); //PWM between 0-255 with 255 being max
//motorForward(PWMval/8);
setBrake(-3200); //full-speed reverse
}
else if(previousValue > value)
{
Serial.println("Decreasing Value, Brake not applied");
setBrake(3200);
}
}
else
{
Serial.println("Brake is not applied");
setBrake(3200); //full-speed forward
}
previousValue = value;
return value;
}
//Brake
void setBrake(int brakeVal)
{
//both directions take two speed bytes
//first byte is low five bits of speed
//second byte is high seven bits of speed
//both commands are the same, only just direction
if(brakeVal < 0)
{
Serial.println("Brake Motor Reverse");
//sets motor target speed in reverse
//must be number 0-3200
brake.write(0x86);
brakeVal = -brakeVal;
}
else
{
Serial.println("Brake Motor Forward");
brake.write(0x85); //motor forward command
}
brake.write(brakeVal & 0x1F);
brake.write(brakeVal >> 5);
}
/****END BRAKE******/
void processGas (const unsigned int value)
{
// do something with gas
Serial.print ("Gas = ");
Serial.println (value);
}
void processSteer (const unsigned int value)
{
// do something with steer
Serial.print ("Steer = ");
Serial.println (value);
} // end of processGear
void processWheel(const unsigned int value)
{
Serial.print("Wheel = ");
Serial.println(value);
}
void handlePreviousState ()
{
switch (state)
{
case GOT_B:
static int check = 0;
if(abs(currentValue-check) > 150)
break;
else
check = processBrake(currentValue);
break;
case GOT_G:
processGas (currentValue);
break;
case GOT_S: //processes first part of Sxxx,xxx
processSteer (currentValue);
break;
case GOT_W:
processWheel(currentValue);
break;
} // end of switch
currentValue = 0;
} // end of handlePreviousState
void processIncomingByte (const byte c)
{
if (isdigit (c))
{
currentValue *= 10;
currentValue += c - '0';
} // end of digit
else
{
// The end of the number signals a state change
handlePreviousState ();
// set the new state, if we recognize it
switch (c)
{
case 'B':
state = GOT_B;
break;
case 'G':
state = GOT_G;
break;
case 'S':
state = GOT_S;
break;
case 'W':
state = GOT_W;
break;
default:
state = NONE;
break;
} // end of switch on incoming byte
} // end of not digit
} // end of processIncomingByte
void loop ()
{
if (Serial.available ())
processIncomingByte (Serial.read ());
//if error is stopping motor, try to re-enable the motor
if(digitalRead(errorPin) == HIGH)
{
exitSafeStart();
}
} // end of loop
Output with actuator powered, the first part is me actually turning the steer/wheel pot and values change and it is smooth. Once I start turning the brake pot I get interference as you can see and the steer/wheel pot just shows the current value it is at.
Steer = 692
Wheel = 612
Steer = 714
Wheel = 613
Steer = 759
Wheel = 613
Steer = 781
Wheel = 612
Steer = 759
Wheel = 613
Steer = 737
Wheel = 610
Steer = 714
Wheel = 610
Steer = 692
Wheel = 613
Steer = 669
Wheel = 609
Steer = 692
Wheel = 612
Steer = 714
Wheel = 613
Steer = 760
Wheel = 612
Steer = 782
Wheel = 613
Steer = 804
Wheel = 614
Steer = 782
Wheel = 612
Steer = 760
Wheel = 613
Steer = 738
Wheel = 615
Steer = 715
Brake = 129
Brake is not applied
Brake Motor Forward
Brake = 146
Brake is not applied
Brake Motor Forward
Steer = 636
Wheel = 613
Steer = 684
Wheel = 6
Brake = 146
Brake is not applied
Brake Motor Forward
Wheel = 605
Brake = 120
Brake is not applied
Brake Motor Forward
Brake = 146
Brake is not applied
Brake Motor Forward
Steer = 640
Wheel = 61
Brake = 124
Brake is not applied
Brake Motor Forward
Brake = 144
Brake is not applied
Brake Motor Forward
Brake = 120
Brake is not applied
Brake Motor Forward
Brake = 145
Brake is not applied
Brake Motor Forward
Wheel = 612
Steer = 63
Wheel = 617
Wheel = 613
Steer = 0
Wheel = 611
Wheel = 61
Steer = 70
Steer = 6
Wheel = 609
Steer = 673
Wheel = 614
Steer = 40
Wheel = 0
Steer = 672
Brake = 118
Brake is not applied
Brake Motor Forward
Brake = 124
Brake is not applied
Brake Motor Forward
Brake = 0
Brake is not applied
Brake Motor Forward
Steer = 649
Steer = 679
Steer = 643
Wheel = 612
Steer = 671
Wheel = 617
Brake = 117
Brake is not applied
Brake Motor Forward
Brake = 145
Brake is not applied
Brake Motor Forward
Steer = 639
Wheel = 613
Wheel = 0
Brake = 0
Brake is not applied
Brake Motor Forward
Output with the actuator not powered, 12V unplugged
Brake = 147
Brake is not applied
Brake Motor Forward
Brake = 164
Brake is not applied
Brake Motor Forward
Brake = 180
Brake is not applied
Brake Motor Forward
Brake = 196
Brake is not applied
Brake Motor Forward
Brake = 180
Brake is not applied
Brake Motor Forward
Brake = 162
Brake is not applied
Brake Motor Forward
Brake = 146
Brake is not applied
Brake Motor Forward
Brake = 162
Brake is not applied
Brake Motor Forward
Brake = 178
Brake is not applied
Brake Motor Forward
Brake = 194
Brake is not applied
Brake Motor Forward
Brake = 210
Brake is applied
Brake Motor Reverse
Brake = 226
Brake is applied
Brake Motor Reverse
Brake = 258
Brake is applied
Brake Motor Reverse
Brake = 274
Brake is applied
Brake Motor Reverse
Brake = 290
Brake is applied
Brake Motor Reverse
Brake = 306
Brake is applied
Brake Motor Reverse
Brake = 323
Brake is applied
Brake Motor Reverse
Brake = 339
Brake is applied
Brake Motor Reverse
Brake = 387
Brake is applied
Brake Motor Reverse
Brake = 404
Brake is applied
Brake Motor Reverse
Brake = 420
Brake is applied
Brake Motor Reverse
Brake = 437
Brake is applied
Brake Motor Reverse
Brake = 454
Brake is applied
Brake Motor Reverse
Brake = 470
Brake is applied
Brake Motor Reverse
Brake = 486
Brake is applied
Brake Motor Reverse
Brake = 534
Brake is applied
Brake Motor Reverse
Brake = 680
Brake is applied
Brake Motor Reverse
Brake = 828
Brake is applied
Brake Motor Reverse
Brake = 893
Brake is applied
Brake Motor Reverse
Brake = 975
All the way
Brake Motor Reverse
Brake = 1023
All the way
Brake Motor Reverse
Brake = 1007
All the way
Brake Motor Reverse
Brake = 988
All the way
Brake Motor Reverse
Brake = 971
All the way
Brake Motor Reverse
Brake = 950
All the way
Brake Motor Reverse
Brake = 933
All the way
Brake Motor Reverse
Brake = 915
All the way
Brake Motor Reverse
Brake = 898
Decreasing Value, Brake not applied
Brake Motor Forward
Brake = 881
Decreasing Value, Brake not applied
Brake Motor Forward
Brake = 860
Decreasing Value, Brake not applied
Brake Motor Forward
Brake = 843
Decreasing Value, Brake not applied
Brake Motor Forward
Brake = 824
Decreasing Value, Brake not applied
Brake Motor Forward
Brake = 805
Decreasing Value, Brake not applied
Brake Motor Forward
Brake = 783
Decreasing Value, Brake not applied
Brake Motor Forward
Brake = 767