To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.handyboardOpen lugnet.robotics.handyboard in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Handy Board / 4608
4607  |  4609
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
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR