robobuggy / buggysim / tutorials / mimic.cpp @ 08be08ec
History | View | Annotate | Download (844 Bytes)
1 |
#include <ros/ros.h> |
---|---|
2 |
#include <turtlesim/Pose.h> |
3 |
#include <turtlesim/Velocity.h> |
4 |
|
5 |
class Mimic |
6 |
{ |
7 |
public:
|
8 |
Mimic(); |
9 |
|
10 |
private:
|
11 |
void poseCallback(const turtlesim::PoseConstPtr& pose); |
12 |
|
13 |
ros::Publisher vel_pub_; |
14 |
ros::Subscriber pose_sub_; |
15 |
}; |
16 |
|
17 |
Mimic::Mimic() |
18 |
{ |
19 |
ros::NodeHandle input_nh("input");
|
20 |
ros::NodeHandle output_nh("output");
|
21 |
vel_pub_ = output_nh.advertise<turtlesim::Velocity>("command_velocity", 1); |
22 |
pose_sub_ = input_nh.subscribe<turtlesim::Pose>("pose", 1, &Mimic::poseCallback, |
23 |
this);
|
24 |
} |
25 |
|
26 |
void Mimic::poseCallback(const turtlesim::PoseConstPtr& pose) |
27 |
{ |
28 |
turtlesim::Velocity vel; |
29 |
vel.angular = pose->angular_velocity; |
30 |
vel.linear = pose->linear_velocity; |
31 |
vel_pub_.publish(vel); |
32 |
} |
33 |
|
34 |
int main(int argc, char** argv) |
35 |
{ |
36 |
ros::init(argc, argv, "turtle_mimic");
|
37 |
Mimic mimic; |
38 |
|
39 |
ros::spin(); |
40 |
} |
41 |
|