-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsub.cpp
74 lines (66 loc) · 2.12 KB
/
sub.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <rclcpp/rclcpp.hpp>
#include <geometry_msgs/msg/twist.hpp>
using namespace std::chrono_literals;
class ManipulatorController : public rclcpp::Node
{
public:
ManipulatorController() : Node("manipulator_controller")
{
publisher_ = this->create_publisher<geometry_msgs::msg::Twist>("manipulator_cmd", 10);
move_to_position1();
}
private:
void move_to_position1()
{
auto message = geometry_msgs::msg::Twist();
message.linear.x = 1.76;
message.linear.y = 0.0;
message.linear.z = 4.38;
message.angular.x = 3.21;
message.angular.y = 0.0;
publisher_->publish(message);
timer_ = this->create_wall_timer(2s, std::bind(&ManipulatorController::move_to_position2, this));
}
void move_to_position2()
{
auto message = geometry_msgs::msg::Twist();
message.linear.x = 0.0;
message.linear.y = 0.8;
message.linear.z = 2.4;
message.angular.x = 0.0;
message.angular.y = 0.0;
publisher_->publish(message);
timer_ = this->create_wall_timer(2s, std::bind(&ManipulatorController::move_to_position3, this));
}
void move_to_position3()
{
auto message = geometry_msgs::msg::Twist();
message.linear.x = 0.0;
message.linear.y = 0.0;
message.linear.z = 0.5;
message.angular.x = 0.0;
message.angular.y = 1.0;
publisher_->publish(message);
timer_ = this->create_wall_timer(2s, std::bind(&ManipulatorController::stop, this));
}
void stop()
{
auto message = geometry_msgs::msg::Twist();
message.linear.x = 0.0;
message.linear.y = 0.0;
message.linear.z = 0.0;
message.angular.x = 0.0;
message.angular.y = 0.0;
publisher_->publish(message);
}
rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr publisher_;
rclcpp::TimerBase::SharedPtr timer_;
};
int main(int argc, char *argv[])
{
rclcpp::init(argc, argv);
auto node = std::make_shared<ManipulatorController>();
rclcpp::spin(node);
rclcpp::shutdown();
return 0;
}