Siddharth Saha's NDoF Sensor Driver for Machina Labs  v1.0.0
ROS 2 Driver for Machina Labs' NDoF Sensor
Functions | Variables
examine_sensor_output Namespace Reference

Functions

def get_difference_in_time (msg1, msg2)
 
def main (bagfile, topic)
 

Variables

 parser = argparse.ArgumentParser(description="Examine sensor output")
 
 help
 
 type
 
 Path
 
 required
 
 str
 
 args = parser.parse_args()
 

Function Documentation

◆ get_difference_in_time()

def examine_sensor_output.get_difference_in_time (   msg1,
  msg2 
)
10 def get_difference_in_time(msg1, msg2):
11  diff_ns = (msg2.nanosec + (msg2.sec * 1e9)) - (msg1.nanosec + (msg1.sec * 1e9))
12  return diff_ns / 1e9
13 
14 
def get_difference_in_time(msg1, msg2)
Definition: examine_sensor_output.py:10

◆ main()

def examine_sensor_output.main (   bagfile,
  topic 
)
15 def main(bagfile, topic):
16  if not bagfile.exists():
17  print(f"Bagfile {bagfile} does not exist")
18  return
19  if not bagfile.suffix == ".mcap":
20  print(f"Bagfile {bagfile} is not an MCAP file")
21  return
22  mcap_summary = []
23  prev_msg = None
24  for msg in tqdm(read_ros2_messages(source=str(bagfile), topics=[topic])):
25  row_info = {}
26  if prev_msg:
27  row_info["publisher_time_diff_sec"] = get_difference_in_time(
28  prev_msg.ros_msg.stamp, msg.ros_msg.stamp
29  )
30  else:
31  prev_msg = msg
32  continue
33  for i in range(len(msg.ros_msg.sensors)):
34  row_info[f"sensor_{i}_time_diff_sec"] = get_difference_in_time(
35  prev_msg.ros_msg.sensors[i].header.stamp, msg.ros_msg.sensors[i].header.stamp
36  )
37  row_info[f"sensor_{i}_average_deviation"] = np.abs(
38  np.array(prev_msg.ros_msg.sensors[i].data.data)
39  - np.array(msg.ros_msg.sensors[i].data.data)
40  ).mean()
41  row_info[f"sensor_{i}_data_valid"] = np.uint8(
42  np.isclose(
43  np.sum(msg.ros_msg.sensors[i].data.data)
44  - msg.ros_msg.sensors[i].data.data[-1],
45  msg.ros_msg.sensors[i].data.data[-1],
46  )
47  )
48  mcap_summary.append(row_info)
49  prev_msg = msg
50  mcap_summary = pd.DataFrame(mcap_summary)
51  print(mcap_summary.describe())
52  pyperclip.copy(mcap_summary.describe().to_markdown())
53 
54 
str
Definition: examine_sensor_output.py:60
def main(bagfile, topic)
Definition: examine_sensor_output.py:15

Variable Documentation

◆ args

examine_sensor_output.args = parser.parse_args()

◆ help

examine_sensor_output.help

◆ parser

examine_sensor_output.parser = argparse.ArgumentParser(description="Examine sensor output")

◆ Path

examine_sensor_output.Path

◆ required

examine_sensor_output.required

◆ str

examine_sensor_output.str

◆ type

examine_sensor_output.type