2
0

More than 3 years have passed since last update.

ROS(rosserial)とArduinoの時刻同期について

Posted at

概要

  • ROS(rosserial)とArduinoの時刻同期は、Arduino側のnode handleのnow()で、接続しているPC時間を呼び出せる

コード (Arduino)

ROSの公式サンプル
http://wiki.ros.org/rosserial_arduino/Tutorials/Time%20and%20TF

ros_lib -> TimeTf from the Arduino

/*
 * rosserial Time and TF Example
 * Publishes a transform at current time
 */

#include <ros.h>
#include <ros/time.h>
#include <tf/transform_broadcaster.h>

ros::NodeHandle  nh;

geometry_msgs::TransformStamped t;
tf::TransformBroadcaster broadcaster;

char base_link[] = "/base_link";
char odom[] = "/odom";

void setup()
{
  nh.initNode();
  broadcaster.init(nh);
}

void loop()
{
  t.header.frame_id = odom;
  t.child_frame_id = base_link;
  t.transform.translation.x = 1.0;
  t.transform.rotation.x = 0.0;
  t.transform.rotation.y = 0.0;
  t.transform.rotation.z = 0.0;
  t.transform.rotation.w = 1.0;
  t.header.stamp = nh.now();
  broadcaster.sendTransform(t);
  nh.spinOnce();
  delay(10);
}

うまくいかない場合

  • loop()関数内に、nh.spinOnce()が書かれていること確認
  • 書かれていない場合は、追記

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0