ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I recently had cause to do this. In my case I needed to send a status byte which contained a series of bit flags onto a specific TxPDO cobid

Here is my working method. External to the method I have the Frame import

from can_msgs.msg import Frame

and the publisher set to the standard outgoing Socketcan topic "/sent_messages and set the COBID"

file_system_status_publisher = rospy.Publisher("/sent_messages", Frame, queue_size=1)
TxPDO_cobid = 0x4a3  # This is the TxPDO from a base ID of 35

In my application I send a status packet onto the can bus on events and a slow poll. Here is the method that handles that transmit

def send_status():

    # Assembles a CAN packet of a single byte that is transmitted on the calculated TxCOBID
    # Included bit flags
                            # 0. 0x01 is USB inserted
                            # 1. 0x02 are the files uploading
                            # 2. 0x04 have all files uploaded
                            # 3. 0x08 is machine ready to perform job

    # These globals are technically not required here but are given for clarity

    global is_usb_plugged_in
    global are_files_uploading_now
    global have_all_files_uploaded
    global is_machine_ready_to_perform_job

    # Set the bit flags

    flags = 0

    if is_usb_plugged_in:
        flags |= 0x01

    if are_files_uploading_now:
        flags |= 0x02

    if have_all_files_uploaded:
        flags |= 0x04

    if is_machine_ready_to_perform_job:
        flags |= 0x08

    file_system_status_message = Frame(id=TxPDO_cobid, dlc=1, data = [flags, 0, 0, 0, 0, 0, 0, 0])    
    file_system_status_publisher.publish(file_system_status_message)

This would seem similar to your requirements

I recently had cause to do this. In my case I needed to send a status byte which contained a series of bit flags onto a specific TxPDO cobid

Here is my working method. External to the method I have the Frame import

from can_msgs.msg import Frame

and the publisher set to the standard outgoing Socketcan topic "/sent_messages and set the COBID"

file_system_status_publisher = rospy.Publisher("/sent_messages", Frame, queue_size=1)
TxPDO_cobid = 0x4a3  # This is the TxPDO from a base ID of 35

In my application I send a status packet onto the can bus on events and a slow poll. Here is the method that handles that transmit

def send_status():

    # Assembles a CAN packet of a single byte that is transmitted on the calculated TxCOBID
    # Included bit flags
                            # 0. 0x01 is USB inserted
                            # 1. 0x02 are the files uploading
                            # 2. 0x04 have all files uploaded
                            # 3. 0x08 is machine ready to perform job

    # These globals are technically not required here but are given for clarity

    global is_usb_plugged_in
    global are_files_uploading_now
    global have_all_files_uploaded
    global is_machine_ready_to_perform_job

    # Set the bit flags

    flags = 0

    if is_usb_plugged_in:
        flags |= 0x01

    if are_files_uploading_now:
        flags |= 0x02

    if have_all_files_uploaded:
        flags |= 0x04

    if is_machine_ready_to_perform_job:
        flags |= 0x08

    # I am only sending one byte so I set my dlc to 1.  I left the other parameters: header, is_rtr, 
    # is_extended, is_error etc as default 

    file_system_status_message = Frame(id=TxPDO_cobid, dlc=1, data = [flags, 0, 0, 0, 0, 0, 0, 0])    
    file_system_status_publisher.publish(file_system_status_message)

This would seem similar to your requirements

I recently had cause to do this. In my case I needed to send a status byte which contained a series of bit flags onto a specific TxPDO cobid

Here is my working method. External to the method I have the Frame import

from can_msgs.msg import Frame

and the publisher set to the standard outgoing Socketcan topic "/sent_messages and set the COBID"

file_system_status_publisher = rospy.Publisher("/sent_messages", Frame, queue_size=1)
TxPDO_cobid = 0x4a3  # This is the TxPDO from a base ID of 35

In my application I send a status packet onto the can bus on events and a slow poll. Here is the method that handles that transmit

