ME 405
balance Namespace Reference

Variables

 pin_E1CH1 = pyb.Pin(pyb.Pin.cpu.B6)
 The pin object connected to Encoder 1's channel 1. More...
 
 pin_E1CH2 = pyb.Pin(pyb.Pin.cpu.B7)
 The pin object connected to Encoder 1's channel 2. More...
 
 e1 = EncDriver('E1', pin_E1CH1, 1, pin_E1CH2, 2, 4, 1000, False)
 An encoder object representing the encoder attached to Motor 1. More...
 
 pin_E2CH1 = pyb.Pin(pyb.Pin.cpu.C6)
 The pin object connected to Encoder 2's channel 1. More...
 
 pin_E2CH2 = pyb.Pin(pyb.Pin.cpu.C7)
 The pin object connected to Encoder 2's channel 2. More...
 
 e2 = EncDriver('E2', pin_E2CH1, 1, pin_E2CH2, 2, 8, 1000, False)
 An encoder object representing the encoder attached to Motor 2. More...
 
int enc_conv = -60/110
 Conversion factor for encoder angle to platform angle. More...
 
 pin_nSLEEP = pyb.Pin(pyb.Pin.cpu.A15, pyb.Pin.OUT_PP)
 The pin object used for the H-bridge sleep pin. More...
 
 pin_nFAULT = pyb.Pin(pyb.Pin.board.PB2, pyb.Pin.IN)
 The pin object used for the motor driver fault pin. More...
 
 pin_IN1 = pyb.Pin(pyb.Pin.cpu.B4)
 The pin object used for the Motor 1's H-bridge input 1. More...
 
 pin_IN2 = pyb.Pin(pyb.Pin.cpu.B5)
 The pin object used for the Motor 1's H-bridge input 2. More...
 
 pin_IN3 = pyb.Pin(pyb.Pin.cpu.B0)
 The pin object used for the Motor 2's H-bridge input 1. More...
 
 pin_IN4 = pyb.Pin(pyb.Pin.cpu.B1)
 The pin object used for the Motor 2's H-bridge input 2. More...
 
 tim = pyb.Timer(3,freq=20000);
 The timer object used for PWM generation. More...
 
 mA = MotorDriver(pin_nSLEEP, pin_nFAULT, pin_IN1, 1, pin_IN2, 2, tim, new_db=2.5, dead_band=(-45,45), debug=False, primary=True)
 A motor object passing in the pins and timer. More...
 
 mB = MotorDriver(pin_nSLEEP, pin_nFAULT, pin_IN3, 3, pin_IN4, 4, tim, new_db=2.5, dead_band=(-45,45))
 A second motor object passing in the pins and timer. More...
 
 PIN_xm = Pin(Pin.cpu.A0)
 The Nucleo pin connected to RTP xm. More...
 
 PIN_xp = Pin(Pin.cpu.A1)
 The Nucleo pin connected to RTP xp. More...
 
 PIN_ym = Pin(Pin.cpu.A6)
 The Nucleo pin connected to RTP ym. More...
 
 PIN_yp = Pin(Pin.cpu.A7)
 The Nucleo pin connected to RTP yp. More...
 
 RTP = RTP(PIN_xm,PIN_xp,PIN_ym,PIN_yp,(176,100),(88,50),filt='fir',debug=False)
 The RTP objct. More...
 
 i2c = I2C(-1, scl=Pin('PB8'), sda=Pin('PB9'), freq=115200)
 Initializes the I2C bus. More...
 
 imu = BNO055(i2c)
 Initializes the bno055 driver using the I2C object. More...
 
list Kplaty = [-14.4129, -0.00223331]
 Y axis reduced system gains. More...
 
list Kplatx = [-8.4129, -0.00223331]
 X axis reduced system gains. More...
 
list Ksysy = [-14.17333, -14.4129, -1.254464, -0.00223331]
 Y axis full system gains. More...
 
list Ksysx = [-14.17333, -10.4129, -2.54464, -0.00223331]
 X axis full system gains. More...
 
int Vdc = 18
 Motor nominal voltage [V]. More...
 
float Kt = 13.8/10**3
 Motor torque constant [Nm/A]. More...
 
float R = 2.21
 Motor terminal resistance [Ohms]. More...
 
float conv = R/(Kt*Vdc)
 Torque to PWM duty conversion factor. More...
 
 plat_y = FSFB('KPY', Kplaty,100, conv=conv)
 FSFB controller for the y-axis of the platform only system. More...
 
 plat_x = FSFB('KPX', Kplatx, 100, conv=conv)
 FSFB controller for the x-axis of the platform only system. More...
 
 sys_y = FSFB('KY', Ksysy, 100, conv=conv)
 FSFB controller for the y-axis of the full system. More...
 
 sys_x = FSFB('KX', Ksysx, 100, conv=conv)
 FSFB controller for the x-axis of the full system. More...
 
