rpisteper是一个库控制步进电机,使用树莓pi和晶体管阵列

RPistepper的Python项目详细描述


rpistepper是一个库,包含:*一个控制步进器的类 带有RPI的马达。*用两个 马达。*用两个执行方螺旋运动的函数 马达。

接线

在我们的设置中,电机(vm)的电源由5v引脚供电 在rpi中,线圈的接地由 ULN2803A晶体管 阵列。

Example setup

alt文本

连接RPI-ULN2803A:

RPi Pin (BCM)ULN2803A
171B
272B
103B
94B
145B
156B
237B
248B

连接ULN2803A-电机:

ULN2803AMotors
1CMotor_1 Coil_A1
2CMotor_1 Coil_A2
3CMotor_1 Coil_B1
4CMotor_1 Coil_B2
5CMotor_2 Coil_A1
6CMotor_2 Coil_A2
7CMotor_2 Coil_B1
8CMotor_2 Coil_B2

在这种情况下,两个电机连接到ULN2803A。

用法

类电机

此类允许用户使用4 GPIO控制6针步进电机 RPI的引脚。

软件采用BCM模式进行PIN标引。

此类最好与“with”语句一起使用,以正确处理 清除GPIO。

self.steps是此类的一个属性,它将获取步骤数 从初始位置开始或设置到特定步骤,类似于 自我。行动。

为了节省能源,建议在 马达空转。

参数是一个带有4个管脚的列表(线圈A1,线圈A2,线圈B1, coil_b2),步骤之间的延迟(默认值为20毫秒)和详细到 显示马达运动报告,最后两个是可选的。例如:

importRPistepperasstpM1_pins=[17,27,10,9]withstp.Motor(M1_pins)asM1:foriinrange(10):# moves 20 steps,release and waitprintM1M1.move(20)M1.release()raw_input('enter to execute next step')

如果类是正常实例化的,请使用cleanupprior方法 关闭应用程序以关闭GPIO资源。还有,如果是 重要的是在完成例行程序时回到初始位置, 使用方法reset

importRPistepperasstpM1_pins=[17,27,10,9]M1=stp.Motor(M1_pins)foriinrange(10):# moves 20 steps,release and waitprintM1M1.move(20)M1.release()raw_input('enter to execute next step')M1.reset()M1.cleanup()

方法

目前有五种实现方法:

defmove(self,steps):'''
    Moves the motor 'steps' steps. Negative steps moves the motor backwards
    '''
defrelease(self):'''
    Sets all pins low. Power saving mode
    '''
defreset(self):'''
    Returns the motor to it's initial position
    '''
defzero(self):'''
    Sets the motor to the next position which Coil_A1 and Coil_A2
    are on. Sets this position as the reference (steps = 0).
    '''
defcleanup(self):'''
    Cleans the GPIO resources
    '''

主要的方法是move,它将电机移动到所需的 步骤

步骤属性

可以检查电机位置或手动设置所需的 使用steps属性的步骤:

importRPistepperasstpM1_pins=[17,27,10,9]withstp.Motor(M1_pins)asM1:foriinrange(10):# moves 20 steps,release and waitprintM1.stepsM1.steps=20*iM1.release()raw_input('enter to execute next step')M1.reset()

属性

此类具有以下属性:

AttributeData
DELAYTime between steps
VERBOSEDisplay motor data on screen
PINSGPIOs used by the instance
actual_stateA list with the status of the coils (on/off)

函数

这两个函数执行预先确定的移动,需要两个 步进电机对象:

defzig_zag(motor1,motor2,amp1,amp2,delay=None):'''
    Executes a zig-zag movement with two RPistepper objects.
    Arguments are: motor1 and motor2 objects and amp1, amp2, the amplitude
    of movement, a tuple (step, rep) representing the number of steps per
    iteration and the number of iterations of the following algorithm:
        Repeat rep1 times:
            1. Moves motor 2 step2*rep2 steps forward
            2. Moves motor 1 step1 steps forward
            3. Moves motor 2 step2*rep2 steps backwards
            4. Moves motor 1 step1 steps forward
        Reset to initial state
        Release the motors
    It's possible to change the delay between steps with the 'delay' argument
    '''
defsquare_spiral(motor1,motor2,amplitude,delay=None):'''
    Executes a square spiral movement with two RPistepper objects.
    Arguments are: motor1 and motor2 objects and the amplitude of movement,
    a tuple (step, rep) representing the number of steps per iteration and
    the number of iterations of the following algorithm:
        for i in range(rep):
            1. Moves motor 2 to position i
            2. Moves motor 1 to position i
            3. Moves motor 1 to position -i
            4. Moves motor 2 to position -i
        Reset to initial state
        Release the motors
    It's possible to change the delay between steps with the 'delay' argument
    '''

/垃圾箱/垃圾箱

rpistepper是用于控制马达的外壳。它提供了所有 Motor类中的方法。所有的命令都记录在 贝壳。可以将命令列表通过管道发送到shell:

rpistepper < sample.stp
        or
cat sample.stp | rpistepper

使用-g标志调用rpistepper将打开一个gui应用程序 具有类似的功能

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在一个问题被连续正确回答三次/并添加差异后,我如何将程序循环回开始   Java中未实例化的匿名类   java如何在Android中录制视频,只允许横向模式和最长时间录制时间   java从另一个活动发送实时消息   多线程java线程和互斥   java禁用Spring安全日志   JAVA伊奥。StreamCorruptedException:在与子级和父级ProcessBuilder通信时写入子级中的标准输出时,流头无效   使用Java(HttpURLConnection)对Restheart进行身份验证(对于Mongodb)   java如何解决Jenkins中的SAXParseException?   java为什么我需要mockito来测试Spring应用程序?   计算sin-cos和tan时缺乏精度(java)   java Hibernate。不同项目中相同一对一映射的不同行为   java图像滑块:如何使用JavaFX将图像放在另一个图像上   java Mockito在使用when时抛出NotAMockException   http Java servlet发送回响应