#include "ros/ros.h"
#include<geometry_msgs/Twist.h>
int main(int argc, char *argv[])
{
int PI = 3.141592653589793653589793;
ros::init(argc, argv, "heart_shape");
ros::NodeHandle n;
ros::Publisher vel_pub = n.advertise<geometry_msgs::Twist>("/turtle1/cmd_vel", 10);
geometry_msgs::Twist vel_cmd;
ros::Rate loopRate(2);
int count = 0;
int i = 0;
while(ros::ok())
{
vel_cmd.linear.x = 1.0;
vel_cmd.linear.y = 0.0;
vel_cmd.linear.z = 0.0;
vel_cmd.angular.x = 0;
vel_cmd.angular.y = 0;
vel_cmd.angular.z = 1;
count++;
while (count==9&&i==0)
{
count = 0;
i=1;
vel_cmd.linear.x = 0.0;
vel_cmd.angular.z = 2*PI;
}
while (count==7&&i==1)
{
vel_cmd.linear.x = 1.0;
vel_cmd.angular.z = 2;
}
vel_pub.publish(vel_cmd);
ros::spinOnce();
loopRate.sleep();
}
return 0;
}
我的想法是先画两个半圆,再画一个大的半圆,但代码怎么改写都没办法实现,下面是基本思路,没有写完但调试出现问题