TOPに戻る

ラズパイ5 +Python+CANopenでモータを回す ⑩ モーション CiA 402の規格<Homing mode> canHome.py

 CANopenで、BLDCモータやステッピング・モータを回す規格がCiA 402です。この基本的な CiA 301 仕様の上に用意された規格によって、位置決め制御などができるようになります。「CiA 402」が正しい名称のようですが、「CiA402」や「CiA-402」の表記も混在しているようです。

基本のオブジェクト

 下の表は、どのモータ・メーカも用意している定義されたオブジェクト例です。

 オブジェクトとは、何でもいろいろなものが入っている入れ物です。

  • Statuswordであれば、運転ステートの状態がStatuswordのビットの位置で得られる
  • Target velocityであれば、目標とする速度の値
  • Position actual valueであれば、今瞬間のセンサから読み取った位置の値

オブジェクト index 内容 概要
Controlword 0x6040 control commands sent from Master to slave (driver) to ask driver (actually FSM in driver) change to ON state (servo-on), OFF state (servo-off), or for other specific purposes

CiA402ステート・マシン(Finite States Automaton; FSA)の制御

Statusword 0x6041 indicates current state of slave device ステート・マシンの状態を知る
Modes of operation 0x6060 modes (torque, velocity, position,...) that Master want slave device to work at

「Profile position mode;位置制御モード」や「Profile velocity Mode;速度制御モード」などの各種モードの指定

Target torque 0x6071 requested torque from Master when slave work in torque mode Profile torque modeの「目標トルク」
Target velocity 0x60ff requested velocity from Master when slave work in velocity mode Profile velocity modeの「目標速度」
Target position 0x607a requested position from Master when slave work in position mode Profile position mode;位置制御モードにおける到達したい「目標位置」
Torque actual value 0x6077 actual torque measured and sent by slave to Master 刻々と変わる「今のトルクの値」
Velocity actual value 0x606c actual velocity measured and sent by slave to Master 刻々と変わる「今の速度の値」
Position actual value 0x6064 actual position measured and sent by slave to Master 刻々と変わる「今の位置の値」

 それぞれの動作モードでは、初期設定で使用される必須なオブジェクトが数個あります。さらに、より詳細な動作を求めるために使われるが普通はデフォルトのまま使うオブジェクトも数個あります。

メーカによってサポートされているかが異なる動作(オペレーション)モード

 CiA 402 ドライブ・プロファイルの動作モードは、下記がリスト・アップされています。最近のロボット用には8番以降が使われるようになったようです。

 

  • プロファイル位置モード(Profile position mode 位置制御モード):  1
  • 速度モード(周波数変換器):2
  • プロファイル速度モード(Profile velocity mode 速度制御モード): 3
  • トルク・プロファイル・モード:4
  • ホーミング・モード(Homing mode):6
  • 補間位置モード: 7
  • サイクリック同期位置モード(CSP:Cyclic sync position mode): 8
  • サイクリック同期速度モード(CSV):9
  • サイクリック同期トルク・モード(CST):10

 ここで使っているモータ・ドライバBLVD-KRDは、次の三つのモードをサポートしています。用語が上記とは微妙に異なっています。

  • プロファイル位置モード(pp)
  • プロファイル速度モード(pv)
  • 原点復帰モード(hm)
  • Profile Torque Mode (tq)<ーv4.00以降

原点復帰モード(hm)を実行してみる

 モータ制御では、電源ONの直後、原点復帰モードを実行すべきのようです。この原点復帰にも、いくつかのHoming Methodがあります。

  • 1 Homing on negative limit switch and index pulse
  • 2 Homing on positive limit switch and index pulse
  • 8 Homing on home switch and index pulse and starting in the positive direction
  • 12 Homing on home switch and index pulse and starting in the negative direction
  • 17 Homing on negative limit switch
  • 18 Homing on positive limit switch
  • 24 Homing on home switch and starting in the positive direction
  • 28 Homing on home switch and starting in the negative direction
  • 35, 37 * Homing on current position

–1 Homing method of Orientalmotor specifications.Refer to the following for details on the operations.
- OPERATING MANUAL BLV Series R Type Function Edition

  たとえば、可動部がこれ以上進むべきでない限界位置にリミット・スイッチを用意して、動作確認には、写真のような治具を用意するとよいでしょう。

 Home positionは、リミット・スイッチの間に設定します。

 Homing Methodの中には、home switchを押したら云々というのがありますが、コントローラBLVD-KRDがもつ四つのディジタル入力を、オブジェクトにアサインする機能が見つかりません。MEXE02にも、そのような機能のメニューが見つかりません。

 次のテストでは、37を使います。つまり、今の位置を原点とするだけです。このモードの実行はSDOの読み書きで実現します。

プログラム

 資料 Brushless Motor BLV series R type Driver CANopen communication profileに書かれているHoming Mode (hm)の最初の部分です。

 真ん中の処理実行の四角な箱の左は、設定値です。右は結果の、ステータスと位置情報です。

 以降、Homing Methodの説明がありますが、英語もあって、実務を経験していないとわかりにくいです。EtheCATなどの対応機器で、国産のCANopen対プロトコルを採用している製品のマニュアルが検索で複数見つかるので参考にします。

 原点復帰モード(hm)はSDOの読み書きで実現しますが、位置=positionはPDOの読み書きで得られます。

 どちらにしても、プログラムの最初で、

  • NMT(通信ステート)をPre-operationalからOperationalに移行
  • State_machine(運転ステート)をSWITCH ON DISABLEDからOPERATION ENABLEDに移行

