405 Documentation  9.0
mainWithnFault.py File Reference

An attempt at balancing the table. More...

Functions

def mainWithnFault.fault_isr (fault)
 Fault ISR. More...
 
def mainWithnFault.fix_isr (fix)
 Fix ISR. More...
 

Variables

int mainWithnFault.faultflag = 0
 Flag for faulting. More...
 
 mainWithnFault.fault = pyb.Pin.board.PB2
 Fault pin. More...
 
 mainWithnFault.extint = pyb.ExtInt(pyb.Pin.board.PB2, pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_UP, fault_isr)
 External Interrupt Object. More...
 
 mainWithnFault.fix = pyb.Pin.board.PC13
 Fix pin @Pin to be pressed that would fix the faults.
 
 mainWithnFault.fixtint = pyb.ExtInt(pyb.Pin.board.PC13, pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_UP, fix_isr)
 External Interrupt Object. More...
 
 mainWithnFault.var = MotorDriver(pyb.Pin.board.PA15, pyb.Pin.board.PB4, pyb.Pin.board.PB5, 3, 1, 2)
 X axis motor. More...
 
 mainWithnFault.var2 = MotorDriver(pyb.Pin.board.PA15, pyb.Pin.board.PB0, pyb.Pin.board.PB1, 3, 3, 4)
 Y axis motor. More...
 
 mainWithnFault.balancer = EncoderDriver(pyb.Pin.board.PB6, pyb.Pin.board.PB7, 1, 2, pyb.Timer(4, prescaler = 7, period = 0x7fffffff))
 X axis Motor encoder. More...
 
 mainWithnFault.balancer2 = EncoderDriver(pyb.Pin.board.PC6, pyb.Pin.board.PC7, 1, 2, pyb.Timer(8, prescaler = 7, period = 0x7fffffff))
 Y axis Motor encoder. More...
 
int mainWithnFault.state = 0
 State flag. More...
 
int mainWithnFault.start = 300
 Fault ignore. More...
 
 mainWithnFault.adc = pyb.ADC(pyb.Pin.board.A0)
 ADC object. More...
 
int mainWithnFault.duty = 0
 Duty cycle value. More...
 
int mainWithnFault.duty2 = 0
 Duty cycle value. More...
 
int mainWithnFault.dut = 75
 New Duty cycle value. More...
 
int mainWithnFault.balanceval = 0
 Distance to go. More...
 
int mainWithnFault.balanceval2 = 0
 Distance to go. More...
 

Detailed Description

An attempt at balancing the table.

This file was simply an attempt at balancing the table on its own. To do so we set up the fault pin isr when there was a problem. We then created two motor driver and encoder objects to balance the table. At the beginning of the while loop we ignored the fault flag for a set amount of times because for some reason it kept triggering whenever we enabled the motors. From there we set the duty cycle based on distance the encoders were from their respective 0 points (where the table would be level). With this method the duty cycle would be proportional to how far the table was from level, but within a range of about 20 - 60% duty cycle. Part of this code is still there in the loop. It can be seen in the if statement where balanceval (where you want to be minus where you actually are at the moment) is between -1 and -32768; duty = (((balanceval/32768)*40)-20). In this case the maximum distance the encoder could be from where it wants to be was -32768, so if that was was the case then the duty cycle would be -60 (from the equation mentioned earlier). We also handled the the encoder being "farther" away too. Let us say that we are 32770 units away. Our new balance val would be -32770 (because where we want to be is zero), yet we because these readings exist on a circle we have actually gotten closer to zero. In this case we need to account for wanting our motor to turn the correct direction based on where it is. That is why for the next calculation of duty cycle we add balanceval to 65535 before dividing by 32768. By adding the positive 65535, which is the maximum distance on the encoder before turning back to zero, we account for the fact that 32768 is truly our farthest distance. Anything above it gets closer to zero as the number gets higher and anything below it gets closer to zero as the number gets lower. Feel free to take a look at the code, we thought it was quite crafty. However, one of the main problems we ran into was the friction in the motor arm joints. These were different to each arm and therefore made the input of the computation of duty cycle difficult because it required different bounds for different motions. It was easier for both motors to pull down rather than pull up and one motor struggled far more than the other. Additionally, it became quite clear that even though it would output a high duty cycle when pushed further and further, it would never reach that far. For that reason, when the displacement was low, the motors did not output enough power. That was why we switched to just setting the duty cycle based on which side of the encoder we were reading. Like before, being on the positive side or the negative side of the encoder mattered for which way we turned. This time though, instead of relating the duty to the displacement, we just gave it a set duty cycle no matter how far it was. The only thing that mattered was the sign of the duty based on the side it was on. This caused a lot of vibrating because when the duty was too low, it could not push the table at all when it was at anything more than a 10 degree angle from flat. When it was too high it could not settle down as it kept over shooting. Thus, this did not work out. There was too much code on one page so we changed it up and restarted in mainThatBalancedtheTable.py