int x_duty = 0
 PWM duty sent to motor A controlling platform x-axis. More...
 
int y_duty = 0
 PWM duty sent to motor B controlling platform y-axis. More...
 
int bal_lim = 20
 Hand balancing limits in degrees. More...
 
int runs = 1
 Number of runs. More...
 
 start_time = utime.ticks_us()
 Start time of the data collection. More...
 
 last_time = start_time
 Last time of the data collection. More...
 
 curr_time = start_time
 Current time of the data collection. More...
 
 el_time = curr_time - start_time
 Elapsed time. More...
 
int dt = 5*10**3
 Desired controller time step. More...
 
 next_time = start_time
 Time of next run. More...
 
int dt_meas = 1
 Measured controller time interval. More...
 
int dt_avg = 1
 Average measued time interval. More...
 
 uart = UART(2)
 UART communication line for debugging. More...
 
tuple pos = (0,0,0)
 Ball Position from the touch pannel (x,y,z) in [m]. More...
 
tuple prev_pos = (0,0,0)
 Previous ball Position from the touch pannel (x,y,z) in [m]. More...
 
tuple vel = (0,0,0)
 Ball Velocity from the touch pannel in [m/s]. More...
 
tuple thta = (0,0,0)
 Platform angle [rad]. More...
 
tuple omga = (0,0,0)
 Platform angular velocity [rad/s]. More...
 
int steady_count = 0
 A counter that increments when the platform is stable. More...
 
int contact_count = 0
 A counter that increments when the ball is off of the platform. More...
 
 offset = curr_time
 Elapsed time offset, recorded on the first run. More...
 

Variable Documentation

◆ bal_lim

int balance.bal_lim = 20

Hand balancing limits in degrees.

◆ contact_count

int balance.contact_count = 0

A counter that increments when the ball is off of the platform.

◆ conv

float balance.conv = R/(Kt*Vdc)

Torque to PWM duty conversion factor.

◆ curr_time

balance.curr_time = start_time

Current time of the data collection.

◆ dt

int balance.dt = 5*10**3

Desired controller time step.

◆ dt_avg

tuple balance.dt_avg = 1

Average measued time interval.

◆ dt_meas

int balance.dt_meas = 1

Measured controller time interval.

◆ e1

balance.e1 = EncDriver('E1', pin_E1CH1, 1, pin_E1CH2, 2, 4, 1000, False)

An encoder object representing the encoder attached to Motor 1.

◆ e2

balance.e2 = EncDriver('E2', pin_E2CH1, 1, pin_E2CH2, 2, 8, 1000, False)

An encoder object representing the encoder attached to Motor 2.

◆ el_time

int balance.el_time = curr_time - start_time

Elapsed time.

◆ enc_conv

int balance.enc_conv = -60/110

Conversion factor for encoder angle to platform angle.

◆ i2c

balance.i2c = I2C(-1, scl=Pin('PB8'), sda=Pin('PB9'), freq=115200)

Initializes the I2C bus.

◆ imu

balance.imu = BNO055(i2c)

Initializes the bno055 driver using the I2C object.

◆ Kplatx

list balance.Kplatx = [-8.4129, -0.00223331]

X axis reduced system gains.

◆ Kplaty

list balance.Kplaty = [-14.4129, -0.00223331]

Y axis reduced system gains.

◆ Ksysx

list balance.Ksysx = [-14.17333, -10.4129, -2.54464, -0.00223331]

X axis full system gains.

◆ Ksysy

list balance.Ksysy = [-14.17333, -14.4129, -1.254464, -0.00223331]

Y axis full system gains.

◆ Kt

float balance.Kt = 13.8/10**3

Motor torque constant [Nm/A].

◆ last_time

balance.last_time = start_time

Last time of the data collection.

◆ mA

balance.mA = MotorDriver(pin_nSLEEP, pin_nFAULT, pin_IN1, 1, pin_IN2, 2, tim, new_db=2.5, dead_band=(-45,45), debug=False, primary=True)

A motor object passing in the pins and timer.

◆ mB

balance.mB = MotorDriver(pin_nSLEEP, pin_nFAULT, pin_IN3, 3, pin_IN4, 4, tim, new_db=2.5, dead_band=(-45,45))

A second motor object passing in the pins and timer.

◆ next_time

balance.next_time = start_time

