NoU_Servo

class NoU_Servo

Controls the output to one of the servo ports on the NoU2. The duty cycle of the 50 Hz PWM signal generated has 16 bits of precision (i.e. 0…65535).

Public Functions

NoU_Servo(uint8_t servoPort, uint16_t minPulse = 540, uint16_t maxPulse = 2300)

Constructs a new NoU_Servo on the specified port. The default values for minPulse and maxPulse have been configured experimentally for the range accepted by most common 9g servos, although each servo is a little different and often has slightly variant minimum and maximum pulse-widths.

Parameters:
  • uint8_t servoPort – The port number of the servo, visible in front of each set of servo pins on the NoU2.

  • uint16_t minPulse – The optional minimum pulse-width to send to the servo in microseconds, corresponding to 0°. See setMinimumPulse().

  • uint16_t minPulse – The optional maximum pulse-width to send to the servo in microseconds, corresponding to 180°. See setMaximumPulse().

void write(float degrees)

Commands the servo to move to the specified degree heading, based on the configured minimum and maximum pulse-widths.

Parameters:

float degrees – The degree heading to command the servo to move to. Maps 0° to the minimum pulse-width and 180° to the maximum pulse-width. Other values are interpolated linearly, including those outside the range of 0…180, although they will produce a pulse-width outside of the minimum and maxmimum.

void writeMicroseconds(uint16_t pulseLength)

Sends a PWM signal with the specified pulse-width to the servo. Ignores the configured minimum and maximum pulse-widths.

Parameters:

uint16_t pulseLength – The pulse-width in microseconds of the PWM signal to begin sending.

void setMinimumPulse(uint16_t minPulse)

Sets the pulse-width corresponding to 0° with regard to the write() function. This value can usually be found in the datasheet for a servo, although it should be noted that the actual minimum pulse-width for some servos can vary slightly from the reported values. To get the greatest range possible out of a servo, it can be necessary to experimentally tweak the minimum pulse-width until the servo is clearly at the edge of its range.

Parameters:

uint16_t minPulse – The pulse-width in microseconds corresponding to 0°.

void setMaximumPulse(uint16_t maxPulse)

Sets the pulse-width corresponding to 180° with regard to the write() function. This value can usually be found in the datasheet for a servo, although it should be noted that the actual maximum pulse-width for some servos can vary slightly from the reported values. To get the greatest range possible out of a servo, it can be necessary to experimentally tweak the maximum pulse-width until the servo is clearly at the edge of its range.

Parameters:

uint16_t maxPulse – The pulse-width in microseconds corresponding to 180°.

uint16_t getMicroseconds()

Gets the pulse-width in microseconds of the PWM signal currently being generated for this servo. Updates when write() and writeMicroseconds() are called.

Returns:

The pulse-width of the current output in microseconds.

float getDegrees()

Gets the pulse-width in degrees of the PWM signal currently being generated for this servo, based on the configured minimum and maximum pulse-widths. Updates when write() and writeMicroseconds() are called.

Returns:

The pulse-width of the current output in degees, with the configured minimum pulse-width being 0°, and the maximum being 180°.