Skip to content

Instantly share code, notes, and snippets.

@horverno
Created June 17, 2022 07:37
Show Gist options
  • Save horverno/c8132cb825ef7a6cb0890b09c8e7c531 to your computer and use it in GitHub Desktop.
Save horverno/c8132cb825ef7a6cb0890b09c8e7c531 to your computer and use it in GitHub Desktop.
cpp ROS circle
#include <visualization_msgs/Marker.h>
#include <math.h>
///....
ros::Publisher circ_marker_pub = n.advertise<visualization_msgs::Marker>("pure_circle", 1);
///....
visualization_msgs::Marker circle_marker;
circle_marker.header.frame_id = "map";
circle_marker.header.stamp = ros::Time::now();
circle_marker.ns = "basic_shapes";
circle_marker.id = 0;
circle_marker.type = circle_marker.LINE_STRIP;
circle_marker.action = visualization_msgs::Marker::ADD;
circle_marker.pose.position.x = 0;
circle_marker.pose.position.y = 0;
circle_marker.pose.position.z = 0;
circle_marker.pose.orientation.x = 0.0;
circle_marker.pose.orientation.y = 0.0;
circle_marker.pose.orientation.z = 0.0;
circle_marker.pose.orientation.w = 1.0;
circle_marker.scale.x = 1.0;
circle_marker.color.r = 0.1f;
circle_marker.color.g = 0.4f;
circle_marker.color.b = 0.9f;
circle_marker.color.a = 1.0;
circle_marker.lifetime = ros::Duration();
float f = 0.0;
float cent_x = 2.1; // Matyi
float cent_y = 8.1; // Matyi
float radius = 4.1; // Matyi
for (double i = 0.0; i < M_PI*2; i = i + 0.1)
{
double x = cent_x + radius * cos(i);
double y = cent_x + radius * sin(i);
geometry_msgs::Point p;
p.x = x;
p.y = y;
p.z = 0.0;
circle_marker.points.push_back(p);
}
circ_marker_pub.publish(circle_marker);
@horverno
Copy link
Author

image

@horverno
Copy link
Author

circle_marker.points.clear(); is needed in the for loop 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment