Exemplo n.º 1
0
class Motor_row():
    def __init__(self, UID_front, UID_back, ipcon, current, max_velocity,
                 ramping_speed):

        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):
        print(steps)
        self.motor_back.set_steps(steps)
        self.motor_front.set_steps(steps)

    def drive_forward(self):
        self.motor_back.drive_forward()
        self.motor_front.drive_forward()

    def drive_backward(self):
        self.motor_back.drive_backward()
        self.motor_front.drive_backward()

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

    def disable(self):
        self.motor_back.disable()
        self.motor_front.disable()
# -*- 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()
Exemplo n.º 3
0
    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")

    dcb.register_callback(dcb.CALLBACK_VELOCITY_REACHED,
                          lambda x: cb_dcb_velocity(x, dcb))
    stepper.register_callback(BrickStepper.CALLBACK_UNDER_VOLTAGE,
                              cb_stepper_undervoltage)
# -*- 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()