UbiquityRobotics / raspicam_node

ROS node for camera module of Raspberry Pi
BSD 3-Clause "New" or "Revised" License
293 stars 162 forks source link

how can I run the raspicam_node on two different robots at the same time? #101

Closed Michdo93 closed 3 years ago

Michdo93 commented 3 years ago

Hi,

I want to know how I could run this node on two diffrent robots at the same time? Is it possible. Because in the same network it is not the best solution to run it and subscribe from'/raspicam_node/image/compressed' it would be better if there is a solution where I can do something like this: '<robot_name>/raspicam_node/image/compressed'

Michdo93 commented 3 years ago

Ok I have done following:

  char hostname[HOST_NAME_MAX];

  gethostname(hostname, HOST_NAME_MAX);

  std::string image_str = std::string(hostname) + "/image";
  std::string motion_vectors_str = std::string(hostname) + "/motion_vectors";
  std::string image_compressed_str = std::string(hostname) + "/image/compressed";
  std::string camera_info_str = std::string(hostname) + "/camera_info";

  if (state_srv.enable_raw_pub){
    auto image_pub = nh_topics.advertise<sensor_msgs::Image>(image_str, 1);
    image.pub.reset(new DiagnosedPublisher<sensor_msgs::Image>(
        image_pub, state_srv.updater, FrequencyStatusParam(&min_freq, &max_freq, 0.1, 10), TimeStampStatusParam(0, 0.2)));
  }

  if (state_srv.enable_imv_pub) {
    auto imv_pub = nh_topics.advertise<raspicam_node::MotionVectors>(motion_vectors_str, 1);
    motion_vectors.pub.reset(new DiagnosedPublisher<raspicam_node::MotionVectors>(
        imv_pub, state_srv.updater, FrequencyStatusParam(&min_freq, &max_freq, 0.1, 10), TimeStampStatusParam(0, 0.2)));
  }

  auto cimage_pub = nh_topics.advertise<sensor_msgs::CompressedImage>(image_compressed_str, 1);
  compressed_image.pub.reset(new DiagnosedPublisher<sensor_msgs::CompressedImage>(
      cimage_pub, state_srv.updater, FrequencyStatusParam(&min_freq, &max_freq, 0.1, 10), TimeStampStatusParam(0, 0.2)));

  camera_info_pub = nh_topics.advertise<sensor_msgs::CameraInfo>(camera_info_str, 1);

Now it is available under '/raspicam_node/<robot_name>/image/compressed'