#!/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()
Example #3
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)
        stepper.drive_forward()
    elif distance <= 150:
        print("Stepper -> Stop")
        stepper.stop()
    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")
# Use velocity reached callback to swing back and forth
# between full speed forward and full speed backward
def cb_velocity_reached(velocity, dc):
    if velocity == 32767:
        print('Velocity: Full speed forward, now turning backward')
        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
#!/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()
Example #7
0
#!/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()
Example #8
0
# Use velocity reached callback to swing back and forth
# between full speed forward and full speed backward
def cb_velocity_reached(velocity, dc):
    if velocity == 32767:
        print("Velocity: Full speed forward, now turning backward")
        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()