させます。

import canopen
import time
import logging
# logging.basicConfig(level=logging.DEBUG)

# Start with creating a network representing one CAN bus
network = canopen.Network()

# Connect to the CAN bus
# sudo ip link set can0 up type can bitrate 1000000
network.connect(bustype='socketcan', channel='can0')
print("\n===start  ID=12 OrientalMotor\n")

# Add some nodes with corresponding Object Dictionaries
node = canopen.BaseNode402(12,'Downloads/BLVD-KRD_CANopen_V200.eds')
network.add_node(node)

def resetNmt():
    # all nodes simulaneously as a broadcast message
    network.nmt.state = 'RESET'
    time.sleep(0.5)
    #print('network state 1) = {0}'.format(network.nmt.state))

    # Reset this node
    node.nmt.state = 'RESET'
    node.nmt.wait_for_bootup(15)
    node.nmt.state = 'RESET COMMUNICATION'
    node.nmt.wait_for_bootup(15)
    #print('node state 1) = {0}\n'.format(node.nmt.state))
    node.nmt.send_command(0x1)   # NMT start
    network.check()
    print('node state = {0}\n'.format(node.nmt.state))

def startState_machine():
    node.setup_402_state_machine()
    node.sdo[0x6040].raw = 0x0010  # Fault Reset
    time.sleep(0.5)
    node.state = 'SWITCH ON DISABLED'
    time.sleep(0.1)  
    timeout = time.time() + 15
    node.state = 'READY TO SWITCH ON'
    while node.state != 'READY TO SWITCH ON':
        if time.time() > timeout:
            raise Exception('Timeout when trying to change state')
        time.sleep(0.01)
    time.sleep(0.1)  
    timeout = time.time() + 15
    node.state = 'SWITCHED ON'
    while node.state != 'SWITCHED ON':
        if time.time() > timeout:
            raise Exception('Timeout when trying to change state')
        time.sleep(0.001)
    time.sleep(0.1)  
    timeout = time.time() + 15
    node.state = 'OPERATION ENABLED'
    while node.state != 'OPERATION ENABLED':
        if time.time() > timeout:
            raise Exception('Timeout when trying to change state')
        time.sleep(0.001)
    time.sleep(0.1) 
    print("---SWITCH state ready\n") 
    network.check()
    print('node state = {0}\n'.format(node.nmt.state))

def readPosition():
    node.nmt.state = 'OPERATIONAL'
    node.tpdo.read()
    node.tpdo[3].wait_for_reception()
    position0 = node.tpdo[3]['Position actual value'].phys
    return position0

def setHoming_on_current_position():
    node.sdo[0x6098].raw = 37  # Homing method: Homing on current position
    node.rpdo[2]['Controlword'].phys  = 0  # Homing operation start
    node.rpdo[2]['Modes of operation'].phys  = 6  # Homing Mode
    node.rpdo[2].transmit()
    node.rpdo[2].start(0.1)
    node.rpdo[1]['Controlword'].phys  = 0x001f
    node.rpdo[1].transmit()

def stopNmt():
    node.sdo[0x6040].raw = 0x0010  # Fault Reset
    print('\ngoing to exit... stopping...')
    # Reset this node
    node.nmt.state = 'RESET'
    node.nmt.wait_for_bootup(15)
    node.nmt.state = 'RESET COMMUNICATION'
    node.nmt.wait_for_bootup(15)
    #node.nmt.send_command(0x02)  # NMT remote stop

#----main----------------

resetNmt()

network.sync.start(0.1)
print("---Switch CiA402 state UP\n") 
startState_machine()

pos = readPosition()
print("\n read this position : ",pos)

setHoming_on_current_position()
time.sleep(1)
print("\n---done. Homing method: Homing on current position")

pos = readPosition()
print("\n read new position  : ",pos)

stopNmt()
network.check()
print('node state = {0}\n'.format(node.nmt.state))
network.sync.stop()
network.disconnect()

 仮想環境で実行中の様子です。

資料

  EPOS4/EPOS2運転モード:Homing modeに関して

  (Homing Methodで原点スイッチを使用する場合は、EPOS Studioでスイッチが接続されたデジタル入力を、“Home switch”に設定)

  

  原点復帰と座標管理

連載 ラズパイ5 +Python+CANopenでモータを回す

(1) 構成と環境(オリエンタルモーター の「BLMR5100K-A-B」 + 「BLVD-KRD」)

(2) サポート・ソフト MEXE02

(3) PythonでSDOの読み出し(仮)caninfo.py

(4) CANopenのベーシックな規格とSDO/PDO、オブジェクト・ディクショナリ<前編>

(5) CANopenのベーシックな規格とSDO/PDO、オブジェクト・ディクショナリ<後編>

(6) 二つの状態遷移(NMTとStatus Machine)

(7) CANバス信号を見る<前編>canreset.py candump0.py

(8) CANバス信号を見る<中編>Arduino

(9) CANバス信号を見る<後編>CANopenのデコードができ無償で使えるツールAnalog Devices TMCL-IDE

(10) モーション CiA 402の規格<Homing mode> canHome.py

(11) モーション CiA 402の規格<Profile Position Mode (PPM)-前編> canPPMread.py

(12) モーション CiA 402の規格<Profile Position Mode (PPM)-中編> caninfo2.py canppm.py

(13) モーション CiA 402の規格<Profile Position Mode (PPM)-後編> canppm2.py

(14) モーション CiA 402の規格<Profile Velocity Mode (PVM)> campvm.py