Subject:
|
Re: My first servo try! Cool! (C Question)
|
Newsgroups:
|
lugnet.robotics.handyboard
|
Date:
|
Tue, 27 Oct 1998 14:37:18 GMT
|
Original-From:
|
Bert Pirson <pirson@SPAMLESScalspan.com>
|
Viewed:
|
1438 times
|
| |
| |
>
> Q1) The servo_deg() function requires a float. How do I
> get it to use an integer if I want to put it in a loop and
> use an integer variable?
>
>
easy way:
for (angle=1; angle<10; angle++)
servo_deg((float)angle)
better way:
modify functions from servo.c to accept integers:
int servo_deg_int(int)angle)
{
return servo(degree_to_pulse(angle));
}
int degree_to_pulse_int((int)angle)
{
int dexcursion_int = 180;
return (((angle*(SERVO_RANGE))/dexcursion_int)+MIN_SERVO_WAVETIME);
}
You could also replace degree_to_pulse_int() with an array of pulse lengths.
For 180 degrees this would use 362 bytes but would be faster. Its the trade
off between speed and memory constraints.
int servo_deg_int(int)angle)
{
int degree_to_pulse[181] = {1400, 1418, 1436, ... etc.};
return servo(degree_to_pulse[angle]);
}
Have not tried this code, but I don't think there are any typos.
You should also check to make sure angle is within the range of your servo
since none of the servo functions have any error checking.
Bert
|
|
1 Message in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|