robobuggy / turtlesim_ref / tutorials / mimic.cpp @ dd5d7f53
History | View | Annotate | Download (842 Bytes)
1 |
#include <ros/ros.h> |
---|---|
2 |
#include <turtlesim_ref/Pose.h> |
3 |
#include <turtlesim_ref/Velocity.h> |
4 |
|
5 |
class Mimic |
6 |
{ |
7 |
public:
|
8 |
Mimic(); |
9 |
|
10 |
private:
|
11 |
void poseCallback(const turtlesim_ref::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_ref::Velocity>("command_velocity", 1); |
22 |
pose_sub_ = input_nh.subscribe<turtlesim_ref::Pose>("pose", 1, &Mimic::poseCallback, this); |
23 |
} |
24 |
|
25 |
void Mimic::poseCallback(const turtlesim_ref::PoseConstPtr& pose) |
26 |
{ |
27 |
turtlesim_ref::Velocity vel; |
28 |
vel.angular = pose->angular_velocity; |
29 |
vel.linear = pose->linear_velocity; |
30 |
vel_pub_.publish(vel); |
31 |
} |
32 |
|
33 |
int main(int argc, char** argv) |
34 |
{ |
35 |
ros::init(argc, argv, "turtle_mimic");
|
36 |
Mimic mimic; |
37 |
|
38 |
ros::spin(); |
39 |
} |
40 |
|