示例#1
0
    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)
示例#2
0
class Motor_row():
    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)

    def enable_motors(self):
        self.motor_back.enable()
        self.motor_front.enable()

    def set_steps(self, steps):

        self.motor_back.set_steps(steps)
        self.motor_front.set_steps(steps)

    def drive_forward(self):
        if self.side == 'r':
            self.motor_back.drive_backward()
            self.motor_front.drive_forward()
        else:
            self.motor_back.drive_forward()
            self.motor_front.drive_backward()

    def drive_backward(self):
        if self.side == 'l':
            self.motor_back.drive_backward()
            self.motor_front.drive_forward()
        else:
            self.motor_back.drive_forward()
            self.motor_front.drive_backward()

    def full_stop(self):
        self.motor_back.stop()
        self.motor_front.stop()

    def disable(self):
        self.motor_back.disable()
        self.motor_front.disable()
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XXYYZZ" # Change XXYYZZ to the UID of your Stepper Brick

from tinkerforge.ip_connection import IPConnection
from tinkerforge.brick_stepper import BrickStepper

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

    stepper.set_motor_current(800) # 800mA
    stepper.set_step_mode(8) # 1/8 step mode
    stepper.set_max_velocity(2000) # Velocity 2000 steps/s

    # Slow acceleration (500 steps/s^2),
    # Fast deacceleration (5000 steps/s^2)
    stepper.set_speed_ramping(500, 5000)

    stepper.enable() # Enable motor power
    stepper.set_steps(60000) # Drive 60000 steps forward

    raw_input("Press key to exit\n") # Use input() in Python 3
    stepper.disable()
    ipcon.disconnect()
示例#4
0
    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()
示例#5
0
    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)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XXYYZZ"  # Change XXYYZZ to the UID of your Stepper Brick

from tinkerforge.ip_connection import IPConnection
from tinkerforge.brick_stepper import BrickStepper

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

    stepper.set_motor_current(800)  # 800mA
    stepper.set_step_mode(8)  # 1/8 step mode
    stepper.set_max_velocity(2000)  # Velocity 2000 steps/s

    # Slow acceleration (500 steps/s^2),
    # Fast deacceleration (5000 steps/s^2)
    stepper.set_speed_ramping(500, 5000)

    stepper.enable()  # Enable motor power
    stepper.set_steps(60000)  # Drive 60000 steps forward

    raw_input("Press key to exit\n")  # Use input() in Python 3
    stepper.disable()
    ipcon.disconnect()