Mechatronics Portfolio
Logan Williamson's Mechatronics Portfolio and Documentation Repository
|
A motor class for a motor object that is used to return a calculated duty cycle. More...
Public Member Functions | |
def | __init__ (self, PWM_tim, IN1_pin, IN2_pin, chA, chB) |
Initializes and returns an object associated with a DC Motor. More... | |
def | set_duty (self, duty) |
Set the PWM duty cycle for the motor channel. More... | |
Public Attributes | |
tim | |
creates a timer object tim using the Timer method More... | |
Pin1 | |
creates a pin object Pin1 connected to user input IN1_pin More... | |
Pin2 | |
creates a pin object Pin2 connected to user input IN2_pin More... | |
tim_ch1 | |
creates a timer channel object tim_ch1 More... | |
tim_ch2 | |
creates a timer channel object tim_ch2 More... | |
A motor class for a motor object that is used to return a calculated duty cycle.
Objects of this class can be used to apply PWM to a given DC motor. This effectively controls the speed of that motor due to the fact that motors work as low-pass filters.
def motor.Motor.__init__ | ( | self, | |
PWM_tim, | |||
IN1_pin, | |||
IN2_pin, | |||
chA, | |||
chB | |||
) |
Initializes and returns an object associated with a DC Motor.
Objects of this class should not be instantiated directly. Instead create a BNO055 object and use that to create Motor objects using the method BNO055.motor(). This will allow higher-level management of these motor objects by the task files that will utilize and manipulate them.
PWM_tim | Creates empty object for an input of pin position for the pin we desire to control all four channels of our pulse width modulation. In this case, we are using timer 3 on the STM32 Nucleo. |
IN1_pin | Creates empty object for an input of pin position. The pin passed into this parameter will be the first of two pins required to control the associated motor object instantiated by this class. |
IN2_pin | Creates empty object for an input of pin position. The pin passed into this parameter will be the second of two pins required to control the associated motor object instantiated by this class. |
chA | Creates empty object for an input of a pin channel. The pin channels will control the direction of rotation of the motor based on the sign of the duty cycle input to the set_duty method. |
chB | Creates empty object for an input of a pin channel. The pin channels will control the direction of rotation of the motor based on the sign of the duty cycle input to the set_duty method. |
def motor.Motor.set_duty | ( | self, | |
duty | |||
) |
Set the PWM duty cycle for the motor channel.
This method sets the duty cycle to be sent to the motor to the given level. Positive values cause effort in one direction, negative values in the opposite direction.
duty | A signed number holding the duty cycle of the PWM signal sent to the motor |
motor.Motor.Pin1 |
creates a pin object Pin1 connected to user input IN1_pin
User input chooses pin. For example, pin input by user can be Pin.cpu.B4
motor.Motor.Pin2 |
creates a pin object Pin2 connected to user input IN2_pin
User input chooses pin. For example, pin input by user can be Pin.cpu.B5
motor.Motor.tim |
creates a timer object tim using the Timer method
Timer object PWM_tim passed in by user for the timer at a preset frequency of 20_000
motor.Motor.tim_ch1 |
creates a timer channel object tim_ch1
tim_ch1 uses tim.channel connected to user input chA and IN1_pin configured in PWM_INVERTED (active low)
motor.Motor.tim_ch2 |
creates a timer channel object tim_ch2
tim_ch1 uses tim.channel connected to user input chA and IN1_pin configured in PWM_INVERTED (active low)