當前位置: 首頁>>代碼示例>>Python>>正文


Python Motor.set_voltage方法代碼示例

本文整理匯總了Python中motor.Motor.set_voltage方法的典型用法代碼示例。如果您正苦於以下問題:Python Motor.set_voltage方法的具體用法?Python Motor.set_voltage怎麽用?Python Motor.set_voltage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在motor.Motor的用法示例。


在下文中一共展示了Motor.set_voltage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: red_chanel

# 需要導入模塊: from motor import Motor [as 別名]
# 或者: from motor.Motor import set_voltage [as 別名]
        self.bus_id = bus_id
        self.radio_id = radio_id
        self.bus = smbus.SMBus(self.bus_id)

    def red_chanel(self, ch_id):
        w = self.bus.read_word_data(self.radio_id, ch_id)
        return w

if __name__ == "__main__":

    m0 = Motor(0)
    m1 = Motor(1, -1)

    rc = Rcradio(2, 0x10)
    offset = 698

    try:
        while 1:
            speed = offset - rc.red_chanel(0)
            if abs(speed) < 3:
                speed = 0
            print(speed)
            m0.set_voltage(speed)
            m1.set_voltage(speed)
            time.sleep(0.1)

    except KeyboardInterrupt:
        m0.close()
        m1.close()
        pass
開發者ID:hajtohaj,項目名稱:BBB_Balancer,代碼行數:32,代碼來源:test_rc.py

示例2: getch

# 需要導入模塊: from motor import Motor [as 別名]
# 或者: from motor.Motor import set_voltage [as 別名]
while c != 'q' and c != 'Q':
    t0 = time.time()
    r0 = m0.get_radians()
    c = getch()
    t1 = time.time()
    r1 = m0.get_radians()
    print("{0}, {1}".format(voltage, (r1 - r0)/(t1 - t0)))
    if ord(c) == 27:
        c = getch()
        if ord(c) == 91:
            c = getch()
            if ord(c) in key_map.keys():
                print(key_map[ord(c)])
                if key_map[ord(c)] == 'up':
                    voltage += voltage_step
                elif key_map[ord(c)] == 'down':
                    voltage -= voltage_step
    elif ord(c) == 32:
        pass
    else:
        print(ord(c))
    if voltage > 100:
        volate = 100
    if voltage < -100:
        voltage = -100
    m0.get_radians()
    m0.set_voltage(voltage)

m0.set_encoder(0)
m0.close()
開發者ID:hajtohaj,項目名稱:BBB_Balancer,代碼行數:32,代碼來源:grab_input.py


注:本文中的motor.Motor.set_voltage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。