class BicycleAdapter(Van): """docstring for BicycleAdapter""" def __init__(self): self.__bicycle = Bicycle() def drive(self): self.__bicycle.ride()
def __init__(self, render_game=False, human_input=False): self.render_game = render_game self.human_input = human_input if self.render_game: pygame.init() self.screen = pygame.display.set_mode((1000, 1000)) self.clock = pygame.time.Clock() self.bike = Bicycle() self.curr_time = 0 self.path = []
def setup_manufacturer1(): bikes = [] wheel = Wheel(5, 15, "basic mountain", 0) frame = Frame(10, 20, 2) bikes.append(Bicycle("El Rusty", wheel, wheel, frame)) wheel = Wheel(3, 25, "basic road", 1) frame = Frame(9, 100, 2) bikes.append(Bicycle("The Economical", wheel, wheel, frame)) wheel = Wheel(4, 50, "basic cross", 2) frame = Frame(7, 250, 0) bikes.append(Bicycle("Ol' Reliable", wheel, wheel, frame)) return Manufacturer("OK Bikes", bikes, .1)
def setup_manufacturer2(): bikes = [] wheel = Wheel(5, 75, "pro cross", 2) frame = Frame(7, 265, 0) bikes.append(Bicycle("The Bike", wheel, wheel, frame)) wheel = Wheel(2, 100, "pro road", 1) frame = Frame(3, 400, 1) bikes.append(Bicycle("Speedster", wheel, wheel, frame)) wheel = Wheel(1, 150, "True Road", 1) frame = Frame(1, 500, 1) bikes.append(Bicycle("SuperSpeed", wheel, wheel, frame)) return Manufacturer("Fast Bikes", bikes, .05)
def main(): test_bike = Bicycle() print("Front pressure:", test_bike.getfrontpressure()) print("Back pressure:", test_bike.getbackpressure()) test_bike.setfrontpressure(47) test_bike.setbackpressure(49) print("Front pressure:", test_bike.getfrontpressure()) print("Back pressure:", test_bike.getbackpressure()) print() """ test_bike.speedup() test_bike.speedup() print("Current Speed:", test_bike.getspeed()) test_bike.setfrontpressure(2) print("Flat Tire") test_bike.speedup() print("Current Speed:", test_bike.getspeed()) print() """ """
def testCarsAndBicycles(self): movers: List[Transportation] = [] movers.append(Car(10, 0.5)) movers.append(Car(15, 0.25)) movers.append(Bicycle("red")) for mover in movers: mover.start() for i in range(len(movers)): self.assertEqual(movers[i].going, True, f"i={i}") # think of movers[1] as a Car (not just transportation) car: Car = cast(Car, movers[1]) car.fuel = 0.0 self.assertEqual(movers[1].going, False)
def main(): vehicle = Vehicle() use_print(vehicle) print(vehicle) car = Car() use_print(car) print(car) plane = Plane(2) use_print(plane) print(plane) bicycle = Bicycle(4) use_print(bicycle) print(bicycle)
def make_bike(self, number, manufacturer="", margin=""): if not manufacturer: manufacturer = self.manufacturer_name if not margin: margin = self.margin bicycles = {} for number in range(number): while True: bike = Bicycle(manufacturer) if bike.model_name not in bicycles.keys(): bicycles[bike.model_name] = bike # Add the margin of the bike manufacturer to the cost of the bike bicycles[bike.model_name].cost *= 1 + margin bicycles[bike.model_name].cost = int( bicycles[bike.model_name].cost) break else: continue return bicycles
def get_synthetic_data(distributions): for dist in distributions[:-1]: drift_angle = np.random.normal(dist[0], dist[1]) print("Synthetic Drift Angle: ", drift_angle) model = Bicycle(drift_angle) # model.drive_open_loop() model.drive_along_path() ideal_model = Bicycle() ideal_model.drive_along_path() error_data = ideal_model.path_data - model.path_data # Plot results # plt.plot(ideal_model.path_data[:, 0], ideal_model.path_data[:, 1]) # plt.show() window = 0 plt.scatter(np.arange(window, error_data.shape[0]), error_data[window:, 0], label=dist[2]) plt.legend() plt.show()
def test_customer_can_afford_a_bike(self): ramona = Customer(name='Ramona', budget=200.0) rock_star = Bikeshop(' Rock Star', {'bianchi': 2, 'schwinn': 5, 'abici': 7, 'cinelli': 1, 'eagle': 2, 'falcon': 6}) bianchi = Bicycle('Bianchi', 6, 450.0) schwinn = Bicycle('Schwinn', 10, 100.0) abici = Bicycle('Abici', 5, 300.0) cinelli = Bicycle('Cinelli', 4, 400.0) eagle = Bicycle('Eagle', 6, 200.0) falcon = Bicycle('Falcon', 7, 930.0) bike_list = [bianchi, schwinn, abici, cinelli, eagle, falcon] # if ramona.budget >= rock_star.calculate_bike_cost(bianchi): # return True # else: # return False self.assertEqual(len(rock_star.check_budget(ramona, bike_list)), 1)
rear.a = 0.5139283534655644 rear.b = -0.2185938844305652 rear.c = 0.9637521999999999 front.Ixx = 0.1834745058089018 front.Iyy = 0.2257063173763909 front.Izz = 0.06923407270022158 front.Ixz = -0.009663296585475524 front.J = 0.09227403707515749 front.m = 2.95 front.R = 0.3358632190780645 front.r = 0 front.a = -0.02086466545111477 front.b = -0.1524559736777648 front.c = -0.0478155 ls = 0.3434334 # END Copy paste from output of data/physicalparameters/compute_model_parameters.py # Assumed g = 9.81 robotic_bicycle = Bicycle() robotic_bicycle.set_parameters(rear, front, ls, g) robotic_bicycle.solve_configuration_constraint_and_set_state() robotic_bicycle.set_steady_constraint_forces() benchmark_bicycle = Bicycle() w = Whipple() benchmark_bicycle.set_parameters(w) benchmark_bicycle.solve_configuration_constraint_and_set_state() benchmark_bicycle.set_steady_constraint_forces()
import sys import math import numpy as np import matplotlib.pyplot as plt from pid import PID from bicycle import Bicycle def main(model): model.driveOpenLoop(0, 'blue') if __name__ == '__main__': target = np.array([10.0, 10.0]) bicycle = Bicycle(target) main(bicycle)
from bicycle import Bicycle from bicycle import Customer from bicycle import Shops from bicycle import affordable_bikes #("Model Name", weight, production cost, inventory) models = Bicycle("X100", 20, 100, 25) models = Bicycle("X200", 15, 300, 23) models = Bicycle("X300", 12, 400, 21) models = Bicycle("X400", 10, 600, 19) models = Bicycle("X600", 8, 800, 12) customers = Customer("Alex",200) customers = Customer("Beth",500) customers = Customer("Charles",1000) shop = Shops(models) options = affordable_bikes(models,customers) shop.sell_bikes(models,customers,options)
steering = pid.steering velocity_next = pid.velocity y[i, :] = [ugv.y + velocity * math.sin(ugv.theta), i] ugv.dynamics(velocity, 0.0, fault, 0.1) y_dot[i, :] = [ugv.y, i] i += 1 path = np.array(ugv.path_data) print(path.shape) plt.plot(path[:, 0], path[:, 1]) plt.xlabel("x (meters)") plt.ylabel("y (meters)") plt.title("UGV Path: Problem 1.b)") # plt.gcf().gca().add_artist(Wedge(center=(int(start_point[0]), int(start_point[1])), r=1, theta1=45, theta2=75, width=1)) plt.scatter(start_point[0], start_point[1], marker='o', color='blue') plt.show() # print(path) # print(y_dot) noise_data = np.subtract(y_dot[:, 0], y[:, 0]) plt.plot(path[:, 0], noise_data) plt.show() if __name__ == '__main__': path = np.array([1.0, 1.0]) ugv = Bicycle(path) target = np.array([2.0, 2.0]) drive_to_target(ugv, target, 0)
def __init__(self): self.__bicycle = Bicycle()
num_bike_lists = [200, 300, 400, 500, 600, 700, 800] charge_rates = [0.01, 0.02, 0.03, 0.04, 0.05, 0.06] profit_mean = [] profit_std = [] bike_list = [] rate_list = [] duration_mean = [] duration_std = [] # conduct simulation for num_bike in num_bike_lists: for rate in charge_rates: tmp_profit = [] tmp_duration = [] for i in range(1000): bike = Bicycle(num_bike=num_bike, rate=rate, seed=None) tmp_profit.append(bike.simulate()) tmp_duration.append(bike.usage_duration) bike_list.append(num_bike) rate_list.append(rate) profit_mean.append(np.mean(tmp_profit)) profit_std.append(np.std(tmp_profit)) duration_mean.append(np.mean(tmp_duration)) duration_std.append(np.std(tmp_duration)) # create csv file maps = { 'num_bike': bike_list, 'rate': rate_list, 'revenue': profit_mean,
#Imports the Bicycle object from bicycle import Bicycle """ Demonstrates the use of the Bicycle object """ #Creates an instance of a Bicycle Object with three arguments test_bike = Bicycle(9, 12, "orange") #ACCESSORS #Prints test_bike's gear, speed, and color using accessor functions print("test_bike's gear =", test_bike.getgear()) print("test_bike's speed =", test_bike.getspeed()) print("test_bike's color =", test_bike.getcolor()) #MUTATORS """ print() #Sets test_bike's gear to 8 using a mutator test_bike.setgear(8); #Sets test_bike's speed to 11 test_bike.setspeed(11) #Sets test_bike's color to "yellow" test_bike.setcolor("yellow") #Prints test_bike's gear, speed, and color again print("test_bike's gear =", test_bike.getgear()) print("test_bike's speed =", test_bike.getspeed()) print("test_bike's color =", test_bike.getcolor())
# state = [x, y, theta, v, 1/L, k/m].Transpose # u = [pwm, steer].Transpose W = World(100, 100) W.load("track2.pkl") N = 6000; control = np.random.rand(2, N) - 0.5; state = np.matrix([[10, 20, 0, 0, 1, 50]]).T cycle_sim = Bicycle(state = state, color="green", name="Original"); cycle_sim.process_noise(R_SIM) cycle_sim.observation_noise(Q_SIM) W.add_agent(cycle_sim) state = np.matrix([[10, 20, 0, 0, 0.1, .1]]).T cycle_model = Bicycle(state = state, color="red", name="Model"); cycle_model.process_noise(R_MODEL) cycle_model.observation_noise(Q_MODEL) W.add_agent(cycle_model) target = 1 path = W.track["path"][0:, 0:] L = len(W.track["path"])
import numpy as np import matplotlib.pyplot as plt import matplotlib.image as mpimg from bicycle import Bicycle import argparse parser = argparse.ArgumentParser( description='2D trajectories of two wheeled vehicle') parser.add_argument('--trajectory', type=str, default='square') args = parser.parse_args() sample_time = 0.01 time_end = 60 model = Bicycle() model.reset() t_data = np.arange(0, time_end, sample_time) x_data = np.zeros_like(t_data) y_data = np.zeros_like(t_data) # maintain velocity at 4 m/s v_data = np.zeros_like(t_data) v_data[:] = 4 w_data = np.zeros_like(t_data) # ================================== # Square Path: set w at corners only # ================================== if (args.trajectory == 'square'): w_data[670:670 + 100] = 0.753
def test_bikeshop_markup(self): bianchi = Bicycle('Bianchi', 6, 450.0) rock_star = Bikeshop(' Rock Star', {'bianchi': 2, 'schwinn': 5, 'abici': 7, 'cinelli': 1, 'eagle': 2, 'falcon': 6}) self.assertEqual (rock_star.calculate_bike_cost(bianchi), 450 * 1.2)
if not first_read: if not stop: print("first read") for point in path_msg: if -1000.0 not in point.coordinate: path.append(list(point.coordinate)) else: path = np.array(path) print(path) print("STOP") stop = 1 if len(k) != 0 and stop == 1: pid = PID(k) bicycle = Bicycle(path) bicycle.pid = pid stamp_time = trans.header.stamp.to_sec() bicycle.x = round(trans.transform.translation.x, 3) bicycle.y = round(trans.transform.translation.y, 3) quaternion_trans = (trans.transform.rotation.x, trans.transform.rotation.y, trans.transform.rotation.z, trans.transform.rotation.w) euler_trans = euler_from_quaternion(quaternion_trans) bicycle.theta = round(euler_trans[2], 3) if i >= 0: bicycle.desired_x = bicycle.path[i, 0] bicycle.desired_y = bicycle.path[i, 1]
#Imports the Bicycle object from bicycle import Bicycle """ Demonstrates the use of the Bicycle object """ #Creates an instance of a Bicycle Object with three arguments test_bike = Bicycle(9, 12, "orange") #ACCESSORS #Prints test_bike's gear, speed, and color using accessor functions print("test_bike's gear =", test_bike.getgear()) print("test_bike's speed =", test_bike.getspeed()) print("test_bike's color =", test_bike.getcolor()) #MUTATORS print() #Sets test_bike's gear to 8 using a mutator test_bike.setgear(8); #Sets test_bike's speed to 11 test_bike.setspeed(11) #Sets test_bike's color to "yellow" test_bike.setcolor("yellow") #Prints test_bike's gear, speed, and color again print("test_bike's gear =", test_bike.getgear()) print("test_bike's speed =", test_bike.getspeed())
#Imports the Bicycle object from bicycle import Bicycle """ Demonstrates the use of the Bicycle object """ #ONLY HAVE ONE "EXAMPLE" UNCOMMENTED AT A TIME #BE SURE THE CORRECT INITIALIZER IS UNCOMMENTED IN bicycle.py #EXAMPLE 1 #Creates an instance of a Bicycle Object test_bike = Bicycle() #Prints test_bike's gear, speed, and color print("test_bike's gear =", test_bike.gear) print("test_bike's speed =", test_bike.speed) print("test_bike's color =", test_bike.color) #Sets test_bike's gear to 3 test_bike.gear = 3 #Sets test_bike's speed to 10 test_bike.speed = 10 #Sets test_bike's color to "red" test_bike.color = "red" #Prints test_bike's gear, speed, and color again print("test_bike's gear =", test_bike.gear) print("test_bike's speed =", test_bike.speed) print("test_bike's color =", test_bike.color)
if -1000.0 not in point.coordinate: path.append(list(point.coordinate)) else: path = np.array(path) print(path) print("STOP") stop = 1 if stop and not target: # print(path) # f = open('/home/conor/catkin_ws/src/network_faults/data/path.csv', 'w') # np.savetxt(f, path, delimiter=",") trials = 100 ideal_condition = 0 ideal_bicycle = Bicycle(path) ideal_bicycle.createPath() healthy_fault_condition = 1 healthy_fault_bicycle = Bicycle(path) healthy_fault_bicycle.createPath() healthy_fault_bicycle.readNoiseFunction() healthy_fault_bicycle.setNoiseFunction(healthy_fault_condition) healthy_fault_bicycle.driveOpenLoop(healthy_fault_condition, 'green') left_fault_condition = 2 left_fault_bicycle = Bicycle(path) left_fault_bicycle.createPath() left_fault_bicycle.readNoiseFunction() left_fault_bicycle.setNoiseFunction(left_fault_condition) left_fault_bicycle.driveOpenLoop(left_fault_condition, 'red')
class Environment: def __init__(self, render_game=False, human_input=False): self.render_game = render_game self.human_input = human_input if self.render_game: pygame.init() self.screen = pygame.display.set_mode((1000, 1000)) self.clock = pygame.time.Clock() self.bike = Bicycle() self.curr_time = 0 self.path = [] def render(self): if self.render_game: self.screen.fill(WHITE) Path.visualize_path_pygame(self.screen, self.path, RED) self.bike.render(self.screen) pygame.display.update() def update2(self, action): new_time = time.time() dt = new_time - self.curr_time #print(dt) self.curr_time = new_time if self.render_game and self.human_input: action = 0 pressed = pygame.key.get_pressed() if pressed[pygame.K_SPACE]: action = 6 print("BRAKE") elif pressed[pygame.K_UP]: if pressed[pygame.K_LEFT]: action = 4 print("UP | LEFT") elif pressed[pygame.K_RIGHT]: action = 5 print("UP | RIGHT") else: action = 1 print("UP") elif pressed[pygame.K_LEFT]: action = 2 print("LEFT") elif pressed[pygame.K_RIGHT]: action = 3 print("RIGHT") self.bike.update2(action, dt) def update(self): delta_prime = 0 acc = 0 brake = False new_time = time.time() dt = new_time - self.curr_time print(dt) self.curr_time = new_time if self.render_game and self.human_input: pressed = pygame.key.get_pressed() if pressed[pygame.K_RIGHT]: delta_prime = -1 elif pressed[pygame.K_LEFT]: delta_prime = 1 if pressed[pygame.K_UP]: acc = 100 elif pressed[pygame.K_DOWN]: acc = -100 brake = pressed[pygame.K_SPACE] #self.bike.update(acc, delta_prime, dt, brake, 0, 0) self.bike.update2(0, dt) #print(cte, new_delta, self.bike.delta) def check_events(self): for event in pygame.event.get(): if event.type == pygame.QUIT: return True return False def end(self): pygame.quit()
def create(vehicleType, vehicle_id): return { 'car': Car(vehicle_id), 'bicycle': Bicycle(vehicle_id) }[vehicleType]
from vehicle import Vehicle from bicycle import Bicycle vehicle = Vehicle() bike = Bicycle() vehicle.description() bike.description()
from customer import Customer from bicycle import Bicycle, Wheel, Frame from shop import Shop from collections import OrderedDict wheel1 = Wheel("aluminum", 1, 10) wheel2 = Wheel("carbon", 2, 15) wheel3 = Wheel("steel", 3, 20) frame1 = Frame("EU", 1, 10) frame2 = Frame("AU", 2, 40) bike1 = Bicycle("VN1", frame = frame1, wheel = wheel1) bike2 = Bicycle("VN2", frame = frame1, wheel = wheel2) bike3 =Bicycle("CN1", frame = frame1, wheel = wheel3) bike4 =Bicycle("CN2", frame = frame2, wheel = wheel1) bike5 =Bicycle("US1", frame = frame2, wheel = wheel2) bike6 =Bicycle("US2", frame = frame2, wheel = wheel3) inventory = OrderedDict() inventory[bike1] = 6 inventory[bike2] = 5 inventory[bike3] = 3 inventory[bike4] = 3 shop1 = Shop(sname = "Saigon", inventory = inventory, margin = 0.2) shop1.add(bike3) shop1.add({bike5: 2, bike6: 1}) pp1 = Customer("Khoe", 200) pp2 = Customer("Tri", 500) pp3 = Customer("Hung", 1000) print(pp1.cname, "can buy", pp1.canbuy(shop1)) print(pp2.cname, "can buy", pp2.canbuy(shop1)) print(pp3.cname, "can buy", pp3.canbuy(shop1) )
color='black', linestyle=':', linewidth=4) plt.xlabel('x') plt.ylabel('y') plt.title('UGV Path') plt.show() sys.exit(1) previous_time = rospy.get_time() agents_publisher.publish(msg) rate.sleep() if __name__ == '__main__': path = '../data/path.csv' df = pd.read_csv(path) coordinates = df.to_numpy() ideal_condition = 3 ideal_bicycle = Bicycle(coordinates) ideal_bicycle.createPath() fault_condition = 1 fault_bicycle = Bicycle(coordinates) fault_bicycle.createPath() driveClosedLoop(ideal_bicycle, fault_bicycle, ideal_condition, fault_condition)
import numpy as np import matplotlib.pyplot as plt import matplotlib.image as mpimg from bicycle import Bicycle sample_time = 0.01 time_end = 20 model = Bicycle() # set delta directly model.delta = np.arctan(2 / 10) t_data = np.arange(0, time_end, sample_time) x_data = np.zeros_like(t_data) y_data = np.zeros_like(t_data) for i in range(t_data.shape[0]): x_data[i] = model.xc y_data[i] = model.yc model.step(np.pi, 0) #model.beta = 0 plt.axis('equal') plt.plot(x_data, y_data, label='Learner Model') plt.legend() plt.show()