Skip to content


ardupilot  None  ros2  dds  micro ros  xrce  lua  sitl  scripts  plugin  gazebo  garden  SITL  debug  mavlink  gimbal  rangefinder  pymavlink  mavros  distance sensor  system_time  timesync  ardurover  script  cheat sheet  wireshark  mavproxy  mission planner  pixhawk  cpp  index  cmake  gtest  ctest  demo  101  variables  cpack  deb  package  dpkg  eigen  linear algebra  c++  format  fmt  smart pointers  data structure  map  container  multithreading  spdlog  cyclonedds  eprosima  fastdds  aptly  apt  repository  repo  local  mirror  encryption  pgp  docker  arm  qemu  state  networking  network  template  python  app  devcontainer  gui  tutorial  tips  volume  mount  compose  multi-stage  stage  docker compose  microsoft  dotnet  .net  c#  vscode  git  branch  tag  bundle  backup  hooks  pre-commit  submodules  marpit  presentation  marp  markdown  mermaid  mkdocs  video  ffmpeg  gstreamer  cheat-sheet  sdp  nvidia  opencv  appsrc  appsink  acceleration  va-api  intel  v4l2loopback  pipe  compositor  alpha  shmsink  shmsrc  intersink  intersrc  tee  queue  udp  stream  klv  misb  mpeg-ts  gst  mpeg  metadata  binding  gi  kml  geo  gis  spatial  gdal  ogr  raster  vector  qgc  qgroundcontrol  snippets  cheat Sheet  asyncio  event  future  thread  task  can  canbus  click  cli  cupy  numpy  gpu  dataclass  slots  dev container  fastapi  rest  uvicorn  debian  setup  stdeb  project  jupyter  widgets  interactive  plot  matplotlib  ipywidgets  3d  subplot  open3d  point cloud  packaging  pyproject  pipx  package manager  black  isort  templates  cookiecutter  docs  project document  docstrings  flake8  linter  git-hook  mypy  unittest  pytest  pylint  from a-z  fixture  scope  logging  pytest.ini  mock  parameterize  enum  flag  iterator  generator  yaml  yml  logging config  tuple  namedtuple  typing  annotation  generic  literal  protocol  self  typed dict  typevar  pyzmq  zmq  msgpack  slam  cartographer  slam_toolbox  build system  colcon  action  namespace  remap  control2  diff-drive  ignition  ros2_control  effort  velocity  gdb  mix  multi language  qos  plugins  ros  pub  sub  msg  node  time  rclcpp  parameters  zero-copy  shm  loan message  rmw  image  large message  discovery  zenoh  bridge  zenoh-plugin-ros2dds  pico  algorithm  calibration  diff  pid  dev  colcon_cd  clean  custom  bloom  rpi  core  settings  behavior  py_trees  bt  behavior_trees  blackboard  visualization  debugging  diagnostic  DiagnosticTask  rclpy  tutorials  diagnostics  math  ned  enu  coordinate  apm  rat_runtime_monitor  bag  rosbag  rosbags  tools  smach  state machine  yasmin  web  rosbridge  vue  profile  gazebo-classic  launch  spawn  model  cook  camera  sensors  gps  imu  ray  gazebo_ros_ray_sensor  lidar  ultrsonic  range  ultrasonic  gazebo classic  wrench  gazebo_ros_state  gz  sdf  world  vscode tips  gazebogz-sim-joint-position-controller-system  simulation  ros_gz_bridge  ign  xacro  diff_drive  odom  odometry  joint_state  argument  OpaqueFunction  DeclareLaunchArgument  LaunchConfiguration  tmux  tmuxp  nav  nav2  turtlebot  perception  tf  vision  cv_bridge  setup.py  name  test  goal abort  cancel goal  action client  action server  custom messages  executor  MultiThreadedExecutor  SingleThreadedExecutor  lifecycle  parameter  param  dynamic-reconfigure  get  global server  persist_parameter  service  client  package.xml  msgs  executers  rep  rqt  humble  rviz  rviz2  pose  marker  tf2  static  graphro  local_setup  rosdep  project settings  vcstool  urdf  robot_state_publisher  urdf_to_graphiz  joint  link  robotics  path planning  trajectory  speed  filters  control  kalman_filter  kalman  filter  pcl  fusing  foc  bldc  arduino  drv8313  simple foc  quaternions  euler  rotation  code  extensions  remote  cache  offline  ssh  tasks  json  schema  server  deep learning  ai  beginner  regression  reinforcement learning  q learning  gym  gymnasium  deepsort  onnx  inference  build  source  wheel  cuda  siam-mask  tracking  segmentation  yolo  ultralytics  yolov8  jetson  tensorrt  rest api  js  javascript  async  alpine.js  mqtt  nano  terabee  i2c  l6234  blink  platformio  lw20  benewake  TF03  serial  tf_mini  libs  cross-compiler  esp32  idf  esp-idf  rtos  hello world  mp6050  mpu9250  mpu6050  embedded  kconfig  semaphore  mutex  timer  adafruit  sensor  mb1202  uart  tfmini  gpio  raspberry pi  arducam  lidat  ubuntu  stm32  nucleo  mbed  blue pill  swd  library  teensy  microros  udev  rule  usb  micro python  pymakr  config  material  workshope  classic  texture  topic  gzstring  position  force  joints  loop device  rootfs  linux  rm  sudo  sudoers  nopasswd  visudo  shell  key  gpg  sign  commands  update-alternative  debconf  dpkg-show  dpkg-reconfigure  debconf-communicate  ip  ss  netstat  systemd  socat  tc  mtu  select  projects  courses to follow  matrix  graphics  2d  course  storm32  deploy  drone  quad  uav  geometric control  se3  so3  joint_states  JointState  Header  rrbot  JointTrajectory  gazebo_ros_joint_pose_trajectory  vrx  buoyancy 

