Beispiel #1
0
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()
    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)

    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")