def __init__(self, UID_front, UID_back, ipcon, current, max_velocity, ramping_speed, side): # side of the wheels r or l self.side = side self.UID_back = UID_back self.UID_front = UID_front # init both stepper self.motor_back = BrickStepper(UID_back, ipcon) self.motor_front = BrickSilentStepper(UID_front, ipcon) # init current in mA print(current) self.motor_back.set_motor_current(current) self.motor_front.set_motor_current(current) # init max_velocity print(max_velocity) self.motor_back.set_max_velocity(max_velocity) self.motor_front.set_max_velocity(max_velocity) # init ramping speed print(ramping_speed) self.motor_back.set_speed_ramping(ramping_speed, ramping_speed) self.motor_front.set_speed_ramping(ramping_speed, ramping_speed) self.motor_back.set_step_mode(8) self.motor_front.set_step_configuration( self.motor_front.STEP_RESOLUTION_8, True)
else: steps = random.randint(-5000, -1000) # steps (backward) print("Driving backward: " + str(steps) + " steps") vel = random.randint(200, 2000) # steps/s acc = random.randint(100, 1000) # steps/s^2 dec = random.randint(100, 1000) # steps/s^2 print("Configuration (vel, acc, dec): " + str((vel, acc, dec))) stepper.set_speed_ramping(acc, dec) stepper.set_max_velocity(vel) stepper.set_steps(steps) if __name__ == "__main__": ipcon = IPConnection() # Create IP connection stepper = BrickStepper(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Register position reached callback to function cb_position_reached stepper.register_callback(stepper.CALLBACK_POSITION_REACHED, lambda x: cb_position_reached(x, stepper)) stepper.enable() # Enable motor power stepper.set_steps(1) # Drive one step forward to get things going raw_input("Press key to exit\n") # Use input() in Python 3 stepper.disable() ipcon.disconnect()
elif distance <= 130: print("Stepper -> Zurück") stepper.drive_backward() else: print("Puffer erreicht") stepper.stop() if __name__ == "__main__": ipcon = IPConnection() dcb = BrickDC(UIDdcb, ipcon) oled = BrickletOLED128x64(UIDoled, ipcon) poti = BrickletLinearPoti(UIDpoti, ipcon) ropoti = BrickletRotaryPoti(UIDropoti, ipcon) stepper = BrickStepper(UIDstepper, ipcon) joystick = BrickletJoystick(UIDjoystick, ipcon) irsensor = BrickletDistanceIR(UIDirsensor, ipcon) ipcon.connect(HOST, PORT) print("Verbindung unter folgenden Daten: \nIP: " + HOST + "\nPort: " + PORT) o_clear() print("Einstellungen werden gesetzt") o_write(1, 5, "Einstellungen") o_write(1, 5, "werden gesetzt") ctrl_hz_fan = 5000 dcb.set_pwm_frequency(5000) dcb.set_acceleration(5000)