<commit_before>/*
 * Software License Agreement (BSD License)
 *
 * Copyright (c) 2014-, Open Perception, Inc.
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution.
 * * Neither the name of the copyright holder(s) nor the names of its
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * Author: <NAME> [<EMAIL>]
 *         <NAME> [<EMAIL>]
 *
 */

#include <ros/ros.h>
#include <ros/package.h>
#include <fstream>
#include <string.h>

int
main(int argc, char ** argv)
{
  ros::init(argc, argv, "calibration_initializer");
  ros::NodeHandle nh("~");

  // Read some parameters from launch file:
  int num_sensors;
  nh.param("num_sensors", num_sensors, 1);
  bool calibration_with_serials;
  nh.param("calibration_with_serials", calibration_with_serials, false);
  int rows;
  nh.param("rows", rows, 6);
  int cols;
  nh.param("cols", cols, 5);
  double cell_width;
  nh.param("cell_width", cell_width, 0.12);
  double cell_height;
  nh.param("cell_height", cell_height, 0.12);
  std::string driver_name;
  nh.param("driver", driver_name, std::string("openni"));

  // Read ID of sensors:
  std::vector<std::string> sensor_id_vector;
  for (unsigned int i = 0; i < num_sensors; i++)
  {
    std::stringstream ss;
    ss << "sensor" << i << "_id";
    std::string sensor_id;
    nh.param(ss.str(), sensor_id, std::string("./"));
    sensor_id_vector.push_back(sensor_id);
  }

  // Write launch file to be used for extrinsic calibration of the sensor network:
  std::string file_name = ros::package::getPath("opt_calibration") + "/launch/opt_calibration_master.launch";
  std::ofstream launch_file;
  launch_file.open(file_name.c_str());

  if (launch_file.is_open())
  {
    launch_file << "<launch>" << std::endl << std::endl;

    // Network parameters:
    launch_file << "  <!-- Network parameters -->" << std::endl
                << "  <arg name=\"num_sensors\" value=\"" << num_sensors << "\" />" << std::endl;

    for (unsigned int i = 0; i < num_sensors; i++)
    {
      if (!std::strcmp(sensor_id_vector[i].substr(0,1).c_str(), "1"))    // if SwissRanger
      {
        std::string sensor_name = sensor_id_vector[i];
        replace(sensor_name.begin(), sensor_name.end(), '.', '_');
        sensor_name = "SR_" + sensor_name;
        launch_file << "  <arg name=\"sensor" << i << "_id\" value=\"" << sensor_name << "\" />" << std::endl;
      }
      else
      {
        launch_file << "  <arg name=\"sensor" << i << "_id\" value=\"" << sensor_id_vector[i] << "\" />" << std::endl;
      }
      launch_file << "  <arg name=\"sensor" << i << "_name\" default=\"$(arg sensor" << i << "_id)\" />" << std::endl;
    }

    // Checkerboard parameters:
    launch_file << "  <!-- Checkerboard parameters -->" << std::endl
        << "  <arg name=\"rows\" default=\"" << rows << "\" />" << std::endl
        << "  <arg name=\"cols\" default=\"" << cols << "\" />" << std::endl
        << "  <arg name=\"cell_width\" default=\"" << cell_width << "\" />" << std::endl
        << "  <arg name=\"cell_height\" default=\"" << cell_height << "\" />" << std::endl << std::endl;

    // RViz and calibration node:
    launch_file << "  <!-- Opening Rviz for visualization-->" << std::endl
        << "  <node name=\"rviz\" pkg=\"rviz\" type=\"rviz\" args=\"-d $(find opt_calibration)/conf/opt_calibration.rviz\"/>" << std::endl << std::endl
        << "  <!-- Launching calibration -->" << std::endl
        << "  <node pkg=\"opt_calibration\" type=\"opt_calibration\" name=\"opt_calibration\" output=\"screen\">" << std::endl
        << "    <param name=\"num_sensors\" value=\"$(arg num_sensors)\" /> " << std::endl
        << "    <param name=\"rows\" value=\"$(arg rows)\" />" << std::endl
        << "    <param name=\"cols\" value=\"$(arg cols)\" />" << std::endl
        << "    <param name=\"cell_width\" value=\"$(arg cell_width)\" />" << std::endl
        << "    <param name=\"cell_height\" value=\"$(arg cell_height)\" />" << std::endl << std::endl
        << "    <param name=\"base_sensor\" value=\"$(arg base_sensor)\" />" << std::endl << std::endl;

    if (calibration_with_serials)
      launch_file << "    <param name=\"calibration_with_serials\" value=\"true\" />" << std::endl << std::endl;

    // Parameters and remapping for every sensor:
    for (unsigned int i = 0; i < num_sensors; i++)
    {
      launch_file << "    <param name=\"sensor_" << i << "/name\" value=\"/$(arg sensor" << i << "_name)\" />" << std::endl;

      if (!std::strcmp(sensor_id_vector[i].substr(0,1).c_str(), "1"))    // if SwissRanger (sensor_id is an IP address)<commit_msg>Bugfix. Removed base_sensor param from opt_calibration/launch/opt_calibration_master.launch creation.<commit_after>/*
 * Software License Agreement (BSD License)
 *
 * Copyright (c) 2014-, Open Perception, Inc.
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution.
 * * Neither the name of the copyright holder(s) nor the names of its
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * Author: <NAME> [<EMAIL>]
 *         <NAME> [<EMAIL>]
 *
 */

#include <ros/ros.h>
#include <ros/package.h>
#include <fstream>
#include <string.h>

int
main(int argc, char ** argv)
{
  ros::init(argc, argv, "calibration_initializer");
  ros::NodeHandle nh("~");

  // Read some parameters from launch file:
  int num_sensors;
  nh.param("num_sensors", num_sensors, 1);
  bool calibration_with_serials;
  nh.param("calibration_with_serials", calibration_with_serials, false);
  int rows;
  nh.param("rows", rows, 6);
  int cols;
  nh.param("cols", cols, 5);
  double cell_width;
  nh.param("cell_width", cell_width, 0.12);
  double cell_height;
  nh.param("cell_height", cell_height, 0.12);
  std::string driver_name;
  nh.param("driver", driver_name, std::string("openni"));

  // Read ID of sensors:
  std::vector<std::string> sensor_id_vector;
  for (unsigned int i = 0; i < num_sensors; i++)
  {
    std::stringstream ss;
    ss << "sensor" << i << "_id";
    std::string sensor_id;
    nh.param(ss.str(), sensor_id, std::string("./"));
    sensor_id_vector.push_back(sensor_id);
  }

  // Write launch file to be used for extrinsic calibration of the sensor network:
  std::string file_name = ros::package::getPath("opt_calibration") + "/launch/opt_calibration_master.launch";
  std::ofstream launch_file;
  launch_file.open(file_name.c_str());

  if (launch_file.is_open())
  {
    launch_file << "<launch>" << std::endl << std::endl;

    // Network parameters:
    launch_file << "  <!-- Network parameters -->" << std::endl
                << "  <arg name=\"num_sensors\" value=\"" << num_sensors << "\" />" << std::endl;

    for (unsigned int i = 0; i < num_sensors; i++)
    {
      if (!std::strcmp(sensor_id_vector[i].substr(0,1).c_str(), "1"))    // if SwissRanger
      {
        std::string sensor_name = sensor_id_vector[i];
        replace(sensor_name.begin(), sensor_name.end(), '.', '_');
        sensor_name = "SR_" + sensor_name;
        launch_file << "  <arg name=\"sensor" << i << "_id\" value=\"" << sensor_name << "\" />" << std::endl;
      }
      else
      {
        launch_file << "  <arg name=\"sensor" << i << "_id\" value=\"" << sensor_id_vector[i] << "\" />" << std::endl;
      }
      launch_file << "  <arg name=\"sensor" << i << "_name\" default=\"$(arg sensor" << i << "_id)\" />" << std::endl;
    }

    // Checkerboard parameters:
    launch_file << "  <!-- Checkerboard parameters -->" << std::endl
        << "  <arg name=\"rows\" default=\"" << rows << "\" />" << std::endl
        << "  <arg name=\"cols\" default=\"" << cols << "\" />" << std::endl
        << "  <arg name=\"cell_width\" default=\"" << cell_width << "\" />" << std::endl
        << "  <arg name=\"cell_height\" default=\"" << cell_height << "\" />" << std::endl << std::endl;

    // RViz and calibration node:
    launch_file << "  <!-- Opening Rviz for visualization-->" << std::endl
        << "  <node name=\"rviz\" pkg=\"rviz\" type=\"rviz\" args=\"-d $(find opt_calibration)/conf/opt_calibration.rviz\"/>" << std::endl << std::endl
        << "  <!-- Launching calibration -->" << std::endl
        << "  <node pkg=\"opt_calibration\" type=\"opt_calibration\" name=\"opt_calibration\" output=\"screen\">" << std::endl
        << "    <param name=\"num_sensors\" value=\"$(arg num_sensors)\" /> " << std::endl
        << "    <param name=\"rows\" value=\"$(arg rows)\" />" << std::endl
        << "    <param name=\"cols\" value=\"$(arg cols)\" />" << std::endl
        << "    <param name=\"cell_width\" value=\"$(arg cell_width)\" />" << std::endl
        << "    <param name=\"cell_height\" value=\"$(arg cell_height)\" />" << std::endl << std::endl;

    if (calibration_with_serials)
      launch_file << "    <param name=\"calibration_with_serials\" value=\"true\" />" << std::endl << std::endl;

    // Parameters and remapping for every sensor:
    for (unsigned int i = 0; i < num_sensors; i++)
    {
      launch_file << "    <param name=\"sensor_" << i << "/name\" value=\"/$(arg sensor" << i << "_name)\" />" << std::endl;

      if (!std::strcmp(sensor_id_vector[i].substr(0,1).c_str(), "1"))    // if SwissRanger (sensor_id is an IP address)
{'fraction_non_alphanumeric': 0.17308827248967204, 'fraction_numerical': 0.003709636624230672, 'mean_word_length': 3.343463932625412, 'pattern_counts': {'":': 0, '<': 390, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6639708', 'n_tokens_mistral': 3801, 'n_tokens_neox': 3564, 'n_words': 1063}