-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpositionsubscriber.cpp
36 lines (27 loc) · 1.06 KB
/
positionsubscriber.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
#include "positionsubscriber.h"
/*------------------------------POSITION SUBSCRIBER------------------------------*/
PositionSubscriber::PositionSubscriber(QObject* parent){
connect(this, SIGNAL(receivedXPosition(float)), this, SLOT(updateXPosition(float)));
connect(this, SIGNAL(receivedYPosition(float)), this, SLOT(updateYPosition(float)));
pos_sub_x = nh.subscribe("/xpos", 1, &PositionSubscriber::positionXCallback, this);
pos_sub_y = nh.subscribe("/ypos", 1, &PositionSubscriber::positionYCallback, this);
}
void PositionSubscriber::positionXCallback(const std_msgs::Float32::ConstPtr& msg){
emit receivedXPosition(msg->data);
}
void PositionSubscriber::positionYCallback(const std_msgs::Float32::ConstPtr& msg){
emit receivedYPosition(msg->data);
}
void PositionSubscriber::updatePosition(float x, float y){
m_x = x;
m_y = y;
emit positionChanged(x,y);
}
void PositionSubscriber::updateXPosition(float x){
m_x = x;
emit positionXChanged(x);
}
void PositionSubscriber::updateYPosition(float y){
m_y = y;
emit positionYChanged(y);
}