Originally Posted by
rogster001
At the moment targetPos and currentPos are local to the functions you have delcared them in, they will not exist after the curly braces in each of those functions.
You need to show a bit more code perhaps to clarify what your aim is, at present whatever you are trying won't work because target and current exist seperately from one another.
You understand? At it is, As soon as pSteer() completes then targetPos has gone. And likewise in pWheel() and currentPos
Yea, that is what I understand. My problem is trying to use targetPos and currentPos before they are gone. Maybe claudiu explained it with the return.
Originally Posted by
claudiu
You should have those two functions "return" what you want, and use those values as arguments for your other function.
Ok, so changed the code a little to return the value and call the calculateError function again.
Code:
int pSteer (const unsigned int value)
{
int steering = constrain(value, 400, 1023);
int targetPos = map(steering, 400, 1023, -100, 100);
//calculateError(targetPos);
return targetPos;
}
void pWheel(const unsigned int value)
{
int wheel = constrain(value, 150, 480);
int currentPos = map(wheelInput, 150, 480, -100,100);
//calculateError(currentPos);
return currentPos;
}
void calculateError(int currentPos, int targetPos)
{
int error = targetPos - currentPos;
}
void loop() //This is the main
{
//calculateError(targetPos,currentPos); //error when this is used, guess it is wrong.
}