-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsub_and_pub_template.cpp
More file actions
51 lines (42 loc) · 1.1 KB
/
sub_and_pub_template.cpp
File metadata and controls
51 lines (42 loc) · 1.1 KB
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
#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
#include "std_msgs/Float64.h"
class SubscribeAndPublish
{
private:
// ROS
ros::NodeHandle n_;
ros::Subscriber twist_sub;
ros::Publisher float_pub;
public:
SubscribeAndPublish()
{
// Subscriber
twist_sub = n_.subscribe("pitch_yaw", 10, &SubscribeAndPublish::process_angle, this);
// Publisher
float_pub = n_.advertise<std_msgs::Float64>("angle", 1);
}
~SubscribeAndPublish() {}
void process_angle(const geometry_msgs::Twist twist)
{
// Initialize published message
std_msgs::Float64 angle;
// Map to angle
float angle_map = 1.047;
angle.data = twist.angular.z * angle_map;
// ROS_INFO("Get angle %f", angle.data);
float_pub.publish(angle);
}
};
int main(int argc, char *argv[])
{
// Launch ros node class
ros::init(argc, argv, "sub_and_pub_template_node");
SubscribeAndPublish SAP;
// Set rate and run
ros::Rate rate(60);
while (ros::ok())
ros::spinOnce();
rate.sleep();
return 0;
}