How to use rtklibnav_to_csv(description of rtklibnav_to_csv)
Prerequisites:
Ensure that the bag file you are using contains the message type 'rtklib_msgs/msg/RtklibNav'.
Here's how you can verify.
$ros2 bag info 'your bag_file'
Topic: /rtklib_nav_1 | Type: rtklib_msgs/msg/RtklibNav
How to execute the command(execute the commnad)
$cd sh_ws/rtklibnav_to_csv/
$sh rtklibnav_to_csv.sh
Prepareation of rtklibnav_to_csv.sh
First1: Change the path of the bag file you are using
before change:
'ros2 bag play '/home/megken/0_data/nagashima/bag/nagashima_run4' --read-ahead-queue-size 100000 &'
change yourself:
"ros2 bag play 'Bag_file you are using' -read-ahead-queue-size 100000 &"
Second2: The name of the CSV_file you output can be changed, it's optional
before change:
echo "headers" > output.csv
echo "line" >> output.csv
echo "sec,nanosec,UNIX_Time,TOW,TOW_to_UNIX,pc_delay" > output_filtered.csv
echo "sec,nanosec,unix_time,tow,TOW_to_UNIX,pc_delay" >> output_filtered.csv
change yourself:
'output.csv'
'output_filtered.csv'
For references:
'output.csv' contains all information , 'output_filtered.csv' contains specific information.
How to create a CSV_file with a command.
Commnad1:
$ros2 topic echo 'topic' --csv --qos-history keep_all --qos-reliability reliable > output.csv
Commnad2:
$ros2 bag play -r 100 YOUR_BAG_DIR
プログラム紹介
#!/bin/bash
#Confirm the "pc_delay_time" using rtklibnav_topic
#The file 'output.csv' contains all information from 'rtklibnav_topic' , while 'output_filtered.csv' contains specific designated infomation.
echo "Starting ros2 bag play with rate 100" #output terminal
ros2 bag play '/home/megken/0_data/nagashima/bag/nagashima_run4' --read-ahead-queue-size 10000000000 &
bag_play_pid=$!
echo "ros2 bag play started with PID: $bag_play_pid"
message_type=$(ros2 topic type /rtklib_nav_1)
echo "Message type: $message_type"
output=$(ros2 interface show $message_type)
headers="sec,nanosec,frame_id,tow,ecef_pos_x,ecef_pos_y,ecef_pos_z,ecef_vel_x,ecef_vel_y,ecef_vel_z,sec,nanosec,frame_id,status,service,latitude,longitude,altitude,position_covariance1,position_covariance2,position_covariance3,position_covariance4,position_covariance5,position_covariance6,position_covariance7,position_covariance8,position_covariance9,position_covariance_type"
echo "Headers: $headers"
echo "$headers" > output.csv
echo "sec,nanosec,UNIX_Time,TOW,TOW_to_UNIX,pc_delay" > output_filtered.cs
echo "Echoing and filtering topic /rtklib_nav_1 to output.csv and output_filtered.csv"
ros2 topic echo /rtklib_nav_1 --csv --qos-history keep_all --qos-reliability reliable | while read line; do
sec=$(echo "$line" | cut -d ',' -f 1)
nanosec=$(echo "$line" | cut -d ',' -f 2)
tow_original=$(echo "$line" | cut -d ',' -f 4)
tow=$(awk -v tow="$tow_original" 'BEGIN {printf "%.9f", tow / 1000 }')
unix_time=$(awk -v sec="$sec" -v nanosec="$nanosec" 'BEGIN {printf "%.9f", sec + nanosec * 1e-9}')
TOW_to_UNIX=$(awk -v tow="$tow" -v time_of_week=2302 'BEGIN {printf "%.9f", time_of_week * 604800 + tow + 315964800 - 18}')
pc_delay=$(awk -v unix_time="$unix_time" -v TOW_to_UNIX="$TOW_to_UNIX" 'BEGIN {printf "%.9f" , TOW_to_UNIX - unix_time}')
if [ ! -z "$sec" ] && [ ! -z "$nanosec" ] && [ ! -z "$tow" ]; then
echo "$sec,$nanosec,$unix_time,$tow,$TOW_to_UNIX,$pc_delay" >> output_filtered.csv
fi
echo "$line" >> output.csv
done
wait $bag_play_pid
echo "Finish all processs"
以上です.