Encoder driver class. More...
Public Member Functions | |
| def | __init__ (self, pin1, pin2, timerNum, debugFlag=False) |
Constructor for class encoder More... | |
| def | update (self) |
| Updates encoder position. More... | |
| def | get_position (self) |
| Retrieves the current encoder position. More... | |
| def | set_position (self, newPosition) |
| Sets the encoder position. More... | |
| def | get_delta (self) |
| Retrieves the last change in encoder position (in ticks, not angle) More... | |
| def | get_speed (self) |
| Gets the current encoder speed in rpm. More... | |
Public Attributes | |
| debugFlag | |
| Debugging flag for print statements to be shown in Putty. | |
| timerNum | |
| Timer number on Nucleo board for encoder. | |
| pin1 | |
| Pin 1 for encoder. | |
| pin2 | |
| Pin 2 for encoder. | |
| tim | |
| definition of timer More... | |
| tim_ch1 | |
| First encoder timer channel. | |
| tim_ch2 | |
| Second encoder timer channel. | |
| lastTime | |
| Previous time, used for determining speed. | |
| currentTime | |
| Current absolute time in microseconds. | |
| lastPos | |
| Last position, updated at the end of each encoder update. | |
| theta | |
| Current angle (in degrees) of encoder. | |
| speed | |
| Current speed (in rpm) of encoder. | |
| realPeriod | |
| Time between updates, used for determining speed. | |
| currentPos | |
| Current encoder count. | |
| deltaTicks | |
| Difference in encoder count since last update. More... | |
Encoder driver class.
Class for implementing methods related to encoders, such as getting the most recent position or speed or updating the count.
| def encoder.encoder.__init__ | ( | self, | |
| pin1, | |||
| pin2, | |||
| timerNum, | |||
debugFlag = False |
|||
| ) |
Constructor for class encoder
| pin1 | Encoder pin # 1 |
| pin2 | Encoder pin # 2 |
| timerNum | Corresponding timer based on datasheet |
| debugFlag | Debugging flag set to True or False |
| def encoder.encoder.get_delta | ( | self | ) |
Retrieves the last change in encoder position (in ticks, not angle)
Can be called from the PC side script
| def encoder.encoder.get_position | ( | self | ) |
Retrieves the current encoder position.
Used by the controller task, as well as being callable by key press from the PC script
| def encoder.encoder.get_speed | ( | self | ) |
Gets the current encoder speed in rpm.
Used by the controller task, as well as being callable by key press from the PC script
| def encoder.encoder.set_position | ( | self, | |
| newPosition | |||
| ) |
Sets the encoder position.
Can be called from the front end to zero an encoder position
| newPosition | Takes in the new desired encoder position value |
| def encoder.encoder.update | ( | self | ) |
Updates encoder position.
This method implements an alogrithm developed in lecture for interpreting tick count changes into correct changes in encoder angular displacement. The encoder count can overflow or underflow, so these values are not enough on their own.
| encoder.encoder.deltaTicks |
Difference in encoder count since last update.
This value will be adjusted based on algorithm
| encoder.encoder.tim |
definition of timer
Period of 35535 (encoder count before overflow occurs), prescaler of 0