コード例 #1
0
ファイル: stepper.py プロジェクト: Techbeard/Robomec
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()
コード例 #2
0
# -*- 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()
コード例 #3
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()