lcm_to_ros
lcm_to_ros copied to clipboard
Trouble with lcm_to_ros for image transmission
Hi,
I'm trying to republish an lcm image topic to a rostopic using your lcm_to_ros repo.
But when I use the pipeline, after generating the header files and running the roslaunch file, I get the following error message:
error -1 decoding image_t!!!
Here is the lcm message definition file:
package image_types;
struct image_t
{
int32_t num_channels;
int32_t width;
int32_t height;
double image[num_channels][width][height];
}
Here is the file I'm using to publish the lcm image topic:
# %%
import numpy as np
import lcm
from image_types import image_t
# %%
lc = lcm.LCM()
# %%
msg = image_t()
msg.width = 10
msg.height = 3
msg.num_channels = 3
msg.image = np.random.rand(3, 10, 3).tolist()
# %%
lc = lcm.LCM()
lc.publish("image_topic", msg.encode())
Here is the config file I defined:
# --- Config file for generating ROS/LCM republishers ---
# This file is intended to be used with the rosrepub-gen
# script, which will (for each non-comment line of this
# file) attempt to generate C++ republisher code that
# republishes messages of a specified to to/from a ROS
# topic from/to an LCM topic.
# Each (non-comment) line of the file should contain four
# comma-separated fields:
# topic_name, msg_package, msg_type, direction
# LCM to ROS republisher with normal hash
#example_topic, exlcm, example_type, lcm2ros
# ROS to LCM republisher with overridden hash value
#other_topic, exlcm_rehash, example_type, ros2lcm
# LCM to ros image republisher
image_topic, image_types, image_t, lcm2ros
Should I be doing something with the rehashing? Is there something obvious that I messed up? I would appreciate some guidance.
Here is a link to a zip file of the catkin_ws I am using: https://drive.google.com/file/d/121cILabY0NERJZgVgLz5OANH4mor7CFj/view?usp=sharing
I'm sorry for the exceptionally long delay, and I guess this is far too late for you, but in case you or someone else is still interested, this is not really implemented because ros messages don't support multidimensional arrays in the same way as lcm (something like float64[][][] image
), except via a more custom handler and/or a multiarray. The lcm part works fine, and you can create and use the tool for the lcm messaging, but the ros message will be broken and not unpack the multi-dimensional array properly.
Unfortunately I can't see an easy way to fix this, though it would probably be possible via implementing a converter that recognises a multi-dimensional array input in the lcm message and then creates a multiarray output when generating the ros message. Another, possibly easier but also inelegant option would be to package nested messages, with an array of 2D images (e.g one for each channel) at the top level message, then each 2D image is an array of length 'width', filled with 1D array messages (each of length 'height'). This should work fine, if a little awkward to access. If it's still of interest please let me know and I can add an example for the second option.
In partial answer to the rest of your question, the python interface should also work fine, and/or I could add some options to the rosmsg-gen.sh
script to also generate the python message definitions via lcm-gen -p
too.