-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturtle_circle.cpp
More file actions
32 lines (29 loc) · 1019 Bytes
/
Copy pathturtle_circle.cpp
File metadata and controls
32 lines (29 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<rclcpp/rclcpp.hpp>
#include"geometry_msgs/msg/twist.hpp"
#include"chrono"
class TurtleCircleNode: public rclcpp::Node
{
private:
rclcpp::TimerBase::SharedPtr timer_;
rclcpp::Publicsher<geometry_msgs::msg::Twist>::SharedPtr Publicsher_; //发布者的智能指针
public:
explicit TurtleCircleNode(const std::string& node_name):Node(node_name)
{
publicher_ = this->create_publisher<geometry_msgs::msg::Twist>("turtle1_cmd_vel", 10);
timer_ = this->create_wall_timer(1000ms,std::bind(&TurtleCircleNode::timer_callback,this));
}
void timer_callback()
{
auto msg = geometry_msgs::msg::Twist();
msg.linear.x = 1.0;
msg.linear.z = 0.5;
publisher_->publish(msg);
}
} ;
int main(int argc,char* argv[])
{
rclcpp::init(argc,argv);
auto node = std::make_shared<TurtleCircleNode>("turtle_node");
rclcpp::spin(node);
rclcpp::shutdown();
}