Skip to content

Commit 5c8c3bd

Browse files
committed
Fix axes
1 parent 1d2a763 commit 5c8c3bd

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

src/vectornav/vectornav/src/vectornav.cc

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -622,30 +622,6 @@ bool Vectornav::configure_sensor()
622622

623623
vs_->writeCommunicationProtocolControl(configComm);
624624

625-
// === ТЕСТ ===
626-
// Настройка поворота системы координат
627-
vn::math::mat3f rotation_matrix;
628-
rotation_matrix(0,0) = 0; // C00
629-
rotation_matrix(0,1) = -1; // C01
630-
rotation_matrix(0,2) = 0; // C02
631-
rotation_matrix(1,0) = 1; // C10
632-
rotation_matrix(1,1) = 0; // C11
633-
rotation_matrix(1,2) = 0; // C12
634-
rotation_matrix(2,0) = 0; // C20
635-
rotation_matrix(2,1) = 0; // C21
636-
rotation_matrix(2,2) = 1; // C22
637-
638-
try {
639-
vs_->writeReferenceFrameRotation(rotation_matrix);
640-
// Сохраняем в энергонезависимую память датчика
641-
vs_->writeSettings();
642-
RCLCPP_INFO(get_logger(), "Reference frame rotation applied");
643-
} catch (const std::exception& e) {
644-
RCLCPP_WARN(get_logger(), "Failed to set reference frame rotation: %s", e.what());
645-
}
646-
// === ТЕСТ END ===
647-
648-
649625
auto boRegs = std::vector<std::string>{"BO1", "BO2", "BO3"};
650626
auto boConfigs = std::vector<vn::sensors::BinaryOutputRegister>();
651627

src/vectornav/vectornav/src/vn_sensor_msgs.cc

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ static void convert_vec_frd_to_rfu(const geometry_msgs::msg::Vector3 & vec_frd,
103103
vec_rfu.z = -vec_frd.z;
104104
}
105105

106+
static void convert_vec_frd_to_rfu_custom(const geometry_msgs::msg::Vector3 & vec_frd, geometry_msgs::msg::Vector3 & vec_rfu)
107+
{
108+
// swap x and y and negate z
109+
vec_rfu.x = vec_frd.x;
110+
vec_rfu.y = -vec_frd.y;
111+
vec_rfu.z = vec_frd.z;
112+
}
113+
114+
static void convert_vec_frd_to_rfu_custom_rate(const geometry_msgs::msg::Vector3 & vec_frd, geometry_msgs::msg::Vector3 & vec_rfu)
115+
{
116+
// swap x and y and negate z
117+
vec_rfu.x = -vec_frd.x;
118+
vec_rfu.y = -vec_frd.y;
119+
vec_rfu.z = -vec_frd.z;
120+
}
121+
106122
static void convert_to_enu(const geometry_msgs::msg::Quaternion & q_msg_frd2ned, geometry_msgs::msg::Quaternion & q_msg_rfu2enu)
107123
{
108124
// convert from FRD_TO_NED to RFU_TO_ENU attitude
@@ -179,12 +195,18 @@ void VnSensorMsgs::sub_vn_common(const vectornav_msgs::msg::CommonGroup::SharedP
179195
msg.header = msg_in->header;
180196

181197
if (use_enu) {
182-
convert_vec_frd_to_rfu(msg_in->angularrate, msg.angular_velocity);
183-
convert_vec_frd_to_rfu(msg_in->accel, msg.linear_acceleration);
198+
convert_vec_frd_to_rfu_custom_rate(msg_in->angularrate, msg.angular_velocity);
199+
convert_vec_frd_to_rfu_custom(msg_in->accel, msg.linear_acceleration);
184200
convert_to_enu(msg_in->quaternion, msg.orientation);
185201
} else {
186-
msg.angular_velocity = msg_in->angularrate;
187-
msg.linear_acceleration = msg_in->accel;
202+
msg.angular_velocity.x = msg_in->angularrate.x * (-1);
203+
msg.angular_velocity.y = msg_in->angularrate.y * (-1);
204+
msg.angular_velocity.z = msg_in->angularrate.z * (-1);
205+
//msg.angular_velocity = msg_in->angularrate*(-1);
206+
//msg.linear_acceleration = msg_in->accel;
207+
msg.linear_acceleration.x = msg_in->accel.x*(-1);
208+
msg.linear_acceleration.y = msg_in->accel.y*(-1);
209+
msg.linear_acceleration.z = msg_in->accel.z;
188210
msg.orientation = msg_in->quaternion;
189211
}
190212

@@ -202,11 +224,14 @@ void VnSensorMsgs::sub_vn_common(const vectornav_msgs::msg::CommonGroup::SharedP
202224
msg.header = msg_in->header;
203225

204226
if (use_enu) {
205-
convert_vec_frd_to_rfu(msg_in->imu_rate, msg.angular_velocity);
206-
convert_vec_frd_to_rfu(msg_in->imu_accel, msg.linear_acceleration);
227+
convert_vec_frd_to_rfu_custom(msg_in->imu_rate, msg.angular_velocity);
228+
convert_vec_frd_to_rfu_custom(msg_in->imu_accel, msg.linear_acceleration);
207229
convert_to_enu(msg_in->quaternion, msg.orientation);
208230
} else {
209-
msg.angular_velocity = msg_in->imu_rate;
231+
msg.angular_velocity.x = msg_in->imu_rate.x * (-1);
232+
msg.angular_velocity.y = msg_in->imu_rate.y * (-1);
233+
msg.angular_velocity.z = msg_in->imu_rate.z * (-1);
234+
//msg.angular_velocity = msg_in->imu_rate*(-1);
210235
msg.linear_acceleration = msg_in->imu_accel;
211236
}
212237

@@ -222,7 +247,7 @@ void VnSensorMsgs::sub_vn_common(const vectornav_msgs::msg::CommonGroup::SharedP
222247
sensor_msgs::msg::MagneticField msg;
223248
msg.header = msg_in->header;
224249
if (use_enu) {
225-
convert_vec_frd_to_rfu(msg_in->magpres_mag, msg.magnetic_field);
250+
convert_vec_frd_to_rfu_custom(msg_in->magpres_mag, msg.magnetic_field);
226251
} else {
227252
msg.magnetic_field = msg_in->magpres_mag;
228253
}
@@ -284,11 +309,14 @@ void VnSensorMsgs::sub_vn_common(const vectornav_msgs::msg::CommonGroup::SharedP
284309
geometry_msgs::msg::TwistWithCovarianceStamped msg;
285310
msg.header = msg_in->header;
286311
if (use_enu) {
287-
convert_vec_frd_to_rfu(ins_velbody_, msg.twist.twist.linear);
288-
convert_vec_frd_to_rfu(msg_in->angularrate, msg.twist.twist.angular);
312+
convert_vec_frd_to_rfu_custom(ins_velbody_, msg.twist.twist.linear);
313+
convert_vec_frd_to_rfu_custom(msg_in->angularrate, msg.twist.twist.angular);
289314
} else {
290315
msg.twist.twist.linear = ins_velbody_;
291-
msg.twist.twist.angular = msg_in->angularrate;
316+
msg.twist.twist.angular.x = msg_in->angularrate.x * (-1);
317+
msg.twist.twist.angular.y = msg_in->angularrate.y * (-1);
318+
msg.twist.twist.angular.z = msg_in->angularrate.z * (-1);
319+
//msg.twist.twist.angular = msg_in->angularrate*(-1);
292320
}
293321

294322
/// TODO(Dereck): Velocity Covariance

0 commit comments

Comments
 (0)