def send_status():

    # Assembles a CAN packet of a single byte that is transmitted on the calculated TxCOBID
    # Included bit flags
                            # 0. 0x01 is USB inserted
                            # 1. 0x02 are the files uploading
                            # 2. 0x04 have all files uploaded
                            # 3. 0x08 is machine ready to perform job

    # These globals are technically not required here but are given for clarity

    global is_usb_plugged_in
    global are_files_uploading_now
    global have_all_files_uploaded
    global is_machine_ready_to_perform_job

    # Set the bit flags

    flags = 0

    if is_usb_plugged_in:
        flags |= 0x01

    if are_files_uploading_now:
        flags |= 0x02

    if have_all_files_uploaded:
        flags |= 0x04

    if is_machine_ready_to_perform_job:
        flags |= 0x08

    # I am only sending one byte so I set my dlc to 1.  I left the other parameters: 
    # header, is_rtr, 
    # is_extended, is_error etc as default 

    file_system_status_message = Frame(id=TxPDO_cobid, dlc=1, data = [flags, data=[flags, 0, 0, 0, 0, 0, 0, 0])    
    file_system_status_publisher.publish(file_system_status_message)

This would seem similar to your requirements

I recently had cause to do this. In my case I needed to send a status byte which contained a series of bit flags onto a specific TxPDO cobid

Here is my working method. External to the method I have the Frame import

from can_msgs.msg import Frame

and the publisher set to the standard outgoing Socketcan topic "/sent_messages and set the COBID"

file_system_status_publisher = rospy.Publisher("/sent_messages", Frame, queue_size=1)
TxPDO_cobid = 0x4a3  # This is the TxPDO CANOPEN TxPDO4 from a base node ID of 35

In my application I send a status packet onto the can bus on events and a slow poll. Here is the method that handles that transmit

def send_status():

    # Assembles a CAN packet of a single byte that is transmitted on the calculated TxCOBID
    # Included bit flags
                            # 0. 0x01 is USB inserted
                            # 1. 0x02 are the files uploading
                            # 2. 0x04 have all files uploaded
                            # 3. 0x08 is machine ready to perform job

    # These globals are technically not required here but are given for clarity

    global is_usb_plugged_in
    global are_files_uploading_now
    global have_all_files_uploaded
    global is_machine_ready_to_perform_job

    # Set the bit flags

    flags = 0

    if is_usb_plugged_in:
        flags |= 0x01

    if are_files_uploading_now:
        flags |= 0x02

    if have_all_files_uploaded:
        flags |= 0x04

    if is_machine_ready_to_perform_job:
        flags |= 0x08

    # I am only sending one byte so I set my dlc to 1.  I left the other parameters: 
    # header, is_rtr, is_extended, is_error etc as default 

    file_system_status_message = Frame(id=TxPDO_cobid, dlc=1, data=[flags, 0, 0, 0, 0, 0, 0, 0])    
    file_system_status_publisher.publish(file_system_status_message)

This would seem similar to your requirements

I recently had cause to do this. In my case I needed to send a status byte which contained a series of bit flags onto a specific TxPDO cobid

Here is my working method. External to the method I have the Frame import

from can_msgs.msg import Frame

and the publisher set to the standard outgoing Socketcan topic "/sent_messages and set the COBID"

file_system_status_publisher = rospy.Publisher("/sent_messages", Frame, queue_size=1)
TxPDO_cobid = 0x4a3  # This is the CANOPEN TxPDO4 from a node ID of 35

In my application I send a status packet onto the can bus on events and a slow poll. Here is the method that handles that transmit

def send_status():

    # Assembles a CAN packet of a single byte that is transmitted on the calculated TxCOBID
    # Included bit flags
                            # 0. 0x01 is USB inserted
                            # 1. 0x02 are the files uploading
                            # 2. 0x04 have all files uploaded
                            # 3. 0x08 is machine ready to perform job

    # These globals are technically not required here but are given for clarity

    global is_usb_plugged_in
    global are_files_uploading_now
    global have_all_files_uploaded
    global is_machine_ready_to_perform_job

    # Set the bit flags

    flags = 0

    if is_usb_plugged_in:
        flags |= 0x01

    if are_files_uploading_now:
        flags |= 0x02

    if have_all_files_uploaded:
        flags |= 0x04

    if is_machine_ready_to_perform_job:
        flags |= 0x08

    # I am only sending one byte so I set my dlc to 1.  I left the other parameters: 
    # header, is_rtr, is_extended, is_error etc as default 

    file_system_status_message = Frame(id=TxPDO_cobid, dlc=1, data=[flags, 0, 0, 0, 0, 0, 0, 0])    
    file_system_status_publisher.publish(file_system_status_message)

Here is a candump showing it working:

xxx@my_computer:~$ candump can0 | grep 4A3
  can0  4A3   [1]  00
  can0  4A3   [1]  00
  can0  4A3   [1]  03
  can0  4A3   [1]  05
  can0  4A3   [1]  05
  can0  4A3   [1]  05
  can0  4A3   [1]  05

This would seem similar to your requirements