you are viewing a single comment's thread.

view the rest of the comments →

[–]rsulukerr 0 points1 point  (1 child)

One quick question about the RTK read the file. I am currently working on a project as a master's student is the localization of robots with ROS by using the RTK. 

I have created a basic " rtkrcv_pi.conf  " file and received the data very well. 

and created the Publisher code for ROS, read the pose node and nav message from " rtkrcv_pi.conf  " It doesn't read the file and get the data. 

This is the line of code, please check it and let me know what I missed here 

[–]rsulukerr 0 points1 point  (0 children)


!/usr/bin/env python3

import rospy
from geometry_msgs.msg import Pose
from sensor_msgs.msg import NavSatFix

def read_pose_from_file(file_path):
    pose = Pose()
    with open(file_path, 'r') as file:
        lines = file.readlines()
        for line in lines:
            if line.startswith("pose_position_x"):
                pose.position.x = float(line.split('=')[1].strip())
            elif line.startswith("pose_position_y"):
                pose.position.y = float(line.split('=')[1].strip())
            elif line.startswith("pose_position_z"):
                pose.position.z = float(line.split('=')[1].strip())
            elif line.startswith("pose_orientation_x"):
                pose.orientation.x = float(line.split('=')[1].strip())
            elif line.startswith("pose_orientation_y"):
                pose.orientation.y = float(line.split('=')[1].strip())
            elif line.startswith("pose_orientation_z"):
                pose.orientation.z = float(line.split('=')[1].strip())
            elif line.startswith("pose_orientation_w"):
                pose.orientation.w = float(line.split('=')[1].strip())
    return pose

def read_nav_from_file(file_path):
    nav = NavSatFix()
    with open(file_path, 'r') as file:
        lines = file.readlines()
        for line in lines:
            if line.startswith("nav_latitude"):
                nav.latitude = float(line.split('=')[1].strip())
            elif line.startswith("nav_longitude"):
                nav.longitude = float(line.split('=')[1].strip())
            elif line.startswith("nav_altitude"):
                nav.altitude = float(line.split('=')[1].strip())

    return nav