博客 / 詳情

返回

對canopen中pdo的理解

  1. canopen協議和can的id
    canopen協議是建立在can總線協議上的協議,can協議的包頭id被重新規劃了能傳送更豐富的信息
    image.png
    其中功能碼是
    image.png

這樣在使用canopen協議的can總線上就不能單純的使用canid來傳送消息了,一些固定的canid就有了特殊的用途,從功能碼可以看出管理報文優先級最高 , 同步時間戳 緊急 pdo次之,這樣canopen的id就是功能碼加上縮小的can的id裏的設備id,這樣can總線就能傳送消息給對應的節點,又能傳送類似廣播的消息給所有節點。

  1. canopen的字典
    既然定義好了通信的目標 傳送的消息是什麼樣的那,就是通信的雙方都使用一個預先定義好的字典來通信,以canopennode的數據結構為例
typedef struct {
    /** The index of Object from 0x1000 to 0xFFFF */
    uint16_t            index;
    /** Number of (sub-objects - 1). If Object Type is variable, then
    maxSubIndex is 0, otherwise maxSubIndex is equal or greater than 1. */
    uint8_t             maxSubIndex;
    /** If Object Type is record, attribute is set to zero. Attribute for
    each member is then set in special array with members of type
    CO_OD_entryRecord_t. If Object Type is Array, attribute is common for
    all array members. See #CO_SDO_OD_attributes_t. */
    uint16_t            attribute;
    /** If Object Type is Variable, length is the length of variable in bytes.
    If Object Type is Array, length is the length of one array member.
    If Object Type is Record, length is zero. Length for each member is
    set in special array with members of type CO_OD_entryRecord_t.
    If Object Type is Domain, length is zero. Length is specified
    by application in @ref CO_SDO_OD_function. */
    uint16_t            length;
    /** If Object Type is Variable, pData is pointer to data.
    If Object Type is Array, pData is pointer to data. Data doesn't
    include Sub-Object 0.
    If object type is Record, pData is pointer to special array
    with members of type CO_OD_entryRecord_t.
    If object type is Domain, pData is null. */
    void               *pData;
}CO_OD_entry_t;

發送接收都按字典的索引index子索引SubIndex和來傳送消息,同時字典又不全是要傳送消息的索引和值的對應,還有一些亂七八糟的功能包括配置都放在了裏面,canopen規定好了一些默認的字典存儲位置

  1. sdo包
    上面看到字典索引和對應的數據,最簡單的訪問方法就是發送對應的設備id加上字典的索引,然後服務端就響應響應的數據,這就是sdo包的通信過程,但是這樣就可能造成頻繁訪問的對象每次都要傳送字典索引來通信,對傳輸數據非常小又要求實時性非常高的場合就還有優化的空間,這就是pdo
  2. pdo包
    pdo則不傳字典中的索引了,直接發送數據內容,由於實時性要求數據丟了就丟了重傳可能已經是沒有意義的了,可能因為這方面的需求pdo才被設計成單向的
    直接傳數據什麼時候發送,怎麼區分是哪個值那,使用的是規定好的can的id,發送接收都約定好PDO1-PDO4各發送什麼數據,根據什麼事件來發送
    這樣就產生了兩個配置,例如PDO1發送的canid是多少,和什麼時候發送是通信配置放在字典裏配置好類似canopennode會直接來使用
    image.png

PDO1發送字典裏的哪個值就是映射參數也放在字典裏 canopennode會根據配置字典對應位置的配置來實現

image.png

user avatar
0 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.