Skip to content

Commit 7afd4bc

Browse files
Added Nav2 support (#72)
* Added Nav2 support * Patched serial implementation and improved RTCM3 stream * Added missing dependencies * Updated packages --------- Co-authored-by: Facundo Garcia <facundo.garcia@fixposition.com>
1 parent 21b772e commit 7afd4bc

File tree

27 files changed

+507
-115
lines changed

27 files changed

+507
-115
lines changed

fixposition_driver_lib/include/fixposition_driver_lib/fixposition_driver.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class FixpositionDriver {
149149
int client_fd_ = -1; //!< TCP or Serial file descriptor
150150
int connection_status_ = -1;
151151
struct termios options_save_;
152+
uint8_t readBuf[8192];
153+
int buf_size = 0;
152154
};
153155
} // namespace fixposition
154156
#endif //__FIXPOSITION_DRIVER_LIB_FIXPOSITION_DRIVER__

fixposition_driver_lib/include/fixposition_driver_lib/params.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct FpOutputParams {
3030
std::vector<std::string> formats; //!< data formats to convert, supports "FP" for now
3131
std::string qos_type; //!< ROS QoS type, supports "sensor_<short/long>" and "default_<short/long>"
3232
bool cov_warning; //!< enable/disable covariance warning
33+
bool nav2_mode; //!< enable/disable nav2 mode
3334

3435
std::string ip; //!< IP address for TCP connection
3536
std::string port; //!< Port for TCP connection

fixposition_driver_lib/src/fixposition_driver.cpp

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -257,66 +257,67 @@ bool FixpositionDriver::RunOnce() {
257257
}
258258

259259
bool FixpositionDriver::ReadAndPublish() {
260-
char readBuf[8192];
261-
262-
ssize_t rv;
263-
if (params_.fp_output.type == INPUT_TYPE::TCP) {
264-
rv = recv(client_fd_, (void*)&readBuf, sizeof(readBuf), MSG_DONTWAIT);
265-
} else if (params_.fp_output.type == INPUT_TYPE::SERIAL) {
266-
rv = read(client_fd_, (void*)&readBuf, sizeof(readBuf));
267-
} else {
268-
rv = 0;
269-
}
270-
271-
if (rv == 0) {
272-
std::cerr << "Connection closed.\n";
273-
return false;
274-
}
275-
276-
if (rv < 0 && errno == EAGAIN) {
277-
/* no data for now, call back when the socket is readable */
260+
int msg_size = 0;
261+
// Nov B
262+
msg_size = IsNovMessage(readBuf, buf_size);
263+
if (msg_size > 0) {
264+
NovConvertAndPublish(readBuf);
265+
buf_size -= msg_size;
266+
if (buf_size > 0) {
267+
memmove(readBuf, &readBuf[msg_size], buf_size);
268+
}
278269
return true;
279-
}
280-
if (rv < 0) {
281-
std::cerr << "Connection error.\n";
282-
return false;
283-
}
284-
285-
ssize_t start_id = 0;
286-
while (start_id < rv) {
287-
int msg_size = 0;
288-
// Nov B
289-
msg_size = IsNovMessage((uint8_t*)&readBuf[start_id], rv - start_id);
270+
} else if (msg_size == 0) {
271+
// Nmea (incl. FP_A)
272+
msg_size = IsNmeaMessage((char*)readBuf, buf_size);
290273
if (msg_size > 0) {
291-
NovConvertAndPublish((uint8_t*)&readBuf[start_id]);
292-
start_id += msg_size;
293-
continue;
294-
}
295-
if (msg_size == 0) {
296-
// do nothing
297-
}
298-
if (msg_size < 0) {
299-
break;
274+
NmeaConvertAndPublish({(const char*)readBuf, (const char*)readBuf + msg_size});
275+
buf_size -= msg_size;
276+
if (buf_size > 0) {
277+
memmove(readBuf, &readBuf[msg_size], buf_size);
278+
}
279+
return true;
280+
} else if (msg_size == 0) {
281+
// If not NOV_B nor NMEA, remove 1 char
282+
if (buf_size > 0) {
283+
buf_size -= 1;
284+
memmove(readBuf, &readBuf[1], buf_size);
285+
}
286+
} else {
287+
// Wait for more data
300288
}
289+
} else {
290+
// wait for more data
291+
}
301292

302-
// Nmea (incl. FP_A)
303-
msg_size = IsNmeaMessage(&readBuf[start_id], rv - start_id);
304-
if (msg_size > 0) {
305-
// NovConvertAndPublish(start, msg_size);
306-
std::string msg(&readBuf[start_id], msg_size);
307-
NmeaConvertAndPublish(msg);
308-
start_id += msg_size;
309-
continue;
293+
// Read more data from the TCP/Serial port
294+
int rem_size = sizeof(readBuf) - buf_size;
295+
if (rem_size > 0) {
296+
ssize_t rv;
297+
if (params_.fp_output.type == INPUT_TYPE::TCP) {
298+
rv = recv(client_fd_, (void*)&readBuf[buf_size], sizeof(readBuf) - buf_size, MSG_DONTWAIT);
299+
} else if (params_.fp_output.type == INPUT_TYPE::SERIAL) {
300+
rv = read(client_fd_, (void*)&readBuf[buf_size], sizeof(readBuf) - buf_size);
301+
} else {
302+
rv = 0;
310303
}
311-
if (msg_size == 0) {
312-
// do nothing
304+
305+
if (rv == 0) {
306+
std::cerr << "Connection closed.\n";
307+
return false;
313308
}
314-
if (msg_size < 0) {
315-
break;
309+
310+
if (rv < 0 && errno == EAGAIN) {
311+
/* no data for now, call back when the socket is readable */
312+
return true;
313+
}
314+
315+
if (rv < 0) {
316+
std::cerr << "Connection error.\n";
317+
return false;
316318
}
317319

318-
// No Match, increment by 1
319-
++start_id;
320+
buf_size += rv;
320321
}
321322

322323
return true;

fixposition_driver_ros1/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ find_package(catkin REQUIRED COMPONENTS
2121
geometry_msgs
2222
message_generation
2323
eigen_conversions
24+
tf2_ros
25+
tf2_geometry_msgs
2426
)
2527
add_message_files(
2628
FILES
@@ -61,8 +63,8 @@ generate_messages(
6163
catkin_package(
6264
INCLUDE_DIRS include
6365
CATKIN_DEPENDS
64-
tf
65-
roscpp geometry_msgs
66+
tf tf2_ros
67+
roscpp geometry_msgs tf2_geometry_msgs
6668
nav_msgs std_msgs message_runtime
6769
)
6870

fixposition_driver_ros1/include/fixposition_driver_ros1/data_to_ros1.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ void TwistWithCovDataToMsg(const TwistWithCovData& data, geometry_msgs::TwistWit
9494
*/
9595
void OdometryDataToTf(const FP_ODOMETRY& data, tf2_ros::TransformBroadcaster& pub);
9696

97+
/**
98+
* @brief
99+
*
100+
* @param[in] data
101+
* @param[out] tf
102+
*/
103+
void OdomToTf(const OdometryData& data, geometry_msgs::TransformStamped& tf);
104+
105+
/**
106+
* @brief
107+
*
108+
* @param[in] tf_map
109+
* @param[out] static_br_
110+
* @param[out] br_
111+
*/
112+
void PublishNav2Tf(const std::map<std::string, std::shared_ptr<geometry_msgs::TransformStamped>>& tf_map, tf2_ros::StaticTransformBroadcaster& static_br_, tf2_ros::TransformBroadcaster& br_);
113+
97114
/**
98115
* @brief
99116
*

fixposition_driver_ros1/include/fixposition_driver_ros1/fixposition_driver_node.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class FixpositionDriverNode : public FixpositionDriver {
4343

4444
void RegisterObservers();
4545

46-
void WsCallback(const fixposition_driver_ros1::SpeedConstPtr& msg);
46+
void WsCallbackRos(const fixposition_driver_ros1::SpeedConstPtr& msg);
4747

48-
void RtcmCallback(const std_msgs::UInt8MultiArray::ConstPtr& msg);
48+
void RtcmCallbackRos(const rtcm_msgs::MessageConstPtr& msg);
4949

5050
private:
5151
/**
@@ -126,6 +126,14 @@ class FixpositionDriverNode : public FixpositionDriver {
126126
// Previous state
127127
Eigen::Vector3d prev_pos;
128128
Eigen::MatrixXd prev_cov;
129+
130+
// Nav2 TF map
131+
std::map<std::string, std::shared_ptr<geometry_msgs::TransformStamped>> tf_map = {
132+
{"ECEFENU0", nullptr},
133+
{"POIPOISH", nullptr},
134+
{"ECEFPOISH", nullptr},
135+
{"ENU0POI", nullptr}
136+
};
129137
};
130138

131139
} // namespace fixposition

fixposition_driver_ros1/include/fixposition_driver_ros1/ros_msgs.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@
2222
#include <tf2_ros/static_transform_broadcaster.h>
2323
#include <tf2_ros/transform_broadcaster.h>
2424
#include <tf2_ros/transform_listener.h>
25+
#include <tf2/LinearMath/Transform.h>
26+
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
2527

2628
// Include generic
2729
#include <fixposition_driver_ros1/Speed.h>
2830
#include <fixposition_driver_ros1/GnssSats.h>
2931
#include <fixposition_driver_ros1/NMEA.h>
3032

33+
// Include RTCM
34+
#include <rtcm_msgs/Message.h>
35+
3136
// Include extras
3237
#include <fixposition_driver_ros1/CovWarn.h>
3338

fixposition_driver_ros1/launch/serial.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ fp_output:
1010
rate: 200
1111
reconnect_delay: 5.0 # wait time in [s] until retry connection
1212
cov_warning: false
13+
nav2_mode: false
1314

1415
customer_input:
1516
speed_topic: "/fixposition/speed"
16-
rtcm_topic: "/fixposition/rtcm"
17+
rtcm_topic: "/rtcm"

fixposition_driver_ros1/launch/tcp.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ fp_output:
1010
rate: 200
1111
reconnect_delay: 5.0 # wait time in [s] until retry connection
1212
cov_warning: false
13+
nav2_mode: false
1314

1415
customer_input:
1516
speed_topic: "/fixposition/speed"
16-
rtcm_topic: "/fixposition/rtcm"
17+
rtcm_topic: "/rtcm"

fixposition_driver_ros1/package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
<depend>message_generation</depend>
1919
<depend>message_runtime</depend>
2020
<depend>fixposition_driver_lib</depend>
21+
<depend>rtcm_msgs</depend>
22+
<depend>tf2_ros</depend>
23+
<depend>tf2_geometry_msgs</depend>
2124
</package>

0 commit comments

Comments
 (0)