I am trying to set a variable, type double, to a function that calculates distance. This is the code I have.
dist = 80.0/tan(tilt_angR);
If I use a printf statement to calculate and display “dist,” the value caclulates and prints properly. However, I need to set this value to a variable. Any help is appreciated.
Thanks for the help, but I have another problem. The variable tilt_angR is set to another function, and I am having the same problem as before. Here is my code.
I think we’re having difficulties divining what you’re attempting. If you could post some larger chunks of your code, such as where you’re calling these statements and an example of the code where the printfs are working. Don’t be shy about cutting and pasting a vast majority of your user_routines.c or zipping up some of your source files and attaching them to a post.
Ok, I have everything setup properly now, I think. The only thing I need to do is assign the variable ‘TILT_SERVO’ to the variable I pass into my function, ‘tiltS’. I am not sure where to declare my variable and how or where to set its value to ‘TILT_SERVO’. I have attached the three files I have edited for my code.
when you call the function simply put TILT_SERVO in the parameter
i.e :
double range
void someFunction ( blah blah)
{
range = DistanceCalc(TILT_SERVO);
}
or:
printf("The Distance is: %lf inches
", DistanceCalc(TILT_SERVO));
if you want to assign your variable the value TILT_SERVO
just declare it (outside of the main loop, towards the beginning of the file under the #defines)
like this: double tiltS;
then insidde your main loop put this code:
tiltS = TILT_SERVO;
this is probably redundant and un-necessary since you already have TILT_SERVO holding the value of the camera tilt
also you may want to be wary of this line
tiltD = ((tiltS - 124) * 65) / 124;
you should change it to this:
tiltD = ((tiltS - 124) * 65) / 124.0;
Just to clarify that you do not in any case want to do integer division
I do not want to do integer division, but I have to. The robot controller does not support floats or doubles. I have the function printing an int and dividing it by a number in order to get a proper answer in inches. If I use a float and type cast it to an int and divide by 100, the function prints a blank space.