Go Down

Topic: Wish list for Servo library enhancements (Read 2 times) previous topic - next topic

mem

A couple of recent threads have discussed servo enhancements such as setting the rate of servo movement or automatically sweeping at user provided speeds.
I would be interested to hear if these or other features would be a popular addition to the Servo library. No promises that suggestions will be quickly implemented but if a number if people want enhancements that fit within the spirit of the current library then it could be considered for a future release.

see: http://arduino.cc/forum/index.php/topic,61586.0.html
and: http://arduino.cc/forum/index.php/topic,68305.msg504226.html

vinceherman

Trim and Reversing are features in most RC transmitters.
I added those features to the servo library (a few versions old) for my own use.

mem


Trim and Reversing are features in most RC transmitters.
I added those features to the servo library (a few versions old) for my own use.


Yes, they are standard features on an RC transmitter, but I wonder if the ease of adding a map function to get this capability into a sketch is one reason why more people don't request this feature. How many bytes of RAM did you use for the trim functions.

One way of implementing trim without using and RAM is to modify the min and max values that can be set in the attach method. The resolution of these values is currently 4 microseconds, I wonder if that would be fine enough for trim settings?

robtillaart

Quick look in the lib:

Servo::write
1) negative values make no sense , replace  by unsigned int types ?
2) I don't like it that the param value in write() can have two distinct meanings.
Code: [Select]
void Servo::write(int value)  <<<<<<<<< make this unsigned int ??

  if(value < MIN_PULSE_WIDTH)
  {  // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
    if(value < 0) value = 0;     <<<<<<<<<<<<<< that line not needed if value is unsigned int
    if(value > 180) value = 180;
    value = map(value, 0, 180, SERVO_MIN(),  SERVO_MAX());     
  }
  this->writeMicroseconds(value);
}
==>

// only supports angles between 0..180
// use writeMicroseconds for pwm
void Servo::write(uint8_t value)

  if(value > 180) value = 180;
  this->writeMicroseconds(map(value, 0, 180, SERVO_MIN(),  SERVO_MAX()));     
}


Servo::writeMicroseconds
1) negative value make no sense , replace by unsigned int?
Code: [Select]
void Servo::writeMicroseconds(int value) 
==>
void Servo::writeMicroseconds(unsigned int value)[/code 


[b]Servo::attach[/b]
1) negative value make no sense , replace by unsigned int?
2) test MIN_PULSE_WIDTH <= min <= max <= MAX_PULSE_WIDTH?
uint8_t Servo::attach(int pin, int min, int max) 
==>
uint8_t Servo::attach(uint8_t pin, unsigned int min, unsigned int max)


Servo::read
1) strange values if ( this->servoIndex == INVALID_SERVO ); readMicroseconds returns value 0 << SERVO_MIN.
Code: [Select]
int Servo::read() // return the value as degrees
{
  return  map( this->readMicroseconds()+1, SERVO_MIN(), SERVO_MAX(), 0, 180);     
}
==>
int Servo::read() // return the value as degrees  && -1 if invalid.
{
  if ( this->servoIndex != INVALID_SERVO )
     return map( this->readMicroseconds()+1, SERVO_MIN(), SERVO_MAX(), 0, 180);
  return -1;   
}



Servo::readMicroseconds
1) return type of function differs from internal var pulsewidth; which is stricly speaking not needed
2) using -1 for invalid values..
Code: [Select]
int Servo::readMicroseconds()
{
  unsigned int pulsewidth;
  if( this->servoIndex != INVALID_SERVO )
    pulsewidth = ticksToUs(servos[this->servoIndex].ticks)  + TRIM_DURATION ;   // 12 aug 2009
  else
    pulsewidth  = 0;  //

  return pulsewidth;   
}
==>
int Servo::readMicroseconds()
{
  if( this->servoIndex != INVALID_SERVO )
    return ticksToUs(servos[this->servoIndex].ticks)  + TRIM_DURATION ;   // 12 aug 2009
  return -1;   
}


my 2 cents
Rob

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

bill2009

Not a concrete wish list item but i find myself struggling with the mismatch between real servos and the model. E.G. Many servos can't really rotate 180 and can't take pulses from 644 to 2400. If i set the limits to protect the servo i have to map the angle for Accuracy.

Go Up