Table of Content

SYSTEM_TIME#

mavlink.io

Ardupilot send and received this message

Sending#

Implement by GCS_Common send_system_time method

the unix time calc from RTC class and return only if we have time source the rtc_source_type is set by logic in AP_RTC::set_utc_usec that call by - GPS when we have 3D fix lock or better - Mavlink message SYSTEM_TIME - ?

ardupilot time source enum
// ordering is important in source_type; lower-numbered is
// considered a better time source.  These values are documented
// and used in the parameters!
enum source_type : uint8_t {
    SOURCE_GPS = 0,
    SOURCE_MAVLINK_SYSTEM_TIME = 1,
    SOURCE_HW = 2,
    SOURCE_NONE,
}

Demo#

Listen to SYSTEM_TIME message with and without GPS source

BRD_RTC_TYPES 0
GPS_TYPE 0
without gps
2023-04-16 19:23:29,160 - __main__ - INFO - param_name: BRD_RTC_TYPES value: 1.0
2023-04-16 19:23:30,151 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 0, 'time_boot_ms': 2154028}
2023-04-16 19:23:31,152 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 0, 'time_boot_ms': 2155028}
2023-04-16 19:23:32,155 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 0, 'time_boot_ms': 2156028}
2023-04-16 19:23:33,154 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 0, 'time_boot_ms': 2157028}
2023-04-16 19:23:34,152 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 0, 'time_boot_ms': 2158028}
BRD_RTC_TYPES 1
GPS_TYPE 1
with gps
2023-04-16 19:27:05,833 - __main__ - INFO - Set SYSRM_TIME message interval to 1sec
2023-04-16 19:27:05,840 - __main__ - INFO - param_name: BRD_RTC_TYPES value: 1.0
2023-04-16 19:27:06,836 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 0, 'time_boot_ms': 4028}
2023-04-16 19:27:07,841 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 0, 'time_boot_ms': 5028}
2023-04-16 19:27:08,837 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 0, 'time_boot_ms': 6028}
2023-04-16 19:27:09,836 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 0, 'time_boot_ms': 7028}
2023-04-16 19:27:10,837 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 0, 'time_boot_ms': 8028}
2023-04-16 19:27:11,842 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 1681662430861592, 'time_boot_ms': 9028}
2023-04-16 19:27:12,837 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 1681662431861192, 'time_boot_ms': 10028}
2023-04-16 19:27:13,840 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 1681662432861625, 'time_boot_ms': 11028}

time_unix

No epoc time until GPS has 3D fix

Demo II#

Send SYSTEM_TIME message to send ardupilot with time source when no GPS found

BRD_RTC_TYPES 2
GPS_TYPE 0

BRD_RTC_TYPES

BRD_RTC_TYPES must be SOURCE_HW and not SOURCE_MAVLINK_SYSTEM_TIME to pass the condition

if (!(allowed_types & (1<<type))) {
    return;
}
from AP_RTC.cpp file

2023-04-16 22:07:18,843 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 1681671783248796, 'time_boot_ms': 573026}
2023-04-16 22:07:18,844 - __main__ - INFO - param_name: BRD_RTC_TYPES value: 2.0
2023-04-16 22:07:19,839 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 1681671784248396, 'time_boot_ms': 574026}
2023-04-16 22:07:20,840 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 1681671785248829, 'time_boot_ms': 575026}
2023-04-16 22:07:21,838 - __main__ - INFO - {'mavpackettype': 'SYSTEM_TIME', 'time_unix_usec': 1681671786248429, 'time_boot_ms': 576026}

BRD_RTC_TYPES

BRD_RTC_TYPES must be SOURCE_HW for ardupilot accept mavlink message “SYSTEM_TIME”

check code
import time
import logging
import os
os.environ["MAVLINK20"]="1"
from pymavlink import mavutil
from pymavlink.dialects.v20 import ardupilotmega

FMT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
logging.basicConfig(format=FMT, level=logging.INFO)
log = logging.getLogger(__name__)

# Create the connection
# master = mavutil.mavlink_connection("/dev/ttyACM0")
# master = mavutil.mavlink_connection("tcp:0.0.0.0:5760")
master = mavutil.mavlink_connection("udp:127.0.0.1:14550")
ONE_SEC = 1e6

def set_message_interval(interval_us):
    master.mav.command_long_send(
    master.target_system,
    master.target_component,
    ardupilotmega.MAV_CMD_SET_MESSAGE_INTERVAL,
    0,
    ardupilotmega.MAVLINK_MSG_ID_SYSTEM_TIME,
    interval_us,
    0,
    0,
    0,
    0,
    0
    )

def set_system_time():
    # while True:
    current = int(time.time()*1e6)
    log.info("%s" , current)
    master.mav.system_time_send(
    current,
    0)
    time.sleep(1/1)

# Wait a heartbeat before sending commands
master.wait_heartbeat()

set_message_interval(ONE_SEC)
set_system_time()

USE_PARAM_ID = -1
master.mav.param_request_read_send(
    master.target_system,
    master.target_component,
    b"BRD_RTC_TYPES",
    USE_PARAM_ID
)

while True:
    msg = master.recv_match()
    if not msg:
        continue
    if msg.get_type() == "SYSTEM_TIME":
        log.info("%s", msg.to_dict())
    if msg.get_type() == "PARAM_VALUE":
        message = msg.to_dict()
        param_name = message["param_id"]
        if param_name == "BRD_RTC_TYPES":
            param_value = message["param_value"]
            log.info("param_name: %s value: %s", param_name, param_value)