![]() |
Value of degree to calculate range?
Hi everyone. I'm not sure if what I'm doing to get the degree for the tilt_servo to find the range of the bot to the rack is correct.
I wrote this in tracking.c at the very bottom: Code:
unsigned float Find_Distance(void)pan angle = ((current pan PWM) - (pan center PWM)) * degrees/pan PWM step ?(other than I'm looking for tilt rather than pan). Do I have to subtract my pwm07 by something like you did in this one? Sorry if I'm being confusing, but I'm trying to understand all of this at once. (My team is made up of 5 people and I'm the only electrician and the only programmer and I don't have much experience as a junior in high school.) |
Re: Value of degree to calculate range?
i dunno where you learned that you need radians... i use degrees. if you look in tracking.H, you'll see the upper and lower servo limits are (i think) 160 and 94. It also says that that's approximately +25 deg and -25 deg. so degrees per servo step is 25/33. then, you need to find the number of servo steps either up or down. i did something like:
Code:
unsigned float Find_Distance(void) |
Re: Value of degree to calculate range?
I wrote like Kevin's suggestion:
Code:
float range_to_target(void) |
Re: Value of degree to calculate range?
We are looking for the Tilt_AngleMy tracking.H file says that the tilt min is 94 and the tilt max is 194. So, the center of that would then be 144, right? (It also says that Tilt_Center_Pwm_Default is 144). So, shouldn't the equation then be:
unsigned float Find_Distance(void) { float angle; float range; angle = (TILT_SERVO-144)*.757575; range = HEIGHT_DIFF /*that's 116- camera height*/ /tan(angle); return(range) } also, where did you get 25/33 from? where'd the 33 come from? Also, what does this mean? Code:
#define TILT_SEARCH_STEP_SIZE_DEFAULT 50 |
Re: Value of degree to calculate range?
I think it would be more efficient to just create a lookup table which maps PWM values to Range Values, you can do all the pre-calculations in Excel or something.
just create a static const array, it will be stored in read only memory so you don't have to worry too much about the size of the array Code:
static const int lookup = { 1,2,3....4};now say you only have a pwm range from 90-150 (61 different values) lookup[60] would be the range value for pwm 150, so for the look up function you could do something like this: Code:
int getRange(int pwm)because you really don't need that much precision (if the range is in inches) and it would just be a waste of memory |
Re: Value of degree to calculate range?
I dont understand whats wrong with what I did. I'm not using an arraylist or anything of that sort. I just want to know, for the pwm value at which the tiltservo is at NOW, what is its angle? thereafter, what is the range from the bot to the rack?
|
Re: Value of degree to calculate range?
the <math.h> header has a tan() function in it. And in the standard header file the function accepts radians as an input. I have it coded this way, and it works reliably for me. The best thing you can do is to set the camera to its centers and then recenter the servos so you know for sure where the center values are.
|
Re: Value of degree to calculate range?
Quote:
|
Re: Value of degree to calculate range?
How might I go about doing that then. I see now the advantages of it, but I am a first year programmer and I actually just learned what an array is last week in school. Any hints on how to set that up in the code would be extremely helpful and appreciated!
|
Re: Value of degree to calculate range?
First off, the way you learn arrays in java probably is at a much higher level (you probably learn about Vectors/ArrayLists and other top level containers)
For robots we are dealing with simple arrays, So like I mentioned above all you need to do is simply calculate your PWM->Tilt Conversion table (in Excel or manually) If you want to do it manually you could printf the TILT_ANGLE , then measure how far your robot is from the light. Collect a few key data points (20-30) then interpolate between them. Then just create an array which has each range value in it. |
Re: Value of degree to calculate range?
Quote:
|
Re: Value of degree to calculate range?
2 Attachment(s)
First to clarify: Math functions in the C library work with radians, not degrees.
Here is excerpt from MPLAB C18 libraries manual: tan Function: Compute the tangent. Include: math.h Prototype: float tan( float x ); Remarks: Computes the tangent of x (in radians). A domain error occurs if the argument is infinite or NaN. Both cases return NaN. Return Value: The tangent of x. File Name: tan.c Attached is spread sheet for calculating a look-up table. Copy and paste the data from the Range Text column to create your array. See rangelu.c for example of completed array. When you need to use the array declare as extern in that file. extern const rom unsigned short targetRange[]; If you use Kevin's changes to increase resolution on the tilt axis. The number of table entries will need to increase and the PWM TO DEGREES factor will need to be changed. |
Re: Value of degree to calculate range?
So this is what I have so far. My pwmTILT is pwm07. My default center Tilt is 144 because the min is 94 and the max is 194. Also, the tilt_serach_step default is 50, so it makes 3 stops for tilt. Here is my code now, does this make sense?
Code:
const rom unsigned short targetRange[] =(ALSO, my camera does not function properly. It turns on, everything is dandy, but it does not track the light well. It has only locked onto the light once out of many tries. The camera will often face quite to the left of the actual light and then it will go up and down in short steps very fast. Any suggestions?) |
Re: Value of degree to calculate range?
I actually just realized that I have to change the numbers in the array because I have to recalculate the height of my camera, so the numbers will be a little different. Lets say I'm working with this, though. What I'm worried about is this:
Code:
unsigned int Find_Distance(void) |
Re: Value of degree to calculate range?
ahh no ones responding and im still confused!
Sorry to be a bother, but we're stuck here. Thanks |
| All times are GMT -5. The time now is 15:04. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi