def load_benchmark_canon(riders): """Returns the benchmark canonical matrices for each rider. Parameters ---------- riders : list A list of riders from ['Charlie', 'Jason', 'Luke']. Returns ------- canon : dictionary The M, C1, K0, and K2 matrices for each rider on the instrumented bicycle. """ path = '/media/Data/Documents/School/UC Davis/Bicycle Mechanics/BicycleParameters/data' canon = {} for rider in riders: if rider == 'Jason': bName = 'Rigid' else: bName= 'Rigidcl' bike = bp.Bicycle(bName, path) bike.add_rider(rider) canon[rider] = bike.canonical(nominal=True) return canon
def draw_plot(): bike = bp.Bicycle('Benchmark', pathToData=os.getcwd() + '\\data') # Alter Bicycle name #bike.add_rider('Jason', reCalc=True) plot = bike.plot_eigenvalues_vs_speed(speeds) plot.savefig( os.getcwd() + '\\assets\\eigen-plots\\defaults\\Benchmark.png') # Alter png name
def create_tables(bikeNames, groupName): bikes = [] for bike in bikeNames: bikes.append(bp.Bicycle(bike, pathToData=pathToData, forceRawCalc=True)) for typ in ['Measured', 'Benchmark']: tab = Table(typ, True, bikes) pathToTableFile = os.path.join(pathToTables, groupName + typ + '.rst') tab.create_rst_table(fileName=pathToTableFile) print('Tables created for', bikeNames)
def test_benchmark_eigenvalues(): expected = dtkbicycle.benchmark_matrices() path_to_package = os.path.split(bicycleparameters.__file__)[0] path_to_data = os.path.join(path_to_package, '..', 'data') benchmark = bicycleparameters.Bicycle('Benchmark', path_to_data, True, True) M, C1, K0, K2 = benchmark.canonical(nominal=True) nptest.assert_allclose(M, expected[0]) nptest.assert_allclose(C1, expected[1]) nptest.assert_allclose(K0, expected[2]) nptest.assert_allclose(K2, expected[3])
def whipple_state_space(rider, speed): """ x' = Ax + Bu + Fv x = [phi, delta, phiDot, deltaDot] u = [Tphi, Tdel] v = [Fcl] """ bicycleModel = LinearLateralForce() pathToData='/media/Data/Documents/School/UC Davis/Bicycle Mechanics/BicycleParameters/data/' if rider == 'Jason': bicycleName = 'Rigid' elif rider == 'Charlie' or rider == 'Luke': bicycleName = 'Rigidcl' bike = bp.Bicycle(bicycleName, pathToData) bike.add_rider(rider) # set the model parameters benchmarkPar = bp.io.remove_uncertainties(bike.parameters['Benchmark']) benchmarkPar['xcl'] = bike.parameters['Measured']['xcl'] benchmarkPar['zcl'] = bike.parameters['Measured']['zcl'] moorePar = bicycle.benchmark_to_moore(benchmarkPar) bicycleModel.set_parameters(moorePar) # set the default equilibrium point pitchAngle = bicycle.pitch_from_roll_and_steer(0., 0., moorePar['rf'], moorePar['rr'], moorePar['d1'], moorePar['d2'], moorePar['d3']) wheelAngSpeed = -speed / moorePar['rr'] equilibrium = np.zeros(len(bicycleModel.stateNames)) equilibrium[bicycleModel.stateNames.index('q5')] = pitchAngle equilibrium[bicycleModel.stateNames.index('u6')] = wheelAngSpeed bicycleModel.linear(equilibrium) states = ['q4', 'q7', 'u4', 'u7'] inputs = ['Fcl', 'T4', 'T7'] outputs = ['q4', 'q7', 'u4', 'u7'] A, B, C, D = bicycleModel.reduce_system(states, inputs, outputs) F = B[:, 0] B = B[:, 1:] return A, B, F
f = open('Whipple.py', 'r') except IOError: from altk import alparse alparse.alparse('Whipple', 'Whipple', code='Python') else: f.close() del f from Whipple import LinearWhipple # create the Whipple model (with my parameters) whip = LinearWhipple() # load the benchmark parameters pathToData = '/media/Data/Documents/School/UC Davis/Bicycle Mechanics/BicycleParameters/data/' benchmark = bp.Bicycle('Benchmark', pathToData) benchmarkPar = bp.io.remove_uncertainties(benchmark.parameters['Benchmark']) # convert to my parameter set moorePar = bicycle.benchmark_to_moore(benchmarkPar, oldMassCenter=False) whip.set_parameters(moorePar) # set the initial conditions to match Meijaard2007 speedNaught = 4.6 u6Naught = -speedNaught / moorePar['rr'] rollRateNaught = 0.5 pitchAngle = bicycle.pitch_from_roll_and_steer(0., 0., moorePar['rf'], moorePar['rr'], moorePar['d1'], moorePar['d2'], moorePar['d3']) # linearize about the nominal configuration equilibrium = np.zeros(len(whip.stateNames))
from scipy import io import bicycleparameters as bp from dtk import bicycle pathToParameters = '/media/Data/Documents/School/UC Davis/Bicycle Mechanics/BicycleParameters/data' rider = 'Luke' if rider == 'Jason': bikeName = 'Rigid' elif rider == 'Charlie' or rider == 'Luke': bikeName = 'Rigidcl' # load the rigid bicycle and seat Luke rigidWithRider = bp.Bicycle(bikeName, forceRawCalc=True, pathToData=pathToParameters) rigidWithRider.add_rider(rider, reCalc=True) h = rigidWithRider.human # find the inertia of the humans without arms, this is with respect to the # benchmark coordinate system and about the CoM of the subset of parts humanMass, humanCoM, humanInertia = h.combine_inertia( ('P', 'T', 'C', 'K1', 'K2', 'J1', 'J2')) riderPar = { 'IBxx': humanInertia[0, 0], 'IByy': humanInertia[1, 1], 'IBzz': humanInertia[2, 2], 'IBxz': humanInertia[2, 0], 'mB': humanMass, 'xB': humanCoM[0][0],
f = open('GyroBike.py', 'r') except IOError: from altk import alparse alparse.alparse('GyroBike', 'GyroBike', code='Python') else: f.close() del f from GyroBike import LinearGyroBike # create the linear gyrobike model gyrobike = LinearGyroBike() # create the gyro bike pathToData = '/media/Data/Documents/School/UC Davis/Bicycle Mechanics/BicycleParameters/data/' gyro = bp.Bicycle('Gyro', pathToData, forceRawCalc=True) # set the model parameters benchmarkPar = bp.io.remove_uncertainties(gyro.parameters['Benchmark']) moorePar = bicycle.benchmark_to_moore(benchmarkPar) moorePar['mg'] = benchmarkPar['mD'] moorePar['ig11'] = benchmarkPar['IDxx'] moorePar['ig22'] = benchmarkPar['IDyy'] gyrobike.set_parameters(moorePar) # set the default equilibrium point speedNaught = 0.5 # just over 1 mph, really slow walking pitchAngle = bicycle.pitch_from_roll_and_steer(0., 0., moorePar['rf'], moorePar['rr'], moorePar['d1'], moorePar['d2'], moorePar['d3']) wheelAngSpeed = -speedNaught / moorePar['rr']
#!/usr/bin/env python import matplotlib.pyplot as plt import bicycleparameters as bp # compare the benchmark parameters to some of the bicycles I measured pathToData = '/media/Data/Documents/School/UC Davis/Bicycle Mechanics/BicycleParameters/data' browser = bp.Bicycle('Browser', pathToData=pathToData, forceRawCalc=True) browser.add_rider('Jason') goldenRatio = (5**0.5 - 1.0) / 2.0 fig_width = 5.0 fig_height = fig_width * goldenRatio fig_size = [fig_width, fig_height] params = { 'axes.labelsize': 10, 'text.fontsize': 10, 'legend.fontsize': 10, 'xtick.labelsize': 8, 'ytick.labelsize': 8, 'text.usetex': True, 'figure.figsize': fig_size } plt.rcParams.update(params) speedFig = plt.figure() browser.compare_bode_speeds([0.5, 2.0, 6.0, 10.0], 1, 0, fig=speedFig) #sixLine = speedFig.ax2.lines[2] #sixLine.set_ydata(sixLine.get_ydata() + 360.)
def new_geo_plot(): bike = bp.Bicycle('Benchmark', pathToData=os.getcwd() + '\\data') plot = bike.plot_bicycle_geometry() plot.savefig(os.getcwd() + '\\assets\\geo-plots\\user-bikes\\dummy.png')
N = C * (s * eye(4) - A).adjugate() * B # These are the roll and steer numerator polynomials, respectively. phiTphi = N[0, 0] deltaTphi = N[1, 0] phiTdelta = N[0, 1] deltaTdelta = N[1, 1] # Find the zeros phiTphiZeros = roots(phiTphi, s, multiple=True) deltaTphiZeros = roots(deltaTphi, s, multiple=True) phiTdeltaZeros = roots(phiTdelta, s, multiple=True) deltaTdeltaZeros = roots(deltaTdelta, s, multiple=True) # Load a bicycle with some parameters and calculate the canonical matrices. pathToData = '/media/Data/Documents/School/UC Davis/Bicycle Mechanics/BicycleParameters/data' bicycle = bp.Bicycle('Rigidcl', pathToData=pathToData, forceRawCalc=True) bicycle.add_rider('Charlie') #bicycle = bp.Bicycle('Benchmark', pathToData=pathToData) Mn, C1n, K0n, K2n = bicycle.canonical() Mn = un.unumpy.nominal_values(Mn) C1n = un.unumpy.nominal_values(C1n) K0n = un.unumpy.nominal_values(K0n) K2n = un.unumpy.nominal_values(K2n) # Create a dictionary to substitute numerical values. # These are the benchmark bicycle parameters. #num = {M[0, 0] : 80.81722, #M[0, 1] : 2.31941332208709, #M[1, 0] : 2.31941332208709, #M[1, 1] : 0.29784188199686,
f = open('RiderLean.py', 'r') except IOError: from altk import alparse alparse.alparse('RiderLean', 'RiderLean', code='Python') else: f.close() del f from RiderLean import LinearRiderLean # create the linear bike model bike = LinearRiderLean() # load the benchmark parameters pathToData='/media/Data/Documents/School/UC Davis/Bicycle Mechanics/BicycleParameters/data/' bikeWithLegs = bp.Bicycle('Browserlegs', pathToData) #bikeWithLegs = bp.Bicycle('Lukelegs', pathToData) benchmarkPar = bp.io.remove_uncertainties(bikeWithLegs.parameters['Benchmark']) # convert to my parameter set moorePar = bicycle.benchmark_to_moore(benchmarkPar, oldMassCenter=False) pitchAngle = bicycle.pitch_from_roll_and_steer(0., 0., moorePar['rf'], moorePar['rr'], moorePar['d1'], moorePar['d2'], moorePar['d3']) # from my inertia model moorePar['d4'] = -1.011421527346159 + moorePar['rr'] moorePar['l5'] = 0.231223496809401 moorePar['l6'] = -1.283035074598082 + moorePar['rr'] - moorePar['d4'] moorePar['lam'] = pitchAngle moorePar['mg'] = 48.816 moorePar['ig11'] = 2.038073562525466
import bicycleparameters as bp import numpy as np bikeNames = ['Browserins', 'Browser', 'Pista', 'Fisher', 'Yellow', 'Yellowrev'] colors = ['k'] * 3 + ['gray'] * 3 linestyles = ['-', '-.', '--'] * 2 bikes = [] for name in bikeNames: bikes.append(bp.Bicycle(name, pathToData='../data')) speeds = np.linspace(0., 10., num=100) bp.plot_eigenvalues(bikes, speeds, colors=colors, linestyles=linestyles), largest=True) bp.plt.vlines([2.5, 5., 7.], -0.5, 4.) #bp.plt.savefig('../plots/largest.png') bp.plt.show()
#!/usr/bin/env python import numpy as np import bicycleparameters as bp from dtk import bicycle pathToData = '/media/Data/Documents/School/UC Davis/Bicycle Mechanics/BicycleParameters/data' speeds = np.linspace(0., 10., num=100) # compare a bike with rider and bike without rider stratos = bp.Bicycle('Stratos', pathToData=pathToData, forceRawCalc=True) stratosRider = bp.Bicycle('Stratos', pathToData=pathToData, forceRawCalc=True) stratosRider.add_rider('Jason') compareRider = bp.plot_eigenvalues([stratos, stratosRider], speeds) ax = compareRider.axes[0] ax.set_ylim(-10, 10) ax.legend_.get_texts()[1].set_text('Stratos + Jason') compareRider.savefig('../../figures/parameterstudy/compare-rider-eig.png', dpi=200) # compare the benchmark parameters to some of the bicycles I measured benchmark = bp.Bicycle('Benchmark', pathToData=pathToData) browser = bp.Bicycle('Browser', pathToData=pathToData, forceRawCalc=True) browser.add_rider('Jason') stratos = bp.Bicycle('Stratos', pathToData=pathToData, forceRawCalc=True) stratos.add_rider('Jason') benchmarkReal = bp.plot_eigenvalues([benchmark, browser, stratos], speeds)
def plot_update(value, wheel, frame, general, options, slider): # accesses Input properties to avoid redundancies ctx = dash.callback_context wheelData = ctx.inputs.get('wheel-table.data') frameData = ctx.inputs.get('frame-table.data') genData = ctx.inputs.get('general-table.data') checklistData = ctx.inputs.get('geometry-checklist.value') rangeSliderData = ctx.inputs.get('range-slider.value') # construct flags for selected values of the geometry plot display options mass_boolean = 'centers' in checklistData ellipse_boolean = 'ellipse' in checklistData # sets the speed range for eigen-plot based on range-slider minBound = rangeSliderData[0] maxBound = rangeSliderData[1] steps = (maxBound - minBound) / 0.1 speeds = np.linspace(minBound, maxBound, num=int(steps)) Bike = bp.Bicycle(value, pathToData=path_to_app_data) # must convert steer axis tilt into radians when recieving values from the datatables if ctx.triggered[0].get('prop_id') != 'bike-dropdown.value': # convert to radians degrees = float(genData[2].get('con')) radians = np.deg2rad(degrees) genData[2]['con'] = radians # creates an alternating list of [parameter,value] from table data newP = [] for p in range(8): if p < 4: newP.extend([pList[p], wheelData[p].get('fW')]) else: newP.extend([pList[p], wheelData[p - 4].get('rW')]) for p in range(12, len(pList)): if p < 19: newP.extend([pList[p], frameData[p - 12].get('rB')]) else: newP.extend([pList[p], frameData[p - 19].get('fA')]) for p in range(8, 12): newP.extend([pList[p], genData[p - 8].get('con')]) # edits bicycle parameters based on table data for i in range(0, len(newP), 2): Bike.parameters['Benchmark'][newP[i]] = newP[i + 1] # create geometry-plot image geo_fake = io.BytesIO() geo_plot = Bike.plot_bicycle_geometry(show=False, centerOfMass=mass_boolean, inertiaEllipse=ellipse_boolean) geo_plot.savefig(geo_fake) geo_image = base64.b64encode(geo_fake.getvalue()) plt.close(geo_plot) # create eigen-plot image eigen_fake = io.BytesIO() eigen_plot = Bike.plot_eigenvalues_vs_speed(speeds, show=False, grid=True, show_legend=False) eigen_plot.savefig(eigen_fake) eigen_image = base64.b64encode(eigen_fake.getvalue()) plt.close(eigen_plot) return 'data:image/png;base64,{}'.format( geo_image.decode()), 'data:image/png;base64,{}'.format( eigen_image.decode())
def new_par(bike_name): bike = bp.Bicycle(bike_name, pathToData=path_to_app_data) par = bike.parameters['Benchmark'] parPure = bp.io.remove_uncertainties(par) return parPure