![]() |
Storing functions to variables
I am trying to set a variable, type double, to a function that calculates distance. This is the code I have.
Quote:
|
Re: Storing functions to variables
If I read this correctly, you're trying to make a function that returns a distance.
Code:
|
Re: Storing functions to variables
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.
Quote:
|
Re: Storing functions to variables
Remember that in C, those aren't functions or equations. They are statements, executed once.
To assign a function to a variable would be something like: Code:
(type omitted) myfunc = tan;Code:
int tilt_angD = ((((int)TILT_SERVO - 124) * 65)/124));Just be careful about your floating-point expressions, the RC doesn't like them much. |
Re: Storing functions to variables
Thanks for the help, but nothing has worked so far. We still have the same problem.
|
Re: Storing functions to variables
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.
|
Re: Storing functions to variables
3 Attachment(s)
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.
|
Re: Storing functions to variables
when you call the function simply put TILT_SERVO in the parameter
i.e : Code:
double rangejust 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 Code:
tiltD = ((tiltS - 124) * 65) / 124;Code:
tiltD = ((tiltS - 124) * 65) / 124.0; |
Re: Storing functions to variables
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.
|
| All times are GMT -5. The time now is 04:12. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi