elif velocity == -32767: print('Velocity: Full speed backward, now turning forward') dc.set_velocity(32767) else: print('Error') # Can only happen if another program sets velocity if __name__ == "__main__": ipcon = IPConnection() # Create IP connection dc = BrickDC(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # The acceleration has to be smaller or equal to the maximum # acceleration of the DC motor, otherwise the velocity reached # callback will be called too early dc.set_acceleration(5000) # Slow acceleration dc.set_velocity(32767) # Full speed forward # Register velocity reached callback to function cb_velocity_reached dc.register_callback(dc.CALLBACK_VELOCITY_REACHED, lambda x: cb_velocity_reached(x, dc)) # Enable motor power dc.enable() raw_input("Press key to exit\n") # Use input() in Python 3 dc.disable() # Disable motor power ipcon.disconnect()
ctrl_velostepper = 3000 ctrl_accstepper = 1000 stepper.set_step_mode(8) stepper.set_motor_current(1000) stepper.set_max_velocity(3000) stepper.set_speed_ramping(1000, 50000) stepper.set_current_position(0) time.sleep(1) o_clear() print("Callbacks werden registriert") o_write(1, 5, "Callbacks") o_write(1, 3, "werden registriert") dcb.register_callback(dcb.CALLBACK_VELOCITY_REACHED, lambda x: cb_dcb_velocity(x, dcb)) stepper.register_callback(BrickStepper.CALLBACK_UNDER_VOLTAGE, cb_stepper_undervoltage) ropoti.register_callback(BrickletRotaryPoti.CALLBACK_POSITION, cb_rotary_fancontrol) poti.register_callback(BrickletLinearPoti.CALLBACK_POSITION, cb_linearpoti_controller) irsensor.register_callback(BrickletDistanceIR.CALLBACK_DISTANCE, cb_irsensor_distance) o_clear() print("Bricks werden gestartet") o_write(1, 6, "Bricks") o_write(1, 3, "werden aktiviert") stepper.enable()
dc.set_velocity(-32767) elif velocity == -32767: print("Velocity: Full speed backward, now turning forward") dc.set_velocity(32767) else: print("Error") # Can only happen if another program sets velocity if __name__ == "__main__": ipcon = IPConnection() # Create IP connection dc = BrickDC(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # The acceleration has to be smaller or equal to the maximum # acceleration of the DC motor, otherwise the velocity reached # callback will be called too early dc.set_acceleration(5000) # Slow acceleration dc.set_velocity(32767) # Full speed forward # Register velocity reached callback to function cb_velocity_reached dc.register_callback(dc.CALLBACK_VELOCITY_REACHED, lambda x: cb_velocity_reached(x, dc)) # Enable motor power dc.enable() raw_input("Press key to exit\n") # Use input() in Python 3 dc.disable() # Disable motor power ipcon.disconnect()