def start(main_controller_connection): signal.signal(signal.SIGTERM, signal_handler) logger.info("Starting drive_controller") # Motor drivers ipcon.connect('localhost', 4223) time.sleep(1.0) right_wheel = BrickDC('6wUYf6', ipcon) right_wheel.set_drive_mode(BrickDC.DRIVE_MODE_DRIVE_COAST) right_wheel.set_acceleration(60000) right_wheel.set_velocity(0) right_wheel.disable_status_led() right_wheel.enable() left_wheel = BrickDC('62gBJZ', ipcon) left_wheel.set_drive_mode(BrickDC.DRIVE_MODE_DRIVE_COAST) left_wheel.set_acceleration(60000) left_wheel.set_velocity(0) left_wheel.disable_status_led() left_wheel.enable() cutter = BrickDC('6e68bZ', ipcon) cutter.set_drive_mode(BrickDC.DRIVE_MODE_DRIVE_COAST) cutter.set_acceleration(10000) cutter.set_velocity(0) cutter.disable_status_led() cutter.enable() while True: if main_controller_connection.poll(): cmd = main_controller_connection.recv() logger.info("Execute external command {}".format(str(cmd))) execute_command(cmd, right_wheel, left_wheel, cutter) time.sleep(0.01)
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XXYYZZ" # Change XXYYZZ to the UID of your DC Brick from tinkerforge.ip_connection import IPConnection from tinkerforge.brick_dc import BrickDC 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 dc.set_drive_mode(dc.DRIVE_MODE_DRIVE_COAST) dc.set_pwm_frequency(10000) # Use PWM frequency of 10kHz dc.set_acceleration(5000) # Slow acceleration dc.set_velocity(32767) # Full speed forward dc.enable() # Enable motor power raw_input("Press key to exit\n") # Use input() in Python 3 dc.disable() # Disable motor power ipcon.disconnect()
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change to your UID from tinkerforge.ip_connection import IPConnection from tinkerforge.brick_dc import BrickDC 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 dc.set_pwm_frequency(10000) # Use PWM frequency of 10kHz dc.set_drive_mode(1) # Use 1 = Drive/Coast instead of 0 = Drive/Brake dc.enable() dc.set_acceleration(5000) # Slow acceleration dc.set_velocity(32767) # Full speed forward raw_input('Press key to exit\n') # Use input() in Python 3 dc.disable() ipcon.disconnect()
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() dcb.enable() time.sleep(1) ctrl_status = "Angeschaltet" updt_oled() input("")