root / mikrokopter / altitude_node / src / altitude_node.cpp @ 737bd480
History | View | Annotate | Download (1.22 KB)
1 |
#include "ros/ros.h" |
---|---|
2 |
#include "std_msgs/Float64.h" |
3 |
#include "mikrokopter/FcDebug.h" |
4 |
#include "../../../control/pid_control.h" |
5 |
|
6 |
class AltitudeNode |
7 |
{ |
8 |
public:
|
9 |
AltitudeNode(); |
10 |
void main_loop() {ros::spin();}
|
11 |
void height_cb(const mikrokopter::FcDebug::ConstPtr& fc); |
12 |
void goal_cb(const std_msgs::Float64::ConstPtr& goal); |
13 |
|
14 |
private:
|
15 |
PID_control pid; |
16 |
ros::NodeHandle n; |
17 |
ros::Publisher pub; |
18 |
ros::Subscriber height_sub; |
19 |
ros::Subscriber goal_sub; |
20 |
}; |
21 |
|
22 |
AltitudeNode::AltitudeNode() : pid(10, 0, 0, 0) |
23 |
{ |
24 |
height_sub = n.subscribe<mikrokopter::FcDebug>("/mikrokopter/fc_debug",
|
25 |
100, &AltitudeNode::height_cb, this); |
26 |
goal_sub = n.subscribe<std_msgs::Float64>("/mikrokopter/height_goal",
|
27 |
100, &AltitudeNode::goal_cb, this); |
28 |
pub = n.advertise<std_msgs::Float64>("/mikrokopter/thrust", 100); |
29 |
} |
30 |
|
31 |
void AltitudeNode::height_cb(const mikrokopter::FcDebug::ConstPtr& fc) |
32 |
{ |
33 |
std_msgs::Float64 msg; |
34 |
msg.data = pid.pid(fc->heightValue, fc->header.stamp.toNSec()); |
35 |
pub.publish(msg); |
36 |
} |
37 |
|
38 |
void AltitudeNode::goal_cb(const std_msgs::Float64::ConstPtr& goal) |
39 |
{ |
40 |
pid.change_goal(goal->data); |
41 |
} |
42 |
|
43 |
int main(int argc, char **argv) { |
44 |
ros::init(argc, argv, "altitude_node");
|
45 |
AltitudeNode an = AltitudeNode(); |
46 |
an.main_loop(); |
47 |
return 0; |
48 |
} |