Author
Jacob Everest
Hunter Morse
Date
Mar. 15, 2021

Function Documentation

◆ fault_isr()

def mainWithnFault.fault_isr (   fault)

Fault ISR.

Sets the faultflag to one if a fault isr has been triggered. Stops all functionality until resolved.

Author
Jacob Everest
Hunter Morse
Date
Mar. 15, 2021

◆ fix_isr()

def mainWithnFault.fix_isr (   fix)

Fix ISR.

Was meant to allow the user to press the blue button on the microcontroller to fix the fault interrupt. Didnt end up working

Author
Jacob Everest
Hunter Morse
Date
Mar. 15, 2021

Variable Documentation

◆ adc

mainWithnFault.adc = pyb.ADC(pyb.Pin.board.A0)

ADC object.

allowed us to connect PC13 to A0 and use the blue button to end the fault state

◆ balancer

mainWithnFault.balancer = EncoderDriver(pyb.Pin.board.PB6, pyb.Pin.board.PB7, 1, 2, pyb.Timer(4, prescaler = 7, period = 0x7fffffff))

X axis Motor encoder.

Encoder object that outputs position of the X axis motor

◆ balancer2

mainWithnFault.balancer2 = EncoderDriver(pyb.Pin.board.PC6, pyb.Pin.board.PC7, 1, 2, pyb.Timer(8, prescaler = 7, period = 0x7fffffff))

Y axis Motor encoder.

Encoder object that outputs position of the Y axis motor

◆ balanceval

mainWithnFault.balanceval = 0

Distance to go.

Value computed later that represents how far we are from where we need to be for balance around the x axis

◆ balanceval2

mainWithnFault.balanceval2 = 0

Distance to go.

Value computed later that represents how far we are from where we need to be for balance around the y axis

◆ dut

int mainWithnFault.dut = 75

New Duty cycle value.

Value used for duty cycle when proportionality became unwieldy

◆ duty

tuple mainWithnFault.duty = 0

Duty cycle value.

Percent of time X motor is receiving energy from PWM

◆ duty2

tuple mainWithnFault.duty2 = 0

Duty cycle value.

Percent of time Y motor is receiving energy from PWM

◆ extint

mainWithnFault.extint = pyb.ExtInt(pyb.Pin.board.PB2, pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_UP, fault_isr)

External Interrupt Object.

Allows the Fault interrupt to be called

◆ fault

mainWithnFault.fault = pyb.Pin.board.PB2

Fault pin.

Pin that the faults are dependent upon

◆ faultflag

int mainWithnFault.faultflag = 0

Flag for faulting.

when high, there has been a fault, when low, it's been resolved

◆ fixtint

mainWithnFault.fixtint = pyb.ExtInt(pyb.Pin.board.PC13, pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_UP, fix_isr)

External Interrupt Object.

Allows the Fix interrupt to be called

◆ start

int mainWithnFault.start = 300

Fault ignore.

Set number of cycles for which we will ignore the fault flag in order to give the motors time to get running before a real fault

◆ state

int mainWithnFault.state = 0

State flag.

What else do you want? It's the state flag

◆ var

mainWithnFault.var = MotorDriver(pyb.Pin.board.PA15, pyb.Pin.board.PB4, pyb.Pin.board.PB5, 3, 1, 2)

X axis motor.

Creates an object that controls the motor that pushes the table Around its widthwise axis

◆ var2

mainWithnFault.var2 = MotorDriver(pyb.Pin.board.PA15, pyb.Pin.board.PB0, pyb.Pin.board.PB1, 3, 3, 4)

Y axis motor.

Creates an object that controls the motor that pushes the table Around its lengthwise axis