-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrosserialInterface.cpp
More file actions
55 lines (38 loc) · 1.11 KB
/
rosserialInterface.cpp
File metadata and controls
55 lines (38 loc) · 1.11 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
52
53
54
55
/**************************************
* Title : rosserialInterface.cpp
* Author : Ian Gagnon
* Created : 2021-05-05
*************************************/
#include "rosserialInterface.h"
ROSserialInterface::ROSserialInterface(): sub_("arduino_motors", &ROSserialInterface::callback, this), pub_("arduino_sensors", &msg_) {
}
ROSserialInterface::~ROSserialInterface() {
}
void ROSserialInterface::setup() {
nh_.initNode();
float data[N_DATA_TO_PUBLISH];
msg_.data = data;
msg_.data_length = N_DATA_TO_PUBLISH;
nh_.subscribe(sub_);
nh_.advertise(pub_);
}
void ROSserialInterface::callback(const std_msgs::Float32MultiArray& msg) {
for (int i=0; i<N_DATA_TO_RECEIVE; i++)
steps_[i] = msg.data[i];
newCommandReceived_ = true;
}
bool ROSserialInterface::newCommandReceived() {
return newCommandReceived_;
}
float* ROSserialInterface::getCommand() {
return steps_;
}
void ROSserialInterface::publish(float* arrayToPublish) {
for (int i=0; i<N_DATA_TO_PUBLISH; i++){
msg_.data[i] = arrayToPublish[i];
}
pub_.publish(&msg_);
}
void ROSserialInterface::main() {
nh_.spinOnce();
}