Skip to content

Commit cd7ab4b

Browse files
committed
Temporary fix of novatel not properly transfroming
1 parent c073d28 commit cd7ab4b

1 file changed

Lines changed: 34 additions & 22 deletions

File tree

src/nova_oem7_to_tf.cpp

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,75 +46,87 @@ class CurrentPoseFromTf : public rclcpp::Node
4646
this->get_parameter("inspva_topic_sub", m_inspva_topic_);
4747

4848
m_pose_pub_ = this->create_publisher<geometry_msgs::msg::PoseStamped>(m_pose_topic_, 10);
49+
// additional publisher for translated pose
50+
m_pose_pub2_ = this->create_publisher<geometry_msgs::msg::PoseStamped>("current_pose2", 10); // TODO: this is only temporary
4951
m_utm_sub_ = this->create_subscription<novatel_oem7_msgs::msg::BESTUTM>(m_utm_topic_, 10, std::bind(&CurrentPoseFromTf::utm_callback, this, _1));
5052
m_inspva_sub_ = this->create_subscription<novatel_oem7_msgs::msg::INSPVA>(m_inspva_topic_, 10, std::bind(&CurrentPoseFromTf::inspva_callback, this, _1));
5153
m_tfBroadcaster_ = std::make_shared<tf2_ros::TransformBroadcaster>(this);
5254
RCLCPP_INFO_STREAM(this->get_logger(), "nova_oem7_to_tf node started");
5355
RCLCPP_INFO_STREAM(this->get_logger(), "nova coord offset: " << m_x_coord_offset_ << ", " << m_y_coord_offset_ << ", " << m_z_coord_exact_height_);
5456
RCLCPP_INFO_STREAM(this->get_logger(), "nova frame_id: " << m_frame_id_ << ", child_frame_id: " << m_child_frame_id_);
5557
RCLCPP_INFO_STREAM(this->get_logger(), "nova utm_topic: " << m_utm_topic_);
56-
57-
if (m_z_coord_ref_switch_.compare("exact") == 0){
58+
59+
if (m_z_coord_ref_switch_.compare("exact") == 0)
60+
{
5861
RCLCPP_INFO_STREAM(this->get_logger(), "nova exact height (z): " << m_z_coord_exact_height_);
5962
}
60-
else {
63+
else
64+
{
6165
RCLCPP_INFO_STREAM(this->get_logger(), "nova original height (z)");
6266
}
63-
6467
}
6568

6669
private:
67-
6870
// Callback function for the subscriber novatel_oem7_msgs
6971
void utm_callback(const novatel_oem7_msgs::msg::BESTUTM::SharedPtr msg)
70-
{
71-
72+
{
73+
7274
// create current pose
7375
m_currentPose.header.stamp = msg->header.stamp;
7476
m_currentPose.header.frame_id = m_frame_id_;
7577
// # 'x_coord_offset': -697237.0, # map_gyor_0
7678
// # 'y_coord_offset': -5285644.0, # map_gyor_0
77-
// # 'x_coord_offset': -639770.0,
79+
// # 'x_coord_offset': -639770.0,
7880
// # 'y_coord_offset': -5195040.0, # map_zala_0
79-
m_currentPose.pose.position.x = msg->easting + m_x_coord_offset_;
80-
m_currentPose.pose.position.y = msg->northing + m_y_coord_offset_;
81-
if (m_z_coord_ref_switch_.compare("exact") == 0){
82-
m_currentPose.pose.position.z = m_z_coord_exact_height_;
81+
m_currentPose.pose.position.x = msg->easting + m_x_coord_offset_;
82+
m_currentPose.pose.position.y = msg->northing + m_y_coord_offset_;
83+
if (m_z_coord_ref_switch_.compare("exact") == 0)
84+
{
85+
m_currentPose.pose.position.z = m_z_coord_exact_height_;
8386
}
84-
else {
87+
else
88+
{
8589
m_currentPose.pose.position.z = msg->height; // original height
8690
}
8791

8892
geometry_msgs::msg::TransformStamped transformStamped;
8993
transformStamped.header.stamp = msg->header.stamp;
9094
transformStamped.header.frame_id = m_frame_id_;
9195
transformStamped.child_frame_id = m_child_frame_id_;
92-
transformStamped.transform.translation.x = msg->easting + m_x_coord_offset_;
96+
transformStamped.transform.translation.x = msg->easting + m_x_coord_offset_;
9397
transformStamped.transform.translation.y = msg->northing + m_y_coord_offset_;
9498
transformStamped.transform.translation.z = m_currentPose.pose.position.z;
95-
if (m_z_coord_ref_switch_.compare("exact") == 0){
96-
transformStamped.transform.translation.z = m_z_coord_exact_height_;
99+
if (m_z_coord_ref_switch_.compare("exact") == 0)
100+
{
101+
transformStamped.transform.translation.z = m_z_coord_exact_height_;
97102
}
98-
else {
103+
else
104+
{
99105
transformStamped.transform.translation.z = msg->height; // original height
100106
}
101107
transformStamped.transform.rotation = m_currentPose.pose.orientation;
102108
// Publish tf
103109
m_tfBroadcaster_->sendTransform(transformStamped);
104110
// Publish the current pose
105111
m_pose_pub_->publish(m_currentPose);
112+
// Publish a translated copy of the current pose on current_pose2
113+
geometry_msgs::msg::PoseStamped translated_pose = m_currentPose;
114+
// Apply translation: x = x - 1.5, y = y + 0.2
115+
translated_pose.pose.position.x = translated_pose.pose.position.x - 1.585;
116+
translated_pose.pose.position.y = translated_pose.pose.position.y + 0.2755;
117+
m_pose_pub2_->publish(translated_pose);
106118
}
107119

108120
void inspva_callback(const novatel_oem7_msgs::msg::INSPVA::SharedPtr msg)
109121
{
110122

111123
// RCLCPP_INFO(this->get_logger(), "INS PVA: %f %f %f", msg->roll, msg->pitch, msg->azimuth);
112124
tf2::Quaternion oriQuater, oriRot, oriNew;
113-
double R = (msg->roll) * (M_PI / 180) * -1;
125+
double R = (msg->roll) * (M_PI / 180) * -1;
114126
double P = (msg->pitch) * (M_PI / 180) * -1;
115127
double Y = (msg->azimuth) * (M_PI / 180) - M_PI;
116-
oriQuater.setRPY(R,P,Y);
117-
oriRot.setRPY(0.0, 0.0, M_PI/2.0);
128+
oriQuater.setRPY(R, P, Y);
129+
oriRot.setRPY(0.0, 0.0, M_PI / 2.0);
118130
oriNew = oriRot * oriQuater;
119131
oriNew.normalize();
120132
m_currentPose.pose.orientation.w = oriNew.getW() * -1;
@@ -124,11 +136,12 @@ class CurrentPoseFromTf : public rclcpp::Node
124136
}
125137

126138
rclcpp::Publisher<geometry_msgs::msg::PoseStamped>::SharedPtr m_pose_pub_;
139+
rclcpp::Publisher<geometry_msgs::msg::PoseStamped>::SharedPtr m_pose_pub2_;
127140
rclcpp::Subscription<novatel_oem7_msgs::msg::BESTUTM>::SharedPtr m_utm_sub_;
128141
rclcpp::Subscription<novatel_oem7_msgs::msg::INSPVA>::SharedPtr m_inspva_sub_;
129142
std::shared_ptr<tf2_ros::TransformBroadcaster> m_tfBroadcaster_;
130143
geometry_msgs::msg::PoseStamped m_currentPose;
131-
// TODO: parameters
144+
// TODO: parameters
132145
std::string m_frame_id_ = "map";
133146
std::string m_child_frame_id_ = "lexus3/base_link";
134147
std::string m_z_coord_ref_switch_ = "orig"; // orig or exact
@@ -138,7 +151,6 @@ class CurrentPoseFromTf : public rclcpp::Node
138151
std::string m_pose_topic_ = "/lexus3/gps/nova/current_pose";
139152
std::string m_utm_topic_ = "/lexus3/nova/bestutm";
140153
std::string m_inspva_topic_ = "/lexus3/nova/inspva";
141-
142154
};
143155

144156
int main(int argc, char **argv)

0 commit comments

Comments
 (0)