Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ROS 2 time_callback acccording to ROS 1 #35

Open
horverno opened this issue Jan 29, 2024 · 0 comments
Open

Update ROS 2 time_callback acccording to ROS 1 #35

horverno opened this issue Jan 29, 2024 · 0 comments
Assignees
Labels
ROS2 ROS2 related issues

Comments

@horverno
Copy link
Member

void time_callback(u16 sender_id, u8 len, u8 msg[], void *context)
{
msg_gps_time_t *time_gps = (msg_gps_time_t *)msg;
sensor_msgs::TimeReference time_msg;
time_msg.header.frame_id = "ros_time";
//time_msg.header.stamp.nsec = ros::Time::now().nsec / 1000;
//time_msg.header.stamp.sec = ros::Time::now().sec;
time_msg.header.stamp = ros::Time::now();
//rounded msec + residual nsec -> truncated sec + remainder nsec
long long int towtemp = time_gps->tow % 1000;
long long int ttemp = (towtemp * 1000000 + time_gps->ns_residual) % 1000000000;
time_msg.time_ref.nsec = ttemp;
time_msg.time_ref.sec = time_gps->tow / 1000 + time_gps->wn * 604800 + 315964782;
time_msg.source = "gps_duro";
std_msgs::Float64 diff_msg;
ros::Duration diff = time_msg.time_ref - time_msg.header.stamp;
diff_msg.data = diff.toSec();
//diff_msg.data = time_gps->tow;
std_msgs::String gps_str_msg;
gps_str_msg.data = std::to_string(time_gps->wn) + " " + std::to_string(time_gps->tow) + " " + std::to_string(time_gps->ns_residual);
time_gps_str_pub.publish(gps_str_msg);
time_ref_pub.publish(time_msg);
time_diff_pub.publish(diff_msg);
}

void time_callback(u16 sender_id, u8 len, u8 msg[], void *context)
{
msg_gps_time_t *time_gps = (msg_gps_time_t *)msg;
time_ref_msg.header.frame_id = "ros_time_frame";
time_ref_msg.header.stamp = node->now();
//rounded msec + residual nsec -> truncated sec + remainder nsec
long long int towtemp = time_gps->tow % 1000;
long long int ttemp = (towtemp * 1000000 + time_gps->ns_residual) % 1000000000;
time_ref_msg.time_ref.nanosec = ttemp;
time_ref_msg.time_ref.sec = time_gps->tow / 1000;
time_ref_msg.source = "gps_duro";
time_ref_pub->publish(time_ref_msg);
}

@horverno horverno added the ROS2 ROS2 related issues label Jan 29, 2024
@horverno horverno self-assigned this Jan 29, 2024
szepilot added a commit that referenced this issue Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ROS2 ROS2 related issues
Projects
None yet
Development

No branches or pull requests

1 participant