An encoder driver object. More...
Public Member Functions | |
| def | __init__ (self, ID, Pin1, Ch1, Pin2, Ch2, tim_no, CPR, debug) |
| Creates an encoder object. More... | |
| def | update (self) |
| Updates the encoder. More... | |
| def | get_position (self, units) |
| Returns the encoder position in desired units. More... | |
| def | set_position (self) |
| Sets the encoder position to a specified value in ticks. More... | |
| def | get_delta (self, units) |
| Returns the current encoder delta in desired units. More... | |
| def | get_ddelta (self) |
| Returns the current encoder delta delta in ticks. More... | |
| def | convert (self) |
| Uses the raw encoder count values to calculate encoder position & delta in other units. More... | |
| def | trace (self) |
| Prints a trace output when called. More... | |
Public Attributes | |
| ID | |
| The unique ID string for the object, used for trace output. More... | |
| debug | |
| A boolean that toggles the trace output to the command line. More... | |
| tim | |
| The timer objct that is used to read the encoder. More... | |
| conv_deg | |
| Conversion factor ticks -> degrees. More... | |
| conv_rad | |
| Conversion factor ticks -> radians. More... | |
| pos | |
| The current position of the encoder. More... | |
| prev_pos | |
| The previous position of the encoder. More... | |
| delta | |
| The difference between the current position and the previous position. More... | |
| prev_delta | |
| The previous delta of the encoder. More... | |
| ddelta | |
| The difference between the current delta and the previous delta. More... | |
| last_count | |
| Previous encoder count. More... | |
| t1 | |
| Ticks value 1. More... | |
| t2 | |
| Ticks value 2 from counter. More... | |
| pos_deg | |
| Encoder position in degrees. More... | |
| pos_rad | |
| Encoder position in radians. More... | |
| delta_deg | |
| Encoder delta in degrees. More... | |
| delta_rad | |
| Encoder delta in radians. More... | |
An encoder driver object.
This class configures hardware, to monitor an encoder's position. The encoder ticks are counted using a timer object, and the timer is queried to get updated position values. The diver class corrects timer overflow errors, and is able to handle encoder rotation CW and CCW.
| def enc_driver.EncDriver.__init__ | ( | self, | |
| ID, | |||
| Pin1, | |||
| Ch1, | |||
| Pin2, | |||
| Ch2, | |||
| tim_no, | |||
| CPR, | |||
| debug | |||
| ) |
Creates an encoder object.
| ID | A string identifying the object for traceing output. |
| Pin1 | The pin object that will be bound to encoder channel A |
| Ch1 | The timer channel for the first pin |
| Pin2 | The pin object that will be bound to encoder channel B |
| Ch2 | The timer channel for the second pin |
| tim_no | The timer number that will be used to read the encoder |
| CPR | Encoder's cycles per revolution |
| debug | A boolean that toggles the trace output on or off |
| def enc_driver.EncDriver.convert | ( | self | ) |
Uses the raw encoder count values to calculate encoder position & delta in other units.
| def enc_driver.EncDriver.get_ddelta | ( | self | ) |
Returns the current encoder delta delta in ticks.
| def enc_driver.EncDriver.get_delta | ( | self, | |
| units | |||
| ) |
Returns the current encoder delta in desired units.
| def enc_driver.EncDriver.get_position | ( | self, | |
| units | |||
| ) |
Returns the encoder position in desired units.
| def enc_driver.EncDriver.set_position | ( | self | ) |
Sets the encoder position to a specified value in ticks.
| def enc_driver.EncDriver.trace | ( | self | ) |
Prints a trace output when called.
| def enc_driver.EncDriver.update | ( | self | ) |
Updates the encoder.
This function passes the position from the last call to the prev_pos atribute, calculates a new delta value, corrects the delta value, and updates the encoder position.
| enc_driver.EncDriver.conv_deg |
Conversion factor ticks -> degrees.
| enc_driver.EncDriver.conv_rad |
Conversion factor ticks -> radians.
| enc_driver.EncDriver.ddelta |
The difference between the current delta and the previous delta.
| enc_driver.EncDriver.debug |
A boolean that toggles the trace output to the command line.
| enc_driver.EncDriver.delta |
The difference between the current position and the previous position.
| enc_driver.EncDriver.delta_deg |
Encoder delta in degrees.
| enc_driver.EncDriver.delta_rad |
Encoder delta in radians.
| enc_driver.EncDriver.ID |
The unique ID string for the object, used for trace output.
| enc_driver.EncDriver.last_count |
Previous encoder count.
| enc_driver.EncDriver.pos |
The current position of the encoder.
| enc_driver.EncDriver.pos_deg |
Encoder position in degrees.
| enc_driver.EncDriver.pos_rad |
Encoder position in radians.
| enc_driver.EncDriver.prev_delta |
The previous delta of the encoder.
| enc_driver.EncDriver.prev_pos |
The previous position of the encoder.
| enc_driver.EncDriver.t1 |
Ticks value 1.
| enc_driver.EncDriver.t2 |
Ticks value 2 from counter.
| enc_driver.EncDriver.tim |
The timer objct that is used to read the encoder.
The prescaler is set to zero and the period is set to 0xFFFF or 65535