Serial Wombat Arduino Library

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SerialWombatServo Class Reference

A class to control Servos attached to the Serial Wombat chip. More...

`#include <SerialWombatServo.h>`

Inheritance diagram for SerialWombatServo:
[legend]
Collaboration diagram for SerialWombatServo:
[legend]

## Public Member Functions
| SerialWombatServo (SerialWombatChip &sw)
| Constructor for the SerialWombatServo Class.
void | attach (uint8_t pin, bool reverse)
| Initialize a servo on the specified pin.
void | attach (uint8_t pin, uint16_t min=544, uint16_t max=2400, bool reverse=false)
| Initialize a servo on the specified pin.
void | write (uint8_t angle)
| Writes a value to the servo.
void | write16bit (uint16_t position)
| Writes a 16 bit value to the servo.
uint8_t | read (void)
| returns the last position of the servo scaled to a number from 0 to 180.
Public Member Functions inherited from SerialWombatPin
| SerialWombatPin (SerialWombatChip &serialWombatChip)
| Instantiates a Serial Wombat Pin.
| SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
| Instantiates a Serial Wombat Pin.
uint16_t | readPublicData ()
| Read the 16 Bit public data associated with this pin.
void | pinMode (uint8_t mode, bool pullDown=false, bool openDrain=false)
| Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings.
void | digitalWrite (uint8_t val)
| Set output pin High or Low.
int | digitalRead ()
| Reads the state of the Pin.
uint16_t | writePublicData (uint16_t value)
| Write a 16 bit value to this pin.
uint8_t | pin ()
| Returns the current SW pin number. Used primarily for virtual calls by derived classes.
uint8_t | swPinModeNumber ()
| Returns the Mode number. Used primarily by derived classes to populate packet data.
int16_t | initPacketNoResponse (uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55)
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55)
int16_t | disable ()
| Disables the pin mode (if applicable)
int16_t | enablePullup (bool enabled)
| Enables the weak pull up on a pin. Implemented on SW18AB and SW8B only.
int16_t | enablePulldown (bool enabled)
| Enables the weak pull down on a pin. Implemented on SW18AB and SW8B only.
int16_t | enableOpenDrain (bool enabled)
| Enables open drain mode on a pin. Implemented on SW18AB and SW8B only.
int16_t | forceDMA (bool enabled)
| Forces use of DMA instead of hardware timing resources on SW18AB.
void | setPinNumberForTesting (uint8_t pin)
| A function designed for testing only. May have unpredictable results if used in real time. Not intended for general use.

## Protected Member Functions
void | initializeServo ()

## Protected Attributes
uint16_t | _position = 0
uint16_t | _min = 544
uint16_t | _max = 2400
bool | _reverse = false
Protected Attributes inherited from SerialWombatPin
uint8_t | _pin = 255
SerialWombatChip & | _sw
uint8_t | _pinMode = 0

## Detailed Description

A class to control Servos attached to the Serial Wombat chip.

The SerialWombatServo class is used to control hobby servos attached to the Serial Wombat chip.

Any output-capable pin may be attached to an instance of the SerialWombatServo class. A separate instance should be declared for each Servo.

On the Serial Wombat 4A and Serial Wombat 4B chips servo output pulses are timed to 1uS precision using a timer interrupt.

On the Serial Wombat 18AB chip all Enhanced Digital Capability output pins (0-4,7,9-19) can be timed to sub-microsecond precision by sharing hardware timing resources (assuming resources are avaialble and have not be permanently claimed by PWM pin modes or other pin modes that claim and hold timing resources).

For SW18AB pins that are not enhanced, or if timing resources are not available the pin mode will degrade to using DMA based output with 17uS resolution. This equates to slightly better than 7 bit resolution for a 500-2500uS pulse range servo.

The SW4B_Ard_Servo example included with the Arduino library shows how to use this class.

This class uses "attach" rather than "begin" to initialize servos to be consistent with the Arduino Servo native API.

A Tutorial video is also avaialble:

https://youtu.be/WiciAtS1ng0

Definition at line 68 of file SerialWombatServo.h.

## Constructor & Destructor Documentation

## ◆ SerialWombatServo()

SerialWombatServo::SerialWombatServo | ( | SerialWombatChip & | sw | ) |
| inline

Constructor for the SerialWombatServo Class.

Parameters

  sw | A reference to a previously declared SerialWombatChip to which the Servo is connected.

Definition at line 76 of file SerialWombatServo.h.

## Member Function Documentation

## ◆ attach() [1/2]

void SerialWombatServo::attach | ( | uint8_t | pin,
|  | bool | reverse )
| inline

Initialize a servo on the specified pin.

This function must be called after the SerialWombatChip instance specified in the constructor has been initialized with a begin call.

This function initializes a servo with a minimum pulse of 544 uS and a maximum pulse of 2400uS to be consistent with the native Arduino API attach function.

Parameters

  pin | The Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3
  reverse | If true, the pulse widths will be reversed, with the longest pulse width corresponding to 0 position.

Definition at line 92 of file SerialWombatServo.h.

## ◆ attach() [2/2]

void SerialWombatServo::attach | ( | uint8_t | pin,
|  | uint16_t | min = 544,
|  | uint16_t | max = 2400,
|  | bool | reverse = false )
| inline

Initialize a servo on the specified pin.

This function must be called after the SerialWombatChip instance specified in the constructor has been initialized with a begin call.

Parameters

  pin | The Serial Wombat pin to set. Valid values for SW4A: 0-3 SW4B: 1-3
  min | Minimum pulse width in uS. Minimum functional value is 100.
  max | Maximum pulse width in uS
  reverse | If true, the pulse widths will be reversed, with the longest pulse width corresponding to 0 position.

Definition at line 111 of file SerialWombatServo.h.

## ◆ initializeServo()

void SerialWombatServo::initializeServo | ( |  | ) |
| inline protected

Definition at line 173 of file SerialWombatServo.h.

## ◆ read()

uint8_t SerialWombatServo::read | ( | void |  | ) |
| inline

returns the last position of the servo scaled to a number from 0 to 180.

Returns
  A position value from 0 to 180.

Definition at line 160 of file SerialWombatServo.h.

## ◆ write()

void SerialWombatServo::write | ( | uint8_t | angle | ) |
| inline

Writes a value to the servo.

This funciton allows setting the "angle" of a servo, although actual travel may vary. Consider using the SerialWombatServo function write16bit() for higher resolution

Parameters

  angle | A value from 0 to 180

Definition at line 129 of file SerialWombatServo.h.

## ◆ write16bit()

void SerialWombatServo::write16bit | ( | uint16_t | position | ) |
| inline

Writes a 16 bit value to the servo.

This funciton scales the pulse width of the signal being sent to the servo.

Parameters

  position | Servo position. 0 sends the minimum pulse width. 65535 sends the maximum pulse width (unless Reverse is enabled)

Definition at line 149 of file SerialWombatServo.h.

## Member Data Documentation

## ◆ _max

uint16_t SerialWombatServo::_max = 2400
| protected

Definition at line 171 of file SerialWombatServo.h.

## ◆ _min

uint16_t SerialWombatServo::_min = 544
| protected

Definition at line 170 of file SerialWombatServo.h.

## ◆ _position

uint16_t SerialWombatServo::_position = 0
| protected

Definition at line 169 of file SerialWombatServo.h.

## ◆ _reverse

bool SerialWombatServo::_reverse = false
| protected

Definition at line 172 of file SerialWombatServo.h.