Skip to content

Commit 9f7a50e

Browse files
committed
Add latest message into tcp-ros bridge with server
1 parent a96774a commit 9f7a50e

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

include/tcp_ros_bridge/tcp_ros_bridge_with_server.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99

1010
#pragma once
1111

12+
#define LATEST_MSG
13+
14+
#ifdef LATEST_MSG
15+
#include "message_latest.hpp"
16+
#else
1217
#include "message.h"
18+
#endif
19+
1320

1421
#include <memory>
1522

@@ -37,7 +44,6 @@
3744

3845
using boost::asio::ip::tcp;
3946

40-
4147
#define DEBUG_
4248

4349
namespace tcp_ros_bridge{
@@ -306,11 +312,25 @@ class tcp_ros_bridge :
306312
{
307313
uint8_t mode, status_fd, vel, light, elevator;
308314
float course, depth;
315+
uint16_t propeller1, propeller2, propeller3, propeller4; // latest
316+
uint16_t sensor_switch, load_reject, release_ins; // latest
309317

310318
// get control parameters from command
319+
#ifdef LATEST_MSG
320+
message_get_control_cmd(&mode, &status_fd, &vel, &course, &depth,
321+
&propeller1, &propeller2, &propeller3, &propeller4,
322+
&light, &elevator, &ctrl_info_.fin0_, &ctrl_info_.fin1_, &ctrl_info_.fin2_, &ctrl_info_.fin3,
323+
&sensor_switch, &load_reject, &release_ins);
324+
#else
311325
message_get_control_cmd(&mode, &status_fd, &vel, &course, &depth,
312326
&ctrl_info_.fin0_, &ctrl_info_.fin1_, &ctrl_info_.fin2_, &ctrl_info_.fin3_, &light, &elevator);
327+
#endif
313328

329+
ctrl_info_.fin0_ = ctrl_info_.fin0_ / 57.3;
330+
ctrl_info_.fin1_ = ctrl_info_.fin1_ / 57.3;
331+
ctrl_info_.fin2_ = ctrl_info_.fin2_ / 57.3;
332+
ctrl_info_.fin3_ = ctrl_info_.fin3_ / 57.3;
333+
314334
std::cout << "[tcp_ros_bridge]: recv fin: " << ctrl_info_.fin0_ << " "
315335
<< ctrl_info_.fin1_ << " "
316336
<< ctrl_info_.fin2_ << " "

src/tcp_ros_bridge_with_server.cpp

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ tcp_ros_bridge::tcp_ros_bridge(const std::string& auv_name,
3939
posegt_sub_ = nh.subscribe<nav_msgs::Odometry>(auv_name + "/pose_gt", 1, boost::bind(&tcp_ros_bridge::posegtCb, this, _1));
4040
dvl_sub_ = nh.subscribe<uuv_sensor_ros_plugins_msgs::DVL>(auv_name + "/dvl", 1, boost::bind(&tcp_ros_bridge::dvlCb, this, _1));
4141

42-
4342
// try create async server
4443
seq_ = 0;
4544

@@ -107,10 +106,10 @@ void tcp_ros_bridge::uuv_ctrl_publish_thread()
107106

108107
ctrl_info_ = tcp_msg_sub_->getCtrlInfo();
109108

110-
fins0 = ctrl_info_.fin0_ / 57.3;
111-
fins1 = ctrl_info_.fin1_ / 57.3;
112-
fins2 = ctrl_info_.fin2_ / 57.3;
113-
fins3 = ctrl_info_.fin3_ / 57.3;
109+
fins0 = ctrl_info_.fin0_;
110+
fins1 = ctrl_info_.fin1_;
111+
fins2 = ctrl_info_.fin2_;
112+
fins3 = ctrl_info_.fin3_;
114113

115114
rpm = ctrl_info_.rpm_;
116115

@@ -131,16 +130,16 @@ void tcp_ros_bridge::uuv_ctrl_publish_thread()
131130
uuv_gazebo_ros_plugins_msgs::FloatStamped fins_msg;
132131
fins_msg.header = header;
133132
// upper port
134-
fins_msg.data = fins0;
133+
fins_msg.data = -fins0;
135134
fins0_pub_.publish(fins_msg);
136135
// upper starboard
137-
fins_msg.data = fins1;
136+
fins_msg.data = -fins1;
138137
fins1_pub_.publish(fins_msg);
139138
// lower port
140-
fins_msg.data = fins2;
139+
fins_msg.data = -fins2;
141140
fins2_pub_.publish(fins_msg);
142141
// lower starboard
143-
fins_msg.data = fins3;
142+
fins_msg.data = -fins3;
144143
fins3_pub_.publish(fins_msg);
145144

146145
boost::this_thread::sleep(boost::posix_time::milliseconds(period_ * 1000));
@@ -197,15 +196,42 @@ void tcp_ros_bridge::uuv_status_send_thread()
197196
uint8_t mode = 0xFF; uint8_t light = 0xFF; uint8_t elevator = 0xFF; // default
198197
uint8_t cmd = 0xFF;
199198

200-
double lng = 114.31; double lat = 30.52;
201-
202-
message_status_pack(mode, 20.0, -5.0, -10.0, 0.0, 0.0, 0.0,
199+
double ins_lng = 114.31; double ins_lat = 30.52;
200+
201+
double battery_volt = 12.0; // unit: V
202+
uint8_t battery_volumn = 0x32; // 50%
203+
double battry_temp = 30.0; // degree
204+
205+
uint32_t leak = 0x00000001;
206+
uint8_t battery_emerg = 0x01;
207+
uint8_t added_battery_emerg = 0x01;
208+
uint8_t propeller_emerg = 0x01;
209+
uint8_t node_emerg = 0x01;
210+
uint8_t estar_fd = 0xFF;
211+
uint8_t load_reject_fd = 0xFF;
212+
uint8_t sensor_switch_fd = 0x00;
213+
uint8_t release_fd = 0xFF;
214+
215+
#ifdef LATEST_MSG
216+
message_status_pack(mode, 5.0, 0.0, -5.0, 0.0, 0.0, 0.0, // mode, binocular_x, binocular_y, binocular_z, binocular_heel, binocular_pitch, binocular_yaw
217+
x, y, z, roll, pitch, yaw, // usbl_x, usbl_y, usbl_z, usbl_roll, usbl_pitch, usbl_yaw
218+
113.0, 30.0, // usbl_lat, usbl_lng
219+
500.0 - abs(z), abs(z), // height, depth
220+
ins_yaw, -pitch, roll, -v, u, -w, ins_lng, ins_lat, 0.0, 0.0, 0.0, // yaw, pitch, roll, vel_north, vel_east, vel_vert, ins_lng, ins_lat
221+
fin0, fin1, fin2, fin3, cmd, // rudder1, rudder2, rudder3, rudder4, command
222+
light, elevator, 0.0, 0.0, 0.0, // light, elevator, ins_accz, ins_accx, ins_accy
223+
battery_volt, battery_volumn, battry_temp, leak, battery_emerg, // battery_voltage, battery_volumn, battery_temperature, leakage, battery_emergency
224+
added_battery_emerg, propeller_emerg, node_emerg, estar_fd, load_reject_fd, sensor_switch_fd, release_fd); // added_battery_emergency, propeller_emergency, node_emergency,
225+
// estar_feedback, load_rejection feedback, sensor switch feedback, release feedback
226+
#else
227+
message_status_pack(mode, 5.0, 0.0, -5.0, 0.0, 0.0, 0.0,
203228
x, y, z, roll, pitch, yaw,
204229
500.0 - abs(z), abs(z),
205-
ins_yaw, -pitch, roll, -v, u, -w,
206-
lng, lat, 0.0, 0.0, 0.0,
230+
ins_yaw, -pitch, roll, -v, u, -w,ins_lng, ins_lat,
231+
0.0, 0.0, 0.0,
207232
fin0, fin1, fin2, fin3, cmd,
208233
light, elevator);
234+
#endif
209235

210236
uint8_t send_buffer[512];
211237
uint16_t len = message_msg_to_send_buffer(send_buffer, 0);

0 commit comments

Comments
 (0)