Thank you for helping. So, I see it is less complicated than I am making it.
So, to get the values that you used of 200 to 800 with the center being 500. Is that the same as me using the min and max of the steering wheel pot?
http://img560.imageshack.us/img560/7...ngwheelpin.jpg
Using this image, you can see I have a pin that allows me to go left and right only a certain distance. I have code wrote to output the value of the current steering input, so I need to find the min, max, and center using this method?
I will be able to use:
target = (input - 500) * (500/300) + 400;
Once I find the values of my pot?
Here is my code for the input arduino('target') and second arduino that is receiving this value.
Code:
int potPin = 0; // select input pin
int val = 0; // variable to store the value
void setup() {
Serial.begin(9600);
}
void loop()
{
val = analogRead(potPin); // read the value from the pot
Serial.println( val );
delay(1);
}
second arduino the receives the 'target' through xbee(This arduino also receives the value of the 'current' directly with the bottom wheel pot)
Code:
char string[8]; //can be 4, 8 is fine
int var;
int index;
boolean started=false;
boolean ended=false;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while(Serial.available() >= 0) //since 0-1023
{
var=Serial.read(); //read the character
if(var=='<') //not sure what to put in if statement to run until end
{
started = true;
index=0;
string[index]='\0';
}
else if(var=='>')
{
ended = true;
break; //break out of while loop when '>' received
}
else if(started)
{
string[index]=var;
index++;
string[index]='\0';
string[index]=var; //store character
}
//x = Serial.read(); //read another string
}
if(started && ended)
{
//convert portion of string to integer representation
int val=atoi(string);
Serial.print("<");
Serial.print(val);
Serial.print(">");
//next time
started = false;
ended = false;
index = 0;
string[index]='\0';
}
}
This second arduino will be able to compare the 'target' and 'current' values to use the 'P'. I plan to trial and error the Kp. Now it can use the:
current = readSensorValue();
error = target-current;
outputPower = error * kP;
That you mentioned.
Also, I plan to send the outputPower value to the roboclaw to determine left/right and how fast. Is this correct way? And I am a little confused on how exactly to send the value/data to the roboclaw for it to interpret.