Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more parameters for camera topic examples. #425

Closed
wants to merge 0 commits into from

Conversation

DanBmh
Copy link
Contributor

@DanBmh DanBmh commented Jan 14, 2020

Added parameter for custom topic names, display window name and camera device id.

Signed-off-by: DanBmh

@DanBmh DanBmh force-pushed the master branch 3 times, most recently from 6f4682e to 09210d8 Compare January 14, 2020 15:27
Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Maybe it's useful to be able to set the camera ID, but I don't we should pass the topic names as parameters since the recommended way to change topics is with remapping. For example,

    ros2 run image_tools showimage --ros-args -r image:=another_topic

In fact, I've removed this from other demos in the past (#401).

Also, I don't see the value in configuring the window name with a parameter. It may distract from the demo.

@DanBmh
Copy link
Contributor Author

DanBmh commented Jan 21, 2020

I didnt think about remapping before, but will this still work if i have two cam2img nodes? In my setup i have two cameras and i would like to stream both of them to their own topic.

Regarding the window name i think i will get the same problem of two windows with the same name if i want to display both camera streams.

Also i dont think the extra parameters will distract users much from the demo as they are optional, but they make the demo (as a build in feature) more usable for other purposes. (I could replace an old ros1 package i used before)

By the way, i was very glad when i found out yesterday that the topic argument existed before. i have ros2 crystal running on a raspi and could not build the package with my changes as a lot other things here have changed inbetween.

@jacobperron
Copy link
Member

I didnt think about remapping before, but will this still work if i have two cam2img nodes? In my setup i have two cameras and i would like to stream both of them to their own topic.

Yes, remapping can be configured per node. For example, if there is more than one node in a process, then we can prefix remaps with the node name and a colon (reference):

ros2 run image_tools showimage --ros-args -r showimage:image:=another_topic

Alternatively, launch supports remapping node topics (e.g. see launch XML design)

I'll add that this demo code is just that, a demonstration. It is not intended to be used directly in other applications and so I'm not convinced we need to worry about supporting more general use-cases. I recommend adapting the code as you need for your application, or use existing tools like rqt_image_view for viewing images from ROS topics.

@DanBmh
Copy link
Contributor Author

DanBmh commented Jan 22, 2020

Thanks for the example and links. If i try this with one node it is working. But if i try it with two nodes it doesnt do most of the times. Using following commands:

sleep 1; ros2 run image_tools cam2image --ros-args -r __ns:=/card_cam_node -p device_id:=0
sleep 2; ros2 run image_tools cam2image --ros-args -r __ns:=/face_cam_node -p device_id:=1

i think the same problem would occur with my topic arguments, as i believe the problem is that im using the same node twice. I also tried to rename the node only with -r __node:=card_cam_node and to remap the topic -r cam2img:image:=card_cam but this doesnt work too. I always get only the topics of the node i started last.

But in rare cases i got both nodes topics at the same time, as intended, but using the same commands and order again (im starting it with docker-compose), the next time i only get one nodes topics.

Is there an argument to run both nodes at the same time?
And do you know the reason for the behavior that my commands did work sometimes?

@jacobperron
Copy link
Member

jacobperron commented Jan 23, 2020

ros2 run is a blocking call. Can you try running the commands in separate shells? I suggest you try using the launch system for starting multiple nodes at the same time. For example, the following launch file should work in Eloquent:

<launch>
  <node namespace="/card_cam" pkg="image_tools" exec="cam2image" output="screen">
    <param name="device_id" value="0" />
  </node>
  <node namespace="/face_cam" pkg="image_tools" exec="cam2image" output="screen">
    <param name="device_id" value="1" />
  </node>
</launch>

You can start it with ros2 launch.

Edit: using namespace instead of node-name in example.

image_tools/src/cam2image.cpp Outdated Show resolved Hide resolved
image_tools/src/cam2image.cpp Outdated Show resolved Hide resolved
image_tools/src/showimage.cpp Outdated Show resolved Hide resolved
@DanBmh
Copy link
Contributor Author

DanBmh commented Feb 3, 2020

I added your suggestion to use the topic name as window name, but only as default value so that a user still can use a custom window name if he likes to.

Using a launch file to start the two camera nodes did work for me. Afterwards i tried running the two separate commands again and i found out this only works if i dont give parameters with -p. If i run it with extra parameters like frequency or width and height the topics of one node always were missing. So im using the launch file solution now.

Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One lint error to fix, otherwise LGTM

image_tools/src/showimage.cpp Outdated Show resolved Hide resolved
@jacobperron
Copy link
Member

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status
  • Windows-container Build Status

@jacobperron
Copy link
Member

There was a compiler warning on Windows, I think 3ba0218 should fix it.
Windows: Build Status

@DanBmh
Copy link
Contributor Author

DanBmh commented Feb 11, 2020

What do we do with this warning now?

@jacobperron
Copy link
Member

What do we do with this warning now?

Sorry, this PR dropped off my radar. I can spend some time investigating on a Windows host when I have a moment.

@jacobperron
Copy link
Member

@DanBmh Sorry, I accidentally pushed the wrong changes to your fork when trying to rebase this PR. I've reopened a PR with your changes in #465. I think I've resolved the compiler warning on Windows too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants