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

Convert a custom can type to can_msgs/Frame

asked 2020-07-29 03:28:04 -0500

ashwinsarvesh gravatar image

updated 2022-05-23 09:02:50 -0500

lucasw gravatar image

Hello,

I would like to convert the CanbusData type to can_msgs/Frame type. But I am not sure how to proceed because the CanBusData type has individual signals defined but the can_msgs/Frame type has frame definitions. For example. I would like to convert "Speed","LeftTurnSignal","RightTurnSignal" signals of the CanBusData type to can_msgs/Frame type, and send it to the socketcan_bridge. But not sure how to do it.

It means a lot if someone could help me, please.

edit retag flag offensive close merge delete

Comments

@gvdhoorn or someone else any help for this?

ashwinsarvesh gravatar image ashwinsarvesh  ( 2020-07-30 04:55:48 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-06-13 08:09:58 -0500

James NT gravatar image

updated 2021-06-13 08:34:15 -0500

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

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2020-07-29 03:28:04 -0500

Seen: 608 times

Last updated: Jun 13 '21