Tells where the motor is at any given time. More...
Public Member Functions | |
| def | __init__ (self, idNum, pin1, pin2, ch1, ch2, timer) |
| Initialization Function. More... | |
| def | __repr__ (self) |
| Name it. More... | |
| def | update (self) |
| Update method. More... | |
| def | getPosition (self) |
| Method to get the position. More... | |
| def | setPosition (self, pos=0) |
| Saves the users desired position. More... | |
| def | getDelta (self) |
| Change in position. More... | |
Public Attributes | |
| id | |
| pin1 | |
| pin2 | |
| timer | |
| prevPosition | |
| position | |
| maxVal | |
Tells where the motor is at any given time.
Input 2 pins, 2 channels, and a timer object to run. Once given, this object will be able to read the motor position, update its position, set a desired position, compute its change in position, and compute how far it is from the users desired position. These position readings can be used to determine where the motor is at any given time relative to where it started as well as the motor speed.
| def encoderDriver.Encoder.__init__ | ( | self, | |
| idNum, | |||
| pin1, | |||
| pin2, | |||
| ch1, | |||
| ch2, | |||
| timer | |||
| ) |
Initialization Function.
Stores the parameters input by the user when creating the class object so that they may be used later by other functions.
| idNum | ID number of motor |
| pin1 | pin to read encoder chA values |
| pin2 | pin to read encoder chB values |
| ch1 | encoder channel A |
| ch2 | endcoder channel B |
| timer | timer to read encoder |
| def encoderDriver.Encoder.__repr__ | ( | self | ) |
| def encoderDriver.Encoder.getDelta | ( | self | ) |
Change in position.
Takes the two most recent values from the update method and computes the difference between the two. If the user were timing the system and taking values at a specific interval, this could be used to compute the speed of the motor. However, the user must use the update method after this one in order to change the most recent value and replace the prevPosition value with the position value, otherwise this method will return the same value over and over.
| None |
| def encoderDriver.Encoder.getPosition | ( | self | ) |
Method to get the position.
This method uses the counter method of our timer object to count how many ticks have gone by since the last time we passed our zero point on the encoder. That means that it simply tells us where we are in our encoder rotation. This method returns a numerical value which represents the motor position.
| None |
| def encoderDriver.Encoder.setPosition | ( | self, | |
pos = 0 |
|||
| ) |
Saves the users desired position.
The setPosition method allows the user to input a position which this method will then save as a value to be used at a later time. This value will most likely be zero, as the user will want to start their table off in a balanced state, otherwise the user will have no idea how far the system needs to go in order to become level.
| pos | An inputed value for the user, allowing them to choose where they want to be, default 0 |
| def encoderDriver.Encoder.update | ( | self | ) |
Update method.
Updates the position of the motor so that the user can later tell how far the motor has traveled. It stores the current value stored in the position variable as "prevPosition", then runs the getPosision() method that will be described later to put the current value for the position into the position variable. This way the most recent position value and the one before it are both stored somewhere. Does not return a value.
| None |