Time of next run.

◆ offset

balance.offset = curr_time

Elapsed time offset, recorded on the first run.

◆ omga

tuple balance.omga = (0,0,0)

Platform angular velocity [rad/s].

◆ pin_E1CH1

balance.pin_E1CH1 = pyb.Pin(pyb.Pin.cpu.B6)

The pin object connected to Encoder 1's channel 1.

◆ pin_E1CH2

balance.pin_E1CH2 = pyb.Pin(pyb.Pin.cpu.B7)

The pin object connected to Encoder 1's channel 2.

◆ pin_E2CH1

balance.pin_E2CH1 = pyb.Pin(pyb.Pin.cpu.C6)

The pin object connected to Encoder 2's channel 1.

◆ pin_E2CH2

balance.pin_E2CH2 = pyb.Pin(pyb.Pin.cpu.C7)

The pin object connected to Encoder 2's channel 2.

◆ pin_IN1

balance.pin_IN1 = pyb.Pin(pyb.Pin.cpu.B4)

The pin object used for the Motor 1's H-bridge input 1.

◆ pin_IN2

balance.pin_IN2 = pyb.Pin(pyb.Pin.cpu.B5)

The pin object used for the Motor 1's H-bridge input 2.

◆ pin_IN3

balance.pin_IN3 = pyb.Pin(pyb.Pin.cpu.B0)

The pin object used for the Motor 2's H-bridge input 1.

◆ pin_IN4

balance.pin_IN4 = pyb.Pin(pyb.Pin.cpu.B1)

The pin object used for the Motor 2's H-bridge input 2.

◆ pin_nFAULT

balance.pin_nFAULT = pyb.Pin(pyb.Pin.board.PB2, pyb.Pin.IN)

The pin object used for the motor driver fault pin.

Here the user-button is used to simulate a fault for testing behavior.

◆ pin_nSLEEP

balance.pin_nSLEEP = pyb.Pin(pyb.Pin.cpu.A15, pyb.Pin.OUT_PP)

The pin object used for the H-bridge sleep pin.

◆ PIN_xm

balance.PIN_xm = Pin(Pin.cpu.A0)

The Nucleo pin connected to RTP xm.

◆ PIN_xp

balance.PIN_xp = Pin(Pin.cpu.A1)

The Nucleo pin connected to RTP xp.

◆ PIN_ym

balance.PIN_ym = Pin(Pin.cpu.A6)

The Nucleo pin connected to RTP ym.

◆ PIN_yp

balance.PIN_yp = Pin(Pin.cpu.A7)

The Nucleo pin connected to RTP yp.

◆ plat_x

balance.plat_x = FSFB('KPX', Kplatx, 100, conv=conv)

FSFB controller for the x-axis of the platform only system.

◆ plat_y

balance.plat_y = FSFB('KPY', Kplaty,100, conv=conv)

FSFB controller for the y-axis of the platform only system.

◆ pos

balance.pos = (0,0,0)

Ball Position from the touch pannel (x,y,z) in [m].

◆ prev_pos

tuple balance.prev_pos = (0,0,0)

Previous ball Position from the touch pannel (x,y,z) in [m].

◆ R

float balance.R = 2.21

Motor terminal resistance [Ohms].

◆ RTP

balance.RTP = RTP(PIN_xm,PIN_xp,PIN_ym,PIN_yp,(176,100),(88,50),filt='fir',debug=False)

The RTP objct.

◆ runs

int balance.runs = 1

Number of runs.

◆ start_time

balance.start_time = utime.ticks_us()

Start time of the data collection.

◆ steady_count

int balance.steady_count = 0

A counter that increments when the platform is stable.

◆ sys_x

balance.sys_x = FSFB('KX', Ksysx, 100, conv=conv)

FSFB controller for the x-axis of the full system.

◆ sys_y

balance.sys_y = FSFB('KY', Ksysy, 100, conv=conv)

FSFB controller for the y-axis of the full system.

◆ thta

tuple balance.thta = (0,0,0)

Platform angle [rad].

◆ tim

balance.tim = pyb.Timer(3,freq=20000);

The timer object used for PWM generation.

◆ uart

balance.uart = UART(2)

UART communication line for debugging.

◆ Vdc

int balance.Vdc = 18

Motor nominal voltage [V].

◆ vel

tuple balance.vel = (0,0,0)

Ball Velocity from the touch pannel in [m/s].

◆ x_duty

balance.x_duty = 0

PWM duty sent to motor A controlling platform x-axis.

◆ y_duty

balance.y_duty = 0

PWM duty sent to motor B controlling platform y-axis.