<commit_before>#include <rclcpp/rclcpp.hpp>
#include <fake_ar_publisher_msgs/msg/ar_marker.hpp>
#include <visualization_msgs/msg/marker.hpp>


rclcpp::Publisher ar_pub;
rclcpp::Publisher visual_pub;

static std::string& camera_frame_name()
{
  static std::string camera_frame;
  return camera_frame;
} 

// Singleton Instance of Object Position
static geometry_msgs::Pose& pose()
{
  static geometry_msgs::Pose pose;
  return pose;
}

// Given a marker w/ pose data, publish an RViz visualization
// You'll need to add a "Marker" visualizer in RVIZ AND define
// the "camera_frame" TF frame somewhere to see it.
static void pubVisualMarker(const fake_ar_publisher_msgs::ARMarker& m)
{
  const double width = 0.08;
  const double thickness = 0.005;
  
  visualization_msgs::Marker marker;
  marker.header.frame_id = m.header.frame_id;
  marker.header.stamp = rclcpp::Time::now();
  marker.ns = "ar_marker_visual";
  marker.id = 0;
  marker.type = visualization_msgs::Marker::CUBE;
  marker.action = visualization_msgs::Marker::ADD;
  marker.pose = m.pose.pose;
  marker.pose.position.z -= thickness / 2.0;
  marker.scale.x = width;
  marker.scale.y = width;
  marker.scale.z = thickness;
  marker.color.a = 1.0;
  marker.color.b = 1.0;
  
  visual_pub.publish(marker);
}

void pubCallback(const rclcpp::TimerEvent&)
{
  geometry_msgs::Pose p = pose();
  fake_ar_publisher::ARMarker m;
  m.header.frame_id = camera_frame_name();
  m.header.stamp = rclcpp::Time::now();
  m.pose.pose = p;

  ar_pub.publish(m);
  
  pubVisualMarker(m); // visualize the marker
}

int main(int argc, char **argv)
{
  // Set up ROS.
  rclcpp::init(argc, argv);
  auto node = rclcpp::Node::make_shared("fake_ar_publisher")
  auto pnh = rclcpp::Node::make_shared("~");
  ar_pub = nh.advertise<fake_ar_publisher_msgs::ARMarker>("ar_pose_marker", 1);
  visual_pub = nh.advertise<visualization_msgs::Marker>("ar_pose_visual", 1);

  // init pose
  pose().orientation.w = 1.0; // facing straight up
  pnh.param<double>("x_pos", pose().position.x, -0.6);
  pnh.param<double>("y_pos", pose().position.y, 0.2);
  pnh.param<double>("z_pos", pose().position.z, 0.5);
  
  pnh.param<std::string>("camera_frame", camera_frame_name(), "camera_frame");

  RCLCPP_INFO("Starting simulated ARMarker publisher");  
  rclcpp::Timer t = node.createTimer(rclcpp::Duration(0.1), pubCallback, false, true);
  rclcpp::spin();
}<commit_msg>Make fake_ar_publisher into a class<commit_after>#include <rclcpp/rclcpp.hpp>
#include <fake_ar_publisher_msgs/msg/ar_marker.hpp>
#include <visualization_msgs/msg/marker.hpp>

using namespace std::chrono_literals;

static std::string& camera_frame_name()
{
  static std::string camera_frame;
  return camera_frame;
} 

// Singleton Instance of Object Position
static geometry_msgs::msg::Pose& pose()
{
  static geometry_msgs::msg::Pose pose;
  return pose;
}

// Given a marker w/ pose data, publish an RViz visualization
// You'll need to add a "Marker" visualizer in RVIZ AND define
// the "camera_frame" TF frame somewhere to see it.

class FakeARPublisher : public rclcpp::Node
{
public:
  FakeARPublisher()
  : Node("fake_ar_publisher")
  {
    ar_pub_ = this->create_publisher<fake_ar_publisher_msgs::msg::ARMarker>("ar_pose_marker", 1);
    visual_pub_ = this->create_publisher<visualization_msgs::msg::Marker>("ar_pose_visual", 1);
    timer_ = this->create_wall_timer(100ms, std::bind(&FakeARPublisher::pubCallback, this));
    
  }

private:
  void pubVisualMarker(const fake_ar_publisher_msgs::msg::ARMarker& m)
  {
    const double width = 0.08;
    const double thickness = 0.005;
    
    visualization_msgs::msg::Marker marker;
    marker.header.frame_id = m.header.frame_id;
    marker.header.stamp = this->now();
    marker.ns = "ar_marker_visual";
    marker.id = 0;
    marker.type = visualization_msgs::msg::Marker::CUBE;
    marker.action = visualization_msgs::msg::Marker::ADD;
    marker.pose = m.pose.pose;
    marker.pose.position.z -= thickness / 2.0;
    marker.scale.x = width;
    marker.scale.y = width;
    marker.scale.z = thickness;
    marker.color.a = 1.0;
    marker.color.b = 1.0;
    
    visual_pub_->publish(marker);
  }


  void pubCallback()
  {
    geometry_msgs::msg::Pose p = pose();
    fake_ar_publisher_msgs::msg::ARMarker m;
    m.header.frame_id = camera_frame_name();
    m.header.stamp = this->now();
    m.pose.pose = p;

    ar_pub_->publish(m);
    
    pubVisualMarker(m); // visualize the marker
  }

  rclcpp::TimerBase::SharedPtr timer_;
  rclcpp::Publisher<fake_ar_publisher_msgs::msg::ARMarker>::SharedPtr ar_pub_;
  rclcpp::Publisher<visualization_msgs::msg::Marker>::SharedPtr visual_pub_;
};

int main(int argc, char **argv)
{
  // Set up ROS.
  rclcpp::init(argc, argv);
  auto node = rclcpp::Node::make_shared("fake_ar_publisher");
  RCLCPP_INFO(node->get_logger(), "Starting simulated ARMarker publisher");  
  rclcpp::spin(std::make_shared<FakeARPublisher>());
  rclcpp::shutdown();
  return 0;
}
{'fraction_non_alphanumeric': 0.143635263264071, 'fraction_numerical': 0.009279806334476498, 'mean_word_length': 4.558295964125561, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 28, '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': '6031916', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1771, 'n_